code wiki / (root) / nx_sketch_mann_kendall.nx

nx_sketch_mann_kendall.nx

buildroot/runtime/nx_sketch_mann_kendall.nx

5841 B178 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_mann_kendall.nx -- streaming Mann-Kendall trend test. Non-parametric trend detection over the last W samples. No distribution assumption -- works on any ordinal data including heavy-tailed, skewed, or with outliers (vs Pearson correlation which assumes linearity + normality). MANN-KENDALL STATISTIC: For each pair (i, j) with i < j in the window: S += sign(x_j - x_i) where sign in {-1, 0, +1} S > 0 = upward trend S < 0 = downward trend |S| > threshold = significant THEORETICAL VARIANCE (no ties): Var(S) = n(n-1)(2n+5)/18 Z = S / sqrt(Var(S)) — standardized, approximately N(0,1) for large n. FOR THE STREAMING VARIANT: maintain a sliding window of W samples. On each new sample: compare against all W-1 previous samples in O(W). Total state: O(W). S incrementally updated. USE CASES: - hydrology: long-term streamflow trends - climatology: warming trend detection - SRE: monotonic latency trend - finance: directional momentum (vs mean-reverting) Production tier; exact integer arithmetic over the window.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sketch_types.nx nx_sketch_mann_kendall.nx

imports: nx_syscalls.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

47struct MannKendall

consts

40const NX_MK_MIN_W: i64 = 3
41const NX_MK_MAX_W: i64 = 100000
43const NX_MK_TREND_NONE: i64 = 0
44const NX_MK_TREND_UP: i64 = 1
45const NX_MK_TREND_DOWN: i64 = 2

functions

57func nx_mk_alloc(window: i64) -> *MannKendall
calls 1: sys_mmap
77func nx_mk_sign(x: i64) -> i64
89func nx_mk_recompute_s(m: *MannKendall) -> i64
called by 1: nx_mk_push calls 1: nx_mk_sign
115func nx_mk_push(m: *MannKendall, value: i64) -> i64
141func nx_mk_var_s(m: *MannKendall) -> i64
called by 1: nx_mk_verdict
153func nx_mk_verdict(m: *MannKendall) -> i64
called by 1: nx_mk_query calls 1: nx_mk_var_s
166func nx_mk_s(m: *MannKendall) -> i64 { return m.s }
167func nx_mk_count(m: *MannKendall) -> i64 { return m.count }
169func nx_mk_query(m: *MannKendall) -> *ApproxI64
176func nx_mk_memory_bytes(m: *MannKendall) -> i64