code wiki / (root) / sketch_mann_kendall.nx

sketch_mann_kendall.nx

buildroot/runtime/sketch_mann_kendall.nx

5756 B172 linesdepth 4pulls 4 transitivereach 2 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 · 2 importers

syscalls.nx sketch_types.nx sketch_mann_kendall.nx sketch_mann_kendall_test.nx sketch_mann_kendall_vs_endpoint_be

imports: syscalls.nxsketch_types.nx

imported by: sketch_mann_kendall_test.nxsketch_mann_kendall_vs_endpoint_bench.nx

structs

41struct MannKendall {

consts

34const NX_MK_MIN_W: i64 = 3
35const NX_MK_MAX_W: i64 = 100000
37const NX_MK_TREND_NONE: i64 = 0
38const NX_MK_TREND_UP: i64 = 1
39const NX_MK_TREND_DOWN: i64 = 2

functions

51func nx_mk_alloc(window: i64) -> *MannKendall {
called by 2: mainmain
71func nx_mk_sign(x: i64) -> i64 {
83func nx_mk_recompute_s(m: *MannKendall) -> i64 {
called by 1: nx_mk_push calls 1: nx_mk_sign
109func nx_mk_push(m: *MannKendall, value: i64) -> i64 {
135func nx_mk_var_s(m: *MannKendall) -> i64 {
called by 1: nx_mk_verdict
147func nx_mk_verdict(m: *MannKendall) -> i64 {
called by 3: nx_mk_querymainmain calls 1: nx_mk_var_s
160func nx_mk_s(m: *MannKendall) -> i64 { return m.s }
called by 2: mainmain
161func nx_mk_count(m: *MannKendall) -> i64 { return m.count }
163func nx_mk_query(m: *MannKendall) -> *ApproxI64 {
called by 1: main calls 2: nx_mk_verdictnx_approx_new
170func nx_mk_memory_bytes(m: *MannKendall) -> i64 {