nx_sketch_zscore.nx
buildroot/runtime/nx_sketch_zscore.nx
about
sketch_zscore.nx -- point z-score anomaly detector.
Composes against sketch_stream_stats (running mean + stddev) to flag
individual samples deviating from the streaming baseline:
z = (x - mean) / stddev
alarm if |z| > threshold (typical 2.0 ~ 95% conf, 3.0 ~ 99.7%)
CAPABILITY:
- O(1) state (mean + variance from StreamStats)
- online: baseline updates with every sample
- Returns Z in PPM ([-1e10, +1e10] practical range)
- Sealed verdict: NORMAL / HIGH / LOW
COMPLEMENTS THE ANOMALY FAMILY:
- sketch_cusum cumulative shift over a window
- sketch_mann_kendall monotonic trend test
- sketch_zscore (this) point outlier vs running baseline
CONFIGURATION:
"warm-up" period: do not raise alarms until count >= min_count.
Default: min_count = 30 (statistician's rule-of-thumb for CLT).
LOSSLESS-LANGUAGE DISCIPLINE: returns z in PPM with NX_ENV_ABS,
param_a = 1 (PPM quantization). Production tier; exact integer
arithmetic over the running statistics.
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_sketch_stream_stats.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 44 | struct ZScore |
consts
| 38 | const NX_ZS_VERDICT_NORMAL: i64 = 0 |
| 39 | const NX_ZS_VERDICT_HIGH: i64 = 1 |
| 40 | const NX_ZS_VERDICT_LOW: i64 = 2 |
| 42 | const NX_ZS_MIN_COUNT_DEFAULT: i64 = 30 |
functions
| 56 | func nx_zs_alloc(threshold_ppm: i64, min_count: i64) -> *ZScore |
| 81 | func nx_zs_score_ppm(z: *ZScore, x: i64) -> i64 |
| 91 | func nx_zs_verdict(z: *ZScore, x: i64) -> i64 |
| 100 | func nx_zs_step(z: *ZScore, x: i64) -> i64 |
| 109 | func nx_zs_count(z: *ZScore) -> i64 calls 1: nx_stats_count |
| 113 | func nx_zs_mean(z: *ZScore) -> i64 calls 1: nx_stats_mean |
| 117 | func nx_zs_stddev(z: *ZScore) -> i64 calls 1: nx_stats_stddev |
| 121 | func nx_zs_n_alarms(z: *ZScore) -> i64 |
| 125 | func nx_zs_query(z: *ZScore, x: i64) -> *ApproxI64 |
| 132 | func nx_zs_memory_bytes(z: *ZScore) -> i64 calls 1: nx_stats_memory_bytes |