code wiki / (root) / sketch_cusum.nx

sketch_cusum.nx

buildroot/runtime/sketch_cusum.nx

4196 B133 linesdepth 4pulls 4 transitivereach 2 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 · 2 importers

syscalls.nx sketch_types.nx sketch_cusum.nx sketch_cusum_test.nx sketch_cusum_vs_threshold_bench.nx

imports: syscalls.nxsketch_types.nx

imported by: sketch_cusum_test.nxsketch_cusum_vs_threshold_bench.nx

structs

42struct Cusum {

consts

38const NX_CUSUM_NORMAL: i64 = 0
39const NX_CUSUM_SHIFT_UP: i64 = 1
40const NX_CUSUM_SHIFT_DOWN: i64 = 2

functions

55func nx_cusum_alloc(k: i64, delta: i64, h: i64) -> *Cusum {
called by 2: mainmain
73func nx_cusum_add(c: *Cusum, x: i64) -> i64 {
called by 2: mainmain
91func nx_cusum_verdict(c: *Cusum) -> i64 {
99func nx_cusum_step(c: *Cusum) -> i64 {
called by 1: main calls 1: nx_cusum_verdict
112func nx_cusum_s_pos(c: *Cusum) -> i64 { return c.s_pos }
called by 1: main
113func nx_cusum_s_neg(c: *Cusum) -> i64 { return c.s_neg }
called by 1: main
114func nx_cusum_n(c: *Cusum) -> i64 { return c.n }
called by 1: main
115func nx_cusum_n_alarms(c: *Cusum) -> i64 { return c.n_alarms }
called by 2: mainmain
117func nx_cusum_query(c: *Cusum) -> *ApproxI64 {
called by 1: main calls 2: nx_cusum_verdictnx_approx_new
124func nx_cusum_memory_bytes(c: *Cusum) -> i64 {
128func nx_cusum_reset(c: *Cusum) -> i64 {
called by 1: main