code wiki / (root) / nx_sketch_holt.nx

nx_sketch_holt.nx

buildroot/runtime/nx_sketch_holt.nx

4313 B139 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_holt.nx -- Holt's linear method (double exponential smoothing). Time-series forecasting primitive that extends EWMA with a TREND component. Two recurrences: level_t = alpha * y_t + (1 - alpha) * (level_{t-1} + trend_{t-1}) trend_t = beta * (level_t - level_{t-1}) + (1 - beta) * trend_{t-1} forecast(h) = level_t + h * trend_t (h steps ahead) alpha controls level smoothing; beta controls trend smoothing. Both in PPM [1, 1_000_000]. COMPLEMENTS EWMA (single-component): - EWMA: smoothed level only; bad for trending data - Holt: level + trend; tracks linear trajectories - (Holt-Winters with seasonality is the natural v2) USE CASES: - revenue / user-count forecasting - SRE: capacity planning given growth trends - sensor calibration drift detection INTEGER FIXED-POINT IMPLEMENTATION (no f64): level, trend stored as i64. Updates via PPM arithmetic. Overflow budget: |y| < 2^32 to keep alpha * y in i64. LOSSLESS-LANGUAGE DISCIPLINE: Production tier; envelope NX_ENV_ABS with param_a = 1 (quantization error per step) and conf 1e9.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sketch_types.nx nx_sketch_holt.nx

imports: nx_syscalls.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

43struct Holt

consts

40const NX_HOLT_PPM_MAX: i64 = 1000000
41const NX_HOLT_PPM_MIN: i64 = 1

functions

54func nx_holt_alloc(alpha_ppm: i64, beta_ppm: i64) -> *Holt
calls 1: sys_mmap
76func nx_holt_add(h: *Holt, y: i64) -> i64
106func nx_holt_level(h: *Holt) -> i64
110func nx_holt_trend(h: *Holt) -> i64
115func nx_holt_forecast(holt: *Holt, h: i64) -> i64
119func nx_holt_count(h: *Holt) -> i64
129func nx_holt_query_forecast(holt: *Holt, h: i64) -> *ApproxI64
137func nx_holt_memory_bytes(h: *Holt) -> i64