code wiki / (root) / sketch_markov.nx

sketch_markov.nx

buildroot/runtime/sketch_markov.nx

6231 B198 linesdepth 4pulls 4 transitivereach 2 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 · 2 importers

syscalls.nx sketch_types.nx sketch_markov.nx sketch_markov_test.nx sketch_markov_vs_uniform_bench.nx

imports: syscalls.nxsketch_types.nx

imported by: sketch_markov_test.nxsketch_markov_vs_uniform_bench.nx

structs

34struct Markov {

consts

31const NX_MARKOV_MIN_N: i64 = 2
32const NX_MARKOV_MAX_N: i64 = 1024

functions

45func nx_markov_alloc(n_states: i64) -> *Markov {
called by 2: mainmain
72func nx_markov_cell_idx(m: *Markov, from: i64, to: i64) -> i64 {
80func nx_markov_observe(m: *Markov, from: i64, to: i64) -> i64 {
98func nx_markov_step(m: *Markov, state: i64) -> i64 {
called by 1: main calls 1: nx_markov_observe
111func nx_markov_probability_ppm(m: *Markov, from: i64, to: i64) -> i64 {
124func nx_markov_count(m: *Markov, from: i64, to: i64) -> i64 {
133func nx_markov_row_sum(m: *Markov, from: i64) -> i64 {
called by 1: main
144func nx_markov_predict(m: *Markov, from: i64) -> i64 {
called by 2: mainmain calls 1: nx_markov_count
164func nx_markov_query_probability(m: *Markov, from: i64, to: i64) -> *ApproxI64 {
174func nx_markov_total(m: *Markov) -> i64 {
called by 1: main
178func nx_markov_memory_bytes(m: *Markov) -> i64 {
182func nx_markov_reset(m: *Markov) -> i64 {
called by 1: main