sketch_cusum.nx
buildroot/runtime/sketch_cusum.nx
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
imports: syscalls.nxsketch_types.nx
imported by: sketch_cusum_test.nxsketch_cusum_vs_threshold_bench.nx
structs
| 42 | struct Cusum { |
consts
| 38 | const NX_CUSUM_NORMAL: i64 = 0 |
| 39 | const NX_CUSUM_SHIFT_UP: i64 = 1 |
| 40 | const NX_CUSUM_SHIFT_DOWN: i64 = 2 |
functions
| 55 | func nx_cusum_alloc(k: i64, delta: i64, h: i64) -> *Cusum { |
| 73 | func nx_cusum_add(c: *Cusum, x: i64) -> i64 { |
| 91 | func nx_cusum_verdict(c: *Cusum) -> i64 { |
| 99 | func nx_cusum_step(c: *Cusum) -> i64 { |
| 112 | func nx_cusum_s_pos(c: *Cusum) -> i64 { return c.s_pos }
called by 1: main |
| 113 | func nx_cusum_s_neg(c: *Cusum) -> i64 { return c.s_neg }
called by 1: main |
| 114 | func nx_cusum_n(c: *Cusum) -> i64 { return c.n }
called by 1: main |
| 115 | func nx_cusum_n_alarms(c: *Cusum) -> i64 { return c.n_alarms } |
| 117 | func nx_cusum_query(c: *Cusum) -> *ApproxI64 { |
| 124 | func nx_cusum_memory_bytes(c: *Cusum) -> i64 { |
| 128 | func nx_cusum_reset(c: *Cusum) -> i64 {
called by 1: main |