Skip to main content

TsbFilter

Struct TsbFilter 

Source
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

Source

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].

Source

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.

Source

pub fn warm_up(&mut self, history: &[f64])

Feeds every value of history in order.

Source

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.

Source

pub const fn alphas(&self) -> (f64, f64)

The smoothing parameters of the sizes and of the demand probability.

Source

pub fn forecast(&self) -> f64

The forecast for every horizon, the smoothed probability times the smoothed size: 0 before any non-zero value, NaN before any value.

Trait Implementations§

Source§

impl Clone for TsbFilter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TsbFilter

Source§

impl Debug for TsbFilter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TsbFilter

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TsbFilter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.