pub struct GruModel { /* private fields */ }Expand description
GRU byte-level predictor with BPTT-10 online training.
Implementations§
Source§impl GruModel
impl GruModel
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new GRU model with Xavier-initialized weights and zeroed buffers.
Sourcepub fn forward(&mut self, byte: u8)
pub fn forward(&mut self, byte: u8)
Forward pass: process one byte, update hidden state, compute output probs.
Call this with the byte that was just OBSERVED. The resulting byte_probs predict the NEXT byte. After forward(), call predict_bit() to get bit probabilities for the next byte.
Also saves the step into the BPTT history ring for train() to use.
Sourcepub fn predict_bit(&self, bpos: u8, c0: u32) -> u32
pub fn predict_bit(&self, bpos: u8, c0: u32) -> u32
Convert byte probabilities to a bit prediction for the CM MetaMixer.
bpos: bit position 0-7 (0 = MSB).
c0: partial byte being built (starts at 1, accumulates bits MSB-first).
Returns: 12-bit probability [1, 4095] of next bit being 1.
Sourcepub fn train(&mut self, actual_byte: u8)
pub fn train(&mut self, actual_byte: u8)
Online training with truncated BPTT.
Computes the output-layer gradient for actual_byte, then propagates
d_h backwards through up to BPTT_HORIZON stored steps. Gradients are
accumulated into pre-allocated buffers and applied in a single weight
update at the end. This avoids the weight-corruption from immediate
per-step updates that would otherwise occur in BPTT.
Call this BEFORE forward(actual_byte) (matches codec.rs flow). Both encoder and decoder see the same byte sequence so their weights and history buffers evolve identically — parity is preserved.