sketch_holt.nx
buildroot/runtime/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 · 2 importers
imports: syscalls.nxsketch_types.nx
imported by: sketch_holt_test.nxsketch_holt_vs_ewma_trended_bench.nx
structs
| 37 | struct Holt { |
consts
| 34 | const NX_HOLT_PPM_MAX: i64 = 1000000 |
| 35 | const NX_HOLT_PPM_MIN: i64 = 1 |
functions
| 48 | func nx_holt_alloc(alpha_ppm: i64, beta_ppm: i64) -> *Holt { |
| 70 | func nx_holt_add(h: *Holt, y: i64) -> i64 { |
| 100 | func nx_holt_level(h: *Holt) -> i64 {
called by 1: main |
| 104 | func nx_holt_trend(h: *Holt) -> i64 {
called by 1: main |
| 109 | func nx_holt_forecast(holt: *Holt, h: i64) -> i64 { |
| 113 | func nx_holt_count(h: *Holt) -> i64 {
called by 1: main |
| 123 | func nx_holt_query_forecast(holt: *Holt, h: i64) -> *ApproxI64 { |
| 131 | func nx_holt_memory_bytes(h: *Holt) -> i64 { |