sketch_markov.nx
buildroot/runtime/sketch_markov.nx
about
sketch_markov.nx -- discrete-state Markov chain transition tracker.
Streaming primitive for sequence modeling. Maintains transition
counts t[i][j] = number of times we saw state i followed by state j.
At query time, transition probabilities P[i][j] = t[i][j] / Σ_k t[i][k]
in PPM (parts per million).
USE CASES:
- log-event sequence modeling (predict next event class)
- DNA / protein sequence analysis
- user-behavior modeling (page A -> page B transitions)
- failure-mode chains (state transitions toward outage)
- text generation (character / word n-grams via k-step extension)
CAPABILITY:
- online learning: every observation updates state
- O(1) per observation
- O(N²) memory (N states); caller-bounded
- exact integer counts; probabilities in PPM at query time
MOST-LIKELY-NEXT-STATE prediction:
nx_markov_predict(s) returns the j with max t[s][j]. When ties
exist, smallest j wins (deterministic).
LOSSLESS-LANGUAGE DISCIPLINE: probabilities in PPM with NX_ENV_ABS
param_a = 1 (PPM quantization). Production tier.
dependencies 2 imports · 2 importers
imports: syscalls.nxsketch_types.nx
imported by: sketch_markov_test.nxsketch_markov_vs_uniform_bench.nx
structs
| 34 | struct Markov { |
consts
| 31 | const NX_MARKOV_MIN_N: i64 = 2 |
| 32 | const NX_MARKOV_MAX_N: i64 = 1024 |
functions
| 45 | func nx_markov_alloc(n_states: i64) -> *Markov { |
| 72 | func nx_markov_cell_idx(m: *Markov, from: i64, to: i64) -> i64 { |
| 80 | func nx_markov_observe(m: *Markov, from: i64, to: i64) -> i64 { |
| 98 | func nx_markov_step(m: *Markov, state: i64) -> i64 { |
| 111 | func nx_markov_probability_ppm(m: *Markov, from: i64, to: i64) -> i64 { |
| 124 | func nx_markov_count(m: *Markov, from: i64, to: i64) -> i64 { |
| 133 | func nx_markov_row_sum(m: *Markov, from: i64) -> i64 {
called by 1: main |
| 144 | func nx_markov_predict(m: *Markov, from: i64) -> i64 { |
| 164 | func nx_markov_query_probability(m: *Markov, from: i64, to: i64) -> *ApproxI64 { |
| 174 | func nx_markov_total(m: *Markov) -> i64 {
called by 1: main |
| 178 | func nx_markov_memory_bytes(m: *Markov) -> i64 { |
| 182 | func nx_markov_reset(m: *Markov) -> i64 {
called by 1: main |