code wiki / (root) / nx_sketch_markov.nx

nx_sketch_markov.nx

buildroot/runtime/nx_sketch_markov.nx

6290 B204 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_sketch_types.nx nx_sketch_markov.nx

imports: nx_syscalls.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

40struct Markov

consts

37const NX_MARKOV_MIN_N: i64 = 2
38const NX_MARKOV_MAX_N: i64 = 1024

functions

51func nx_markov_alloc(n_states: i64) -> *Markov
calls 1: sys_mmap
78func nx_markov_cell_idx(m: *Markov, from: i64, to: i64) -> i64
86func nx_markov_observe(m: *Markov, from: i64, to: i64) -> i64
called by 1: nx_markov_step calls 1: nx_markov_cell_idx
104func nx_markov_step(m: *Markov, state: i64) -> i64
117func nx_markov_probability_ppm(m: *Markov, from: i64, to: i64) -> i64
130func nx_markov_count(m: *Markov, from: i64, to: i64) -> i64
139func nx_markov_row_sum(m: *Markov, from: i64) -> i64
150func nx_markov_predict(m: *Markov, from: i64) -> i64
calls 1: nx_markov_count
170func nx_markov_query_probability(m: *Markov, from: i64, to: i64) -> *ApproxI64
180func nx_markov_total(m: *Markov) -> i64
184func nx_markov_memory_bytes(m: *Markov) -> i64
188func nx_markov_reset(m: *Markov) -> i64