Papers
Topics
Authors
Recent
Search
2000 character limit reached

Context Tree Switching (CTS) Algorithm

Updated 9 February 2026
  • Context Tree Switching is a universal coding and prediction algorithm that extends the CTW framework by dynamically switching between expert predictors.
  • It employs a modified model-mixing mechanism at each node to combine memoryless and split-context predictors, achieving improved empirical compression on benchmarks like the Calgary Corpus.
  • The algorithm maintains O(nD) complexity with explicit redundancy bounds for PST-representable binary sources, making it suitable for modern high-throughput sequence modeling and online compression.

Context Tree Switching (CTS) is a universal coding and prediction algorithm that extends the Context Tree Weighting (CTW) technique for binary, stationary, nn-Markov sources. CTS modifies the model-mixing mechanism of CTW to encompass a larger model class with no additional asymptotic time or space complexity, and provably maintains efficient redundancy rates for coding. CTS achieves improved empirical compression performance relative to CTW, particularly on natural data streams such as those from the Calgary Corpus, and advances the state of the art for universal, provably optimal sequence prediction and compression in binary domains (Veness et al., 2011).

1. Model Assumptions and Formal Setup

CTS assumes the data sequence x1:nx_{1:n}, where xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}, is generated by a stationary nn-Markov source. There exists an (unknown) Markov order DD, such that the conditional source probability is local:

μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})

This model is represented by a Prediction Suffix Tree (PST) SXDS \subseteq \mathsf{X}^{\leq D} with leaf parameters ΘS[0,1]S\Theta_S \in [0,1]^{|S|}. For any sSs \in S, where ss is the unique suffix of x1:nx_{1:n}0, the leaf probability is x1:nx_{1:n}1.

Universal coders such as CTS are evaluated by code-length x1:nx_{1:n}2, where x1:nx_{1:n}3 is the model probability, and redundancy x1:nx_{1:n}4. Achieving x1:nx_{1:n}5 is the target for universal codes.

2. Context Tree Weighting vs. Context Tree Switching

CTW recursively combines local models at each context: for context x1:nx_{1:n}6 of length x1:nx_{1:n}7, define x1:nx_{1:n}8 as the subsequence with most recent x1:nx_{1:n}9-suffix xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}0. The Krichevsky–Trofimov (KT) estimate for such a context is xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}1, a Bayesian mixture over Bernoulli parameters.

The standard CTW recursion:

xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}2

CTS generalizes this by switching between two "experts" at each node, using a time-varying mixture rather than a fixed weight scheme:

  • Expert 0: memoryless KT predictor xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}3
  • Expert 1: split-context predictor, whose one-step predictive gain is:

xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}4

CTS maintains two nonnegative weights xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}5 and xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}6 per context xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}7, summing to xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}8, and a global or local sequence of switch rates, e.g., xiX:={0,1}x_i \in \mathsf{X} := \{0,1\}9 for all nodes.

3. Algorithmic Recursion and Update Scheme

At each symbol nn0, CTS traverses the context tree from root to leaf for nn1. The update scheme is as follows:

nn2

  • Base cases: for nn3, nn4; new nodes are initialized nn5.

CTS thus implements an online mixture over "stay-with-expert" or "switch-expert" decision paths at each node, allowing the effective model to dynamically adapt context depth and composition. The per-symbol time complexity is nn6; storage is nn7 at fixed nn8.

4. Theoretical Properties and Redundancy Bounds

CTS matches the computational complexity of CTW, at nn9 total update time and DD0 memory. It provides rigorous redundancy bounds for any binary stationary source representable as a PST of depth at most DD1.

Let DD2 be a PST of depth DD3, DD4 leaves, and maximum context length DD5. The cumulative code-length satisfies:

DD6

where:

  • DD7: CTW structure penalty,
  • DD8,
  • DD9: log-likelihood for tree μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})0 with parameters μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})1.

Thus, wrapped in an arithmetic coder, the total redundancy is

μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})2

matching CTW up to an additive μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})3 term—μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})4 optimality for fixed μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})5.

5. Empirical Evaluation and Comparative Performance

CTS and CTW were evaluated on the 14-file Calgary Corpus, with compression measured in average bits/byte using binary arithmetic coding. Several algorithmic variants were tested, with and without enhancements such as count-halving, binary decomposition, and zero-redundancy estimators.

Corpus CTW (D=48) CTS (D=48) CTW* (D=48) CTS* (D=48)
bib 2.25 2.23 1.83 1.79
book1 2.31 2.32 2.18 2.19
geo 5.01 5.05 4.53 4.18
  • Unenhanced CTS achieves up to 7% smaller compressed size than CTW, with no case worse than 1%. Enhanced CTS* with μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})6 provides up to 8% better compression than CTW*. Increasing tree depth to μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})7 with enhancements further reduces bits/byte (e.g., μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})8 on "trans").
  • Weighted averages: PPM* (μ(xtx1:t1)=μ(xtxtD:t1)\mu(x_t | x_{1:t-1}) = \mu(x_t | x_{t-D:t-1})9), CTW* (SXDS \subseteq \mathsf{X}^{\leq D}0), PPMZ (SXDS \subseteq \mathsf{X}^{\leq D}1), CTS* (SXDS \subseteq \mathsf{X}^{\leq D}2), Deplump PPM variant (SXDS \subseteq \mathsf{X}^{\leq D}3). CTS* thereby matches PPMZ and closely approaches the leading Deplump variant, while maintaining universality and provable SXDS \subseteq \mathsf{X}^{\leq D}4 complexity (Veness et al., 2011).

6. Context and Significance

CTS broadens the model class over which effective mixture prediction is performed relative to CTW, incorporating arbitrary switching between context segmentation and memoryless prediction at each node. By preserving computational and asymptotic efficiency, and providing explicit redundancy guarantees, CTS is a robust universal coding method for binary, stationary contexts. Its empirical advantage is consistently demonstrated on standard benchmarks, and its theoretical regime includes all D-Markov sources representable by PSTs of bounded depth. This suggests CTS is well-suited for modern applications where adaptivity, universality, and provable performance are critical, such as high-throughput sequence modeling and online compression (Veness et al., 2011).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Context Tree Switching (CTS).