nx_sketch_holt.nx
buildroot/runtime/nx_sketch_holt.nx
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
imports: nx_syscalls.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 43 | struct Holt |
consts
| 40 | const NX_HOLT_PPM_MAX: i64 = 1000000 |
| 41 | const NX_HOLT_PPM_MIN: i64 = 1 |
functions
| 54 | func nx_holt_alloc(alpha_ppm: i64, beta_ppm: i64) -> *Holt calls 1: sys_mmap |
| 76 | func nx_holt_add(h: *Holt, y: i64) -> i64 |
| 106 | func nx_holt_level(h: *Holt) -> i64 |
| 110 | func nx_holt_trend(h: *Holt) -> i64 |
| 115 | func nx_holt_forecast(holt: *Holt, h: i64) -> i64 called by 1: nx_holt_query_forecast |
| 119 | func nx_holt_count(h: *Holt) -> i64 |
| 129 | func nx_holt_query_forecast(holt: *Holt, h: i64) -> *ApproxI64 |
| 137 | func nx_holt_memory_bytes(h: *Holt) -> i64 |