Context Tree Switching

Joel Veness, Kee Siong Ng, Marcus Hutter, Michael H. Bowling

This paper, published in 2011 by researchers from the University of Alberta and the Australian National University, introduces Context Tree Switching (CTS)—a clever evolution of one of the most respected algorithms in information theory.

TL;DR

Context Tree Switching (CTS) is a new universal compression algorithm that improves upon the classic Context Tree Weighting (CTW) method. By replacing a static weighting scheme with a dynamic "switching" mechanism, CTS can adapt to a much broader range of data models in real-time without increasing computational complexity, leading to consistently better compression on standard benchmarks.

What Problem Does This Paper Address?

The goal is the optimal prediction and compression of binary, stationary, $n$-Markov sources (sequences where the next bit depends on the previous $n$ bits).

For decades, Context Tree Weighting (CTW) has been the gold standard. It works by building a suffix tree and "weighting" different models (different tree depths) to find a good average. However, standard weighting has a fundamental limitation: it only guarantees performance relative to the best single model in its set.

In practice, the "best" model often changes as more data arrives. Early on, a simple, shallow tree might be best because it has fewer parameters to learn (low "parameter redundancy"). Later, a deep, complex tree might become superior. Standard CTW struggles to transition between these efficiently. The authors sought a way to "switch" between these models dynamically as the data stream evolves.

Methods

The authors bridge the gap between two fields: universal compression and online learning.

  1. The Switching Distribution: They adapt the "Switch Distribution" (originally from Bayesian model selection) into a recursive form. Unlike simple weighting, which assumes one model is "true" for the whole sequence, switching allows the algorithm to track a sequence of models that changes over time.
  2. Recursive Integration: The core innovation is replacing the standard CTW update equation with a new "Switching" recursion. While CTW simply averages the probability of a bit being 0 or 1 across different tree nodes, CTS maintains "switch weights" that decide whether to trust the current node or its children.
  3. The $n^{-1}$ Switch Rate: A critical technical contribution is determining the "switch rate" ($\alpha$). The authors prove that by decaying the switch rate over time (specifically $\alpha_n = 1/n$), they can achieve a strong theoretical redundancy bound that is nearly as good as CTW's in the worst case, but much better in practice.
  4. Complexity Parity: Remarkably, the authors show that CTS maintains the same $O(nD)$ time and $O(D)$ space complexity as the original CTW, where $n$ is the sequence length and $D$ is the maximum tree depth.

Datasets

The algorithm was evaluated using the Calgary Corpus, a classic benchmark in the compression community consisting of various file types including text (books, papers), source code, and geographic data. They compared several versions:

  • Base CTW vs. Base CTS: Comparing the raw algorithms.
  • Enhanced versions ($CTW^*$ vs. $CTS^*$): Including practical optimizations like "count halving" and binary decomposition for non-binary data.
  • Modern Baselines: Comparing against state-of-the-art methods like PPMZ and DEPLUMP.

Key Insights and Ideas

  • The "Aha" Moment: The realization that CTW's recursive structure is perfectly suited for the "Fixed-Share" or "Switching" algorithms used in machine learning to track the best expert over time.
  • Model Evolution: CTS naturally handles the "cold start" problem. It starts by favoring simple models (shallow trees) and automatically shifts its weight to more complex models (deeper trees) only when the evidence (data) justifies the extra complexity.
  • Theoretical Safety: The authors provide a formal proof (Theorem 3) showing that CTS isn't just a heuristic; it has a mathematically guaranteed "regret bound." Even if the data is "weird," CTS won't perform significantly worse than the best possible fixed-depth tree.

Key Results

  • Consistent Improvement: CTS outperformed CTW on almost every file in the Calgary Corpus.
  • Compression Gains: In some instances, the base CTS produced files 7% smaller than base CTW.
  • State-of-the-Art Performance: The enhanced $CTS^*$ achieved an average of 1.93 bits per byte on the Calgary Corpus, matching the highly optimized PPMZ algorithm and coming very close to the more complex DEPLUMP (1.89 bits per byte).
  • Efficiency: The improvements were achieved without any noticeable increase in the time or memory required to process the files.

Limitations and Future Work

  • Binary Focus: The current derivation is strictly for binary sources. While the authors use "binary decomposition" to handle bytes, a direct multi-symbol (alphabet size $> 2$) version of the switching recursion remains an open area for exploration.
  • Non-Stationarity: While the algorithm is designed for stationary sources, the "switching" nature suggests it could be adapted for piecewise stationary sources (where the data-generating rules change abruptly). The authors suggest this as a promising next step.
  • Advanced Estimators: The paper uses the standard Krichevsky-Trofimov (KT) estimator at the leaf nodes. Replacing this with more modern "Zero-Redundancy" estimators could potentially push the performance even further.

Summary updated

BibTeX
@inproceedings{veness2012context,
  author = {Joel Veness and Kee Siong Ng and Marcus Hutter and Michael H. Bowling},
  title = {{Context Tree Switching}},
  booktitle = {DCC},
  year = {2012},
  url = {https://openreview.net/forum?id=ySydVmRnjY},
}
Figure