sketch_mann_kendall.nx
buildroot/runtime/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 · 2 importers
imports: syscalls.nxsketch_types.nx
imported by: sketch_mann_kendall_test.nxsketch_mann_kendall_vs_endpoint_bench.nx
structs
| 41 | struct MannKendall { |
consts
| 34 | const NX_MK_MIN_W: i64 = 3 |
| 35 | const NX_MK_MAX_W: i64 = 100000 |
| 37 | const NX_MK_TREND_NONE: i64 = 0 |
| 38 | const NX_MK_TREND_UP: i64 = 1 |
| 39 | const NX_MK_TREND_DOWN: i64 = 2 |
functions
| 51 | func nx_mk_alloc(window: i64) -> *MannKendall { |
| 71 | func nx_mk_sign(x: i64) -> i64 { |
| 83 | func nx_mk_recompute_s(m: *MannKendall) -> i64 { |
| 109 | func nx_mk_push(m: *MannKendall, value: i64) -> i64 { |
| 135 | func nx_mk_var_s(m: *MannKendall) -> i64 {
called by 1: nx_mk_verdict |
| 147 | func nx_mk_verdict(m: *MannKendall) -> i64 { |
| 160 | func nx_mk_s(m: *MannKendall) -> i64 { return m.s } |
| 161 | func nx_mk_count(m: *MannKendall) -> i64 { return m.count } |
| 163 | func nx_mk_query(m: *MannKendall) -> *ApproxI64 { |
| 170 | func nx_mk_memory_bytes(m: *MannKendall) -> i64 { |