skaters
Rust port of the skaters online
distributional forecasting core. Every forecaster is a struct with
step(&mut self, y: f64) -> Vec<Dist>, and all state is plain
serde-serializable data. That is a product contract: a skater can be
checkpointed to JSON and restored.
Parity discipline
No module ships without passing the parity vectors. parity/vectors.json is
generated by the Python reference and embeds the input series, so both sides
run on identical floats. The gate replays every implemented scenario and
compares seven probes per step and horizon (mean, std, logpdf at 0.3, cdf at
0.3, quantiles 0.1 and 0.9, CRPS at 0.3) at atol = rtol = 1e-6:
cargo test --release
# parity: 59 scenarios, 105658 values checked
Coverage is the full library: every transform and leaf at k=1 and k=3, the
ensembles (precision-weighted, bayesian, terminal-leaf), multiscale, sticky
(on the repeat-heavy series), the GPD tail splice, the full laplace
composition (pol_laplace, pol_laplace_k3), the adaptive search
(search_default), the spec build path (spec_diff_ensemble, spec_ema),
the periodicity detector (ranked lag/acf block), and the covariance
estimators (running, EMA, Ledoit-Wolf blocks). Nothing is skipped.
Two details matter for agreement beyond ordinary care with operation order.
Sums that Python computes with the built-in sum() use a Neumaier-compensated
fsum (CPython 3.12+ compensates float sums; naive accumulation diverges the
prune tie-breaks). And Dist::prune reproduces the ulp-tolerant closest-pair
merge exactly, which exists precisely to keep platforms in agreement.
Portable math
All transcendentals (exp, log, log1p, expm1, pow, erf, erfc) route through the
pure-Rust libm crate, never the system libm. Portable math means identical
bits on every platform including wasm32. Parity versus Python remains the
1e-6 vector gate above; within a platform family the Rust core itself is
bit-deterministic.
Usage
use laplace;
let mut f = laplace;
for y in observations
laplace(k) is the general forecaster: a likelihood-weighted ensemble over
the full candidate population with a CRPS terminal leaf, the lattice
projection for repeating values, GPD tail splicing, and PIT/z calibration
state (Parade::pit, Parade::z). At k > 1 it runs multi-scale over
decimated clocks. Building blocks (conjugate, transforms, leaves,
ensembles) are exported for composition.
Python backend (skaters-fast)
rust/python/ is skaters-fast, an opt-in PyO3 skin that lets Python run the
identical laplace model at about 20x the per-step rate of the pure Python
reference with the same bits on every platform. Build it into a venv with
maturin develop --release -m rust/python/Cargo.toml. See
rust/python/README.md.
Benchmark
cargo run --release --bin bench times laplace(1) over 5000 ticks (the
parity series, tiled). On an Apple M-series laptop:
laplace(1) step: 14.1 us/tick
laplace(1) step + mean: 300.5 us/tick
The second line adds one mean() read per tick. After the tail splice
activates (tick 500) that read evaluates a 65-node numeric quantile grid on
the spliced predictive, which is why probing moments costs far more than
stepping. Cheap queries (cdf, logpdf, a single quantile) do not pay that
cost.