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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GruModel
impl RefUnwindSafe for GruModel
impl Send for GruModel
impl Sync for GruModel
impl Unpin for GruModel
impl UnsafeUnpin for GruModel
impl UnwindSafe for GruModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more