pub struct VqCodebook {
pub embeddings: Vec<f32>,
pub n_codes: usize,
pub code_dim: usize,
pub ema_momentum: f32,
pub commitment_weight: f32,
pub ema_counts: Vec<f32>,
pub ema_sum: Vec<f32>,
}Expand description
EMA-maintained vector-quantisation codebook.
Stores K code vectors of dimension C as a flat [K × C] row-major buffer.
EMA running statistics (ema_counts, ema_sum) are used for the
Laplace-smoothed online codebook update rule:
n_k ← m·n_k + (1-m)·|S_k|
e_k ← m·e_k_sum + (1-m)·Σ_{z∈S_k} z (running sum)
code_k ← e_k_sum / n_k (normalised)Fields§
§embeddings: Vec<f32>Codebook entries E ∈ ℝ^{K×C}, row-major. Length = K * C.
n_codes: usizeNumber of codes K.
code_dim: usizeCode dimensionality C.
ema_momentum: f32EMA momentum m for codebook update (closer to 1 → slower update).
commitment_weight: f32Commitment loss weight β.
ema_counts: Vec<f32>EMA usage counts per code [K]. Initialised to 1 (Laplace smoothing).
ema_sum: Vec<f32>EMA running sums per code [K × C]. Initialised to the code vectors.
Trait Implementations§
Source§impl Clone for VqCodebook
impl Clone for VqCodebook
Source§fn clone(&self) -> VqCodebook
fn clone(&self) -> VqCodebook
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for VqCodebook
impl RefUnwindSafe for VqCodebook
impl Send for VqCodebook
impl Sync for VqCodebook
impl Unpin for VqCodebook
impl UnsafeUnpin for VqCodebook
impl UnwindSafe for VqCodebook
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
Mutably borrows from an owned value. Read more