Struct Statistics

Source
pub struct Statistics<T> { /* private fields */ }
Expand description

A structure that computes various statistics over a fixed-size window of values.

Statistics<T> maintains a circular buffer of values and computes statistical measures such as mean, variance, standard deviation, median, etc. It can handle both single value statistics and paired statistics (when T is a tuple).

The structure automatically updates statistics as new values are added and old values are removed from the window, making it efficient for streaming data analysis.

§Type Parameters

  • T - The type of values to compute statistics over. Can be a single numeric type or a tuple for paired statistics.

Implementations§

Source§

impl<T> Statistics<T>

Source

pub fn new(period: usize) -> Self
where T: Copy + Default,

Creates a new statistics object with the specified period

§Arguments
  • period - The period of the statistics
§Returns
  • Statistics<T> - The new statistics object
Source

pub fn reset(&mut self) -> &mut Self
where T: Default + Copy,

Resets the statistics

§Returns
  • &mut Self - The statistics object
Source

pub const fn len(&self) -> usize

Returns the current number of elements in the buffer.

§Returns
  • usize - The current number of elements in the buffer
Source

pub const fn is_full(&self) -> bool

Check if the statistics buffer is full

§Returns
  • bool - True if the statistics buffer is full
Source

pub const fn period(&self) -> usize

Returns the period of the statistics

§Returns
  • usize - The period of the statistics
Source

pub const fn ddof(&self) -> bool

Returns the Delta Degrees of Freedom

§Returns
  • bool - The Delta Degrees of Freedom
Source

pub const fn set_ddof(&mut self, ddof: bool) -> &mut Self

Sets the Delta Degrees of Freedom

§Arguments
  • ddof - The Delta Degrees of Freedom
§Returns
  • &mut Self - The statistics object

Trait Implementations§

Source§

impl<T: Clone> Clone for Statistics<T>

Source§

fn clone(&self) -> Statistics<T>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Statistics<T>

Source§

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

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

impl<T: Float + Default> PairedStatistics<T> for Statistics<(T, T)>

Source§

fn next(&mut self, (x, y): (T, T)) -> &mut Self

Updates the paired statistical calculations with a new value pair in the time series Read more
Source§

fn cov(&self) -> Option<T>

Returns the covariance of the paired values in the rolling window Read more
Source§

fn corr(&self) -> Option<T>

Returns the correlation coefficient (Pearson’s r) of paired values in the rolling window Read more
Source§

fn beta(&self) -> Option<T>

Returns the beta coefficient of the paired values in the rolling window Read more
Source§

impl<T: Float + Default + Sum> SingleStatistics<T> for Statistics<T>

Source§

fn next(&mut self, value: T) -> &mut Self

Updates the statistical calculations with a new value in the time series Read more
Source§

fn sum(&self) -> Option<T>

Returns the sum of all values in the rolling window Read more
Source§

fn sum_sq(&self) -> Option<T>

Returns the sum of squares of all values in the rolling window Read more
Source§

fn mean(&self) -> Option<T>

Returns the arithmetic mean of all values in the rolling window Read more
Source§

fn mean_sq(&self) -> Option<T>

Returns the mean of squares of all values in the rolling window Read more
Source§

fn mode(&mut self) -> Option<T>

Returns the mode (most frequently occurring value) in the rolling window Read more
Source§

fn median(&mut self) -> Option<T>

Returns the median (middle value) of the rolling window Read more
Source§

fn min(&mut self) -> Option<T>

Returns the minimum value in the rolling window Read more
Source§

fn max(&mut self) -> Option<T>

Returns the maximum value in the rolling window Read more
Source§

fn mean_absolute_deviation(&self) -> Option<T>

Returns the mean absolute deviation of values in the rolling window Read more
Source§

fn median_absolute_deviation(&mut self) -> Option<T>

Returns the median absolute deviation of values in the rolling window Read more
Source§

fn variance(&self) -> Option<T>

Returns the variance of values in the rolling window Read more
Source§

fn stddev(&self) -> Option<T>

Returns the standard deviation of values in the rolling window Read more
Source§

fn zscore(&self) -> Option<T>

Returns the z-score of the most recent value relative to the rolling window Read more
Source§

fn skew(&self) -> Option<T>

Returns the skewness of values in the rolling window Read more
Source§

fn kurt(&self) -> Option<T>

Returns the kurtosis of values in the rolling window Read more
Source§

fn linreg_slope(&self) -> Option<T>

Returns the slope of the linear regression line Read more
Source§

fn linreg_slope_intercept(&self) -> Option<(T, T)>

Returns both slope and intercept of the linear regression line Read more
Source§

fn linreg_intercept(&self) -> Option<T>

Returns the y-intercept of the linear regression line Read more
Source§

fn linreg_angle(&self) -> Option<T>

Returns the angle (in degrees) of the linear regression line Read more
Source§

fn linreg(&self) -> Option<T>

Returns the linear regression value (predicted y) for the last position Read more
Source§

fn drawdown(&mut self) -> Option<T>

Returns the current drawdown from peak Read more
Source§

fn max_drawdown(&mut self) -> Option<T>

Returns the maximum drawdown in the window Read more
Source§

fn diff(&self) -> Option<T>

Returns the difference between the last and first values Read more
Source§

fn pct_change(&self) -> Option<T>

Returns the percentage change between the first and last values Read more
Source§

fn log_return(&self) -> Option<T>

Returns the logarithmic return between the first and last values Read more
Source§

fn quantile(&mut self, q: f64) -> Option<T>

Returns the quantile of the values in the window Read more
Source§

fn iqr(&mut self) -> Option<T>

Returns the interquartile range of the values in the window Read more

Auto Trait Implementations§

§

impl<T> Freeze for Statistics<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Statistics<T>
where T: RefUnwindSafe,

§

impl<T> Send for Statistics<T>
where T: Send,

§

impl<T> Sync for Statistics<T>
where T: Sync,

§

impl<T> Unpin for Statistics<T>
where T: Unpin,

§

impl<T> UnwindSafe for Statistics<T>
where T: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.