ptwm_core::entropy::context_mixing::model
ptwm_core::entropy::context_mixing::model
Four byte-history context models (orders 0–3). Each maps a context — a hash of recent whole bytes combined with the partial-byte register c0 — to an adaptive 12-bit probability counter in a fixed hash table.
ptwm_core::entropy::context_mixing::model
crates/ptwm-core/src/entropy/context_mixing/model.rs:1mod modelFour byte-history context models (orders 0–3). Each maps a context — a hash of recent whole bytes combined with the partial-byte register `c0` — to an adaptive 12-bit probability counter in a fixed hash table.
ptwm_core::entropy::context_mixing::model::Models
crates/ptwm-core/src/entropy/context_mixing/model.rs:34pub struct ModelsThe four models. The counter tables share one flat `Vec<u16>` of `N_MODELS * TABLE_SIZE` (~512 KiB, one allocation, no double indirection in the per-bit hot path); model `m` owns `[m*TABLE_SIZE, (m+1)*TABLE_SIZE)`. Allocated fresh per encode/decode call — CM is opt-in and per-bit-compute-dominated, so the once-per-plane allocation is negligible.
ptwm_core::entropy::context_mixing::model::N_MODELS
crates/ptwm-core/src/entropy/context_mixing/model.rs:6pub const N_MODELSNumber of context models.
ptwm_core::entropy::context_mixing::model::update_counter
crates/ptwm-core/src/entropy/context_mixing/model.rs:23pub fn update_counter(p: &mut u16, bit: u8)Move a 12-bit probability counter (`0..=4095`, stored in u16) toward the observed `bit` (target 4095 for `bit == 1`, 0 for `bit == 0`).
mixer
Context-gated logistic mixer. One weight vector per gating context (the partial-byte register c0, bounded to 256). Mixes the models' stretched logits, squashes to a probability, and learns the weights online by logistic gradient. Integer/deterministic.
squash
lpaq squash (logistic) and stretch (logit) over 12-bit probabilities. squash(d) maps a stretched logit d to a probability in 0..=4095; stretch(p) is its inverse. Both are integer and deterministic.