nx_sketch_mann_kendall.nx
buildroot/runtime/nx_sketch_mann_kendall.nx
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
imports: nx_syscalls.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 47 | struct MannKendall |
consts
| 40 | const NX_MK_MIN_W: i64 = 3 |
| 41 | const NX_MK_MAX_W: i64 = 100000 |
| 43 | const NX_MK_TREND_NONE: i64 = 0 |
| 44 | const NX_MK_TREND_UP: i64 = 1 |
| 45 | const NX_MK_TREND_DOWN: i64 = 2 |
functions
| 57 | func nx_mk_alloc(window: i64) -> *MannKendall calls 1: sys_mmap |
| 77 | func nx_mk_sign(x: i64) -> i64 |
| 89 | func nx_mk_recompute_s(m: *MannKendall) -> i64 |
| 115 | func nx_mk_push(m: *MannKendall, value: i64) -> i64 |
| 141 | func nx_mk_var_s(m: *MannKendall) -> i64 called by 1: nx_mk_verdict |
| 153 | func nx_mk_verdict(m: *MannKendall) -> i64 |
| 166 | func nx_mk_s(m: *MannKendall) -> i64 { return m.s } |
| 167 | func nx_mk_count(m: *MannKendall) -> i64 { return m.count } |
| 169 | func nx_mk_query(m: *MannKendall) -> *ApproxI64 |
| 176 | func nx_mk_memory_bytes(m: *MannKendall) -> i64 |