pub struct TsbFilter { /* private fields */ }Expand description
The method of Teunter, Syntetos and Babai (TSB) on a stream of demand values, with no heap.
The probability that a period has demand is smoothed every period with
alpha_probability, the size of the non-zero values only when one occurs with
alpha_size; both start from their first value, as statsforecast’s TSB. The forecast
for every horizon is their product.
§Examples
use backshift::TsbFilter;
let mut filter = TsbFilter::new(0.5, 0.2).unwrap();
filter.warm_up(&[0.0, 3.0, 0.0, 0.0, 5.0]);
// Probability 0.3024 (from 0, 1, 0, 0, 1), size 4 (from 3 and 5).
assert!((filter.forecast() - 1.2096).abs() < 1e-12);Implementations§
Source§impl TsbFilter
impl TsbFilter
Sourcepub fn new(alpha_size: f64, alpha_probability: f64) -> Result<Self, FilterError>
pub fn new(alpha_size: f64, alpha_probability: f64) -> Result<Self, FilterError>
A filter with the smoothing parameters of the sizes and of the demand probability, before any value.
§Errors
FilterError::InvalidParameter unless both lie in (0, 1].
Sourcepub fn update(&mut self, y: f64) -> f64
pub fn update(&mut self, y: f64) -> f64
Feeds one period’s demand and returns its error against the forecast before it
(NaN before the first value).
A negative or non-finite value counts as missing: its error is NaN, and nothing is
smoothed.
Sourcepub fn optimised(history: &[f64]) -> Result<Self, FilterError>
pub fn optimised(history: &[f64]) -> Result<Self, FilterError>
The filter whose smoothing parameters minimise the mean squared one-step error over
history, warmed up on it, without a heap.
A coarse grid over both parameters picks a start; searches on each in turn (a grid refined by Brent’s method) improve it.
§Errors
FilterError::InvalidParameter if history has fewer than two non-zero values.