Instead of relying on a single context length, Context Mixing runs multiple predictors in parallel (e.g., Order-0 overall bias, Order-1 previous bit, Order-2 previous byte/word).
Predictions $P_i(1)$ are stretched into logit domain $x_i = \ln(P_i/(1-P_i))$, combined with adaptive weights $w_i$, and squashed back via $P(1) = 1/(1+e^{-\sum w_i x_i})$.
After each bit $y \in \{0, 1\}$ is processed, model counts update, and weight values adapt using gradient descent: $w_i \leftarrow w_i + \eta \cdot x_i \cdot (y - P(1))$.
Simulation Controls & Input
Individual Context Models Predictions
Bit #0Logistic Mixing Calculation
Adaptive Model Weights
Compression Efficiency
Note: Using ideal arithmetic/range coding, each predicted bit $y$ requires exactly $-\log_2 P(y)$ bits of compressed storage.
Decompressor Synchronization
The decompressor reconstructs the exact same context tables and weights bit-by-bit in real time:
Educational Guide: How Context Mixing Works
1. The Problem with Single Context Models
Traditional predictive compressors (like PPM or Huffman) use a fixed context order. High-order contexts (e.g., last 4 characters) are extremely accurate when matches are found, but fail completely when encountering unseen sequences. Low-order contexts (e.g., last 1 character) are reliable but less specific.
Context Mixing solves this dilemma: It runs multiple independent models of varying orders simultaneously and dynamically combines their predictions.
2. Why Logistic (Non-linear) Mixing?
Instead of simple linear averaging $P_{mix} = \frac{P_1 + P_2}{2}$, modern compressors like PAQ convert probabilities into log-odds (logit domain) using the $stretch$ function:
In logit space, confident predictions (near 0 or 1) stretch to large negative/positive infinity. When summed with weights, a single highly confident model can overrule multiple uncertain models!
3. Adaptive Weight Updates (Online Learning)
The mixer assigns weight $w_i$ to each model. After predicting bit $y \in \{0, 1\}$, weights update using stochastic gradient descent to minimize cross-entropy loss:
Models that predicted correctly receive increased weight, while models that gave wrong high-confidence predictions are quickly penalized.
4. Symmetric Decompression Guarantee
Data compression is lossless because the Decompressor executes the exact same mathematical logic:
- Calculates predictions $P_i(1)$ using the exact same context history.
- Applies the same weights $w_i$ to get $P(1)$.
- Reads the actual encoded bit $y$ from the arithmetic stream.
- Updates context counts and weights identical to the compressor.