Predictors and tolerance
A predictor consumes samples (t, x), where t is the unwrapped tick count in
nanoseconds divided by tick_ns. Wire ticks wrap at 65,536 but predictor time
does not. Updating requires a strictly increasing t; reset clears the state.
The polynomial predictors keep a window of samples, oldest first. ewma keeps
a single smoothed level and needs no window.
Built-in predictors
| Kind | Minimum window | Behaviour |
|---|---|---|
hold_last | 1 | Returns the newest final value, or None when empty. |
ewma | none | Flat exponentially weighted moving average; requires alpha. |
linear | 2 | Least-squares degree-1 polynomial. |
quadratic | 3 | Least-squares degree-2 polynomial. |
cubic | 4 | Least-squares degree-3 polynomial. |
For degree d, the polynomial fit uses m = d + 1 time-normalised moments.
With window samples (t_i, x_i), it sets t0 to the oldest time and
S = newest_t - t0, then uses u_i = (t_i - t0) / S. It solves the resulting
m × m system by Gaussian elimination with partial pivoting, rejects pivots
below 1e-12, and evaluates the result by Horner’s method at
u = (t - t0) / S. All accumulation and evaluation order is fixed; there is no
use of fused multiply-add.
Predictions are made for t strictly after the newest sample, so u > 1 is
normal. A fit returning a non-finite result yields None.
EWMA
ewma is configured with a smoothing factor alpha, which must be finite and
in (0, 1]:
predictor: { type: ewma, alpha: 0.2 }
The first sample sets the level exactly. Every later sample updates it with
beta = 1 - alpha cached at construction:
level = alpha * x + beta * level
All operations are plain f64 in that order with no fused multiply-add. A
larger alpha tracks new samples faster; alpha = 1 gives the same result as
hold_last prediction. predict(t) returns the current level for any tick, so
the forecast is flat and does not extrapolate a trend. Irregular tick spacing
does not change the weighting: each accepted sample contributes equally to the
recurrence. A non-finite level yields None.
The state hash covers the sample count, alpha bits, last sample tick and level
bits, in that order as little-endian bytes. Both the Rust implementation and the
Python reference model use this layout.
Opaque fields
bool, enum, string and list fields may only use hold_last. Their
predictor stores the last final value: a slot for bool/enum, UTF-8 bytes for a
string, or one slot per list element. Equality is exact; there is no tolerance.
For a list this means equal length and equal elements after quantisation and
casting.
Tolerance
For numeric fields, tolerance declares abs, rel, or both. With both,
mode: all requires both bounds to pass and mode: any requires either. The
comparison uses final f64 values:
d = |truth - prediction|
a_ok = abs is None or d <= abs
r_ok = rel is None or d <= rel * |truth|
Tolerance is inclusive (<=). It must not be smaller than one quantise step.
auto tolerance is not implemented in v1.
Recovery periods
Each predictor field may declare refresh (K) and reset (K_R) in the
field or in the message sync: block. K_R must be a multiple of K. For
predictors with a window, K must be at least that window; for ewma and
hold_last any positive K is valid. Consecutive committed Refresh frames
are exactly K apart; consecutive Reset frames are exactly K_R apart.
max_resets_per_frame limits how many fields may reset in the same frame.
A Reset clears the receiver’s predictor and immediately updates it with the
included true value. A Refresh only updates. Included is a normal true value
that also updates both ends. See Recovery and validity for the
receiver’s trust rules.