nx_sketch_markov.nx
buildroot/runtime/nx_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 · 0 importers
imports: nx_syscalls.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 40 | struct Markov |
consts
| 37 | const NX_MARKOV_MIN_N: i64 = 2 |
| 38 | const NX_MARKOV_MAX_N: i64 = 1024 |
functions
| 51 | func nx_markov_alloc(n_states: i64) -> *Markov calls 1: sys_mmap |
| 78 | func nx_markov_cell_idx(m: *Markov, from: i64, to: i64) -> i64 |
| 86 | func nx_markov_observe(m: *Markov, from: i64, to: i64) -> i64 |
| 104 | func nx_markov_step(m: *Markov, state: i64) -> i64 calls 1: nx_markov_observe |
| 117 | func nx_markov_probability_ppm(m: *Markov, from: i64, to: i64) -> i64 |
| 130 | func nx_markov_count(m: *Markov, from: i64, to: i64) -> i64 |
| 139 | func nx_markov_row_sum(m: *Markov, from: i64) -> i64 |
| 150 | func nx_markov_predict(m: *Markov, from: i64) -> i64 calls 1: nx_markov_count |
| 170 | func nx_markov_query_probability(m: *Markov, from: i64, to: i64) -> *ApproxI64 |
| 180 | func nx_markov_total(m: *Markov) -> i64 |
| 184 | func nx_markov_memory_bytes(m: *Markov) -> i64 |
| 188 | func nx_markov_reset(m: *Markov) -> i64 |