code wiki / (root) / nx_sketch_cusum.nx

nx_sketch_cusum.nx

buildroot/runtime/nx_sketch_cusum.nx

4320 B139 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_cusum.nx -- CUSUM change-point detector (Page 1954). Detects shifts in stream mean from a known reference value. Maintains two cumulative sums: S+_t = max(0, S+_{t-1} + (x_t - k - delta)) S-_t = max(0, S-_{t-1} - (x_t - k - delta)) where: k = reference target value (expected mean) delta = slack tolerance (don't alarm on tiny perturbations) ALARM: S+ > h -> upward shift detected (mean increased) S- > h -> downward shift detected (mean decreased) h is the alarm threshold (caller-tuned for false-positive rate). CAPABILITY: - Real-time change-point detection in O(1) state - SRE: latency / error-rate shift detection - manufacturing QC: process drift - finance: regime change - sensor: equipment fault THEORETICAL: Average run length (ARL) under null: ~ exp(h) ARL under shift of size delta: ~ h / delta All integer arithmetic, EXACT semantics. Production tier. LOSSLESS-LANGUAGE DISCIPLINE: alarm verdict is exact (sealed enum-like). nx_cusum_query returns the current statistic with NX_ENV_ABS, param_a = 0.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sketch_types.nx nx_sketch_cusum.nx

imports: nx_syscalls.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

48struct Cusum

consts

44const NX_CUSUM_NORMAL: i64 = 0
45const NX_CUSUM_SHIFT_UP: i64 = 1
46const NX_CUSUM_SHIFT_DOWN: i64 = 2

functions

61func nx_cusum_alloc(k: i64, delta: i64, h: i64) -> *Cusum
calls 1: sys_mmap
79func nx_cusum_add(c: *Cusum, x: i64) -> i64
97func nx_cusum_verdict(c: *Cusum) -> i64
105func nx_cusum_step(c: *Cusum) -> i64
118func nx_cusum_s_pos(c: *Cusum) -> i64 { return c.s_pos }
119func nx_cusum_s_neg(c: *Cusum) -> i64 { return c.s_neg }
120func nx_cusum_n(c: *Cusum) -> i64 { return c.n }
121func nx_cusum_n_alarms(c: *Cusum) -> i64 { return c.n_alarms }
123func nx_cusum_query(c: *Cusum) -> *ApproxI64
130func nx_cusum_memory_bytes(c: *Cusum) -> i64
134func nx_cusum_reset(c: *Cusum) -> i64