Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidrusu/ctw
An Implementation of the Context Tree Weighting (CTW) Sequence Prediction Algorithm
https://github.com/davidrusu/ctw
rust sequence-prediction
Last synced: 22 days ago
JSON representation
An Implementation of the Context Tree Weighting (CTW) Sequence Prediction Algorithm
- Host: GitHub
- URL: https://github.com/davidrusu/ctw
- Owner: davidrusu
- Created: 2022-03-05T03:14:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-03-05T04:17:14.000Z (over 2 years ago)
- Last Synced: 2024-09-14T01:42:12.589Z (about 2 months ago)
- Topics: rust, sequence-prediction
- Language: Rust
- Homepage: http://www.davidrusu.com/blog#ctw
- Size: 5.86 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Context Tree Weighting (CTW)
CTW is a lightweight, practical and well performing sequence prediction algorithm discovered by Frans Willems, Yuri Shtarkov and Tjalling Tjalkens (1995).
It has good query and update performance (linear in the context length).
# Useage
The following example demonstrates CTW learning the altenating binary sequence 101010...
```rust
use ctw::CtwTree;
let mut rng = rand::thread_rng();
let mut tree = CtwTree::new(8); // context length is 8let pattern = [true, false].into_iter().cycle().take(100); // true, false, true, ..
tree.update_batch(&Vec::from_iter(pattern));let mut predictions = Vec::new();
for _ in 0..10 {
let prediction = tree.sample(&mut rng);
tree.update(prediction);// convert bool to 1 and 0 for legibility
let bit = if prediction { 1 } else { 0 };
predictions.push(bit);
}println!("predictions: {predictions:?}"); // --> "prediction: [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]"
assert_eq!(predictions, vec![1,0,1,0,1,0,1,0,1,0]);
```# Resources
1. http://www.hutter1.net/publ/sctw.pdf
2. https://web.stanford.edu/class/ee378a/lecture-notes/lecture_9.pdf
3. http://www.data-compression.info/Algorithms/CTW/
4. https://www.cs.cmu.edu/~aarti/Class/10704_Spring15/CTW.pdf (original paper)