code wiki / (root) / nx_sketch_zscore.nx

nx_sketch_zscore.nx

buildroot/runtime/nx_sketch_zscore.nx

4364 B134 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_sketch_stream_stats.nx nx_sketch_types.nx nx_sketch_zscore.nx

imports: nx_syscalls.nxnx_sketch_stream_stats.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

44struct ZScore

consts

38const NX_ZS_VERDICT_NORMAL: i64 = 0
39const NX_ZS_VERDICT_HIGH: i64 = 1
40const NX_ZS_VERDICT_LOW: i64 = 2
42const NX_ZS_MIN_COUNT_DEFAULT: i64 = 30

functions

56func nx_zs_alloc(threshold_ppm: i64, min_count: i64) -> *ZScore
81func nx_zs_score_ppm(z: *ZScore, x: i64) -> i64
91func nx_zs_verdict(z: *ZScore, x: i64) -> i64
100func nx_zs_step(z: *ZScore, x: i64) -> i64
109func nx_zs_count(z: *ZScore) -> i64
calls 1: nx_stats_count
113func nx_zs_mean(z: *ZScore) -> i64
calls 1: nx_stats_mean
117func nx_zs_stddev(z: *ZScore) -> i64
calls 1: nx_stats_stddev
121func nx_zs_n_alarms(z: *ZScore) -> i64
125func nx_zs_query(z: *ZScore, x: i64) -> *ApproxI64
132func nx_zs_memory_bytes(z: *ZScore) -> i64