RAVENNAKIT
Loading...
Searching...
No Matches
rav::SlidingStats Class Reference

Values can be added after which different calculations can be performed on the values. More...

#include <sliding_stats.hpp>

Classes

struct  Stats

Public Member Functions

 SlidingStats (const size_t size)
 Constructor.
void add (const double value)
 Adds a new value and recalculates the statistics.
double mean () const
double median () const
double variance () const
double standard_deviation () const
double min () const
double max () const
size_t count () const
bool full () const
double peak_deviation_from_mean () const
Stats get_stats () const
bool is_outlier_median (const double value, const double threshold) const
 Checks if the current value is an outlier compared to the median.
bool is_outlier_zscore (const double value, const double threshold) const
 Checks if the current value is an outlier compared to the average.
std::string to_string (const double multiply_factor=1.0) const
void reset ()
 Resets the sliding window average.

Detailed Description

Values can be added after which different calculations can be performed on the values.

The values are stored in a ring buffer to keep track of the last N values. Older values will be overwritten by newer values.

Definition at line 41 of file sliding_stats.hpp.

Constructor & Destructor Documentation

◆ SlidingStats()

rav::SlidingStats::SlidingStats ( const size_t size)
inlineexplicit

Constructor.

Parameters
sizeThe amount of elements to hold.

Definition at line 57 of file sliding_stats.hpp.

Member Function Documentation

◆ add()

void rav::SlidingStats::add ( const double value)
inline

Adds a new value and recalculates the statistics.

Parameters
valueThe value to add.

Definition at line 63 of file sliding_stats.hpp.

◆ count()

size_t rav::SlidingStats::count ( ) const
inlinenodiscard
Returns
The number of values added to the sliding window average.

Definition at line 120 of file sliding_stats.hpp.

◆ full()

bool rav::SlidingStats::full ( ) const
inlinenodiscard
Returns
True if the window is full, or false otherwise.

Definition at line 127 of file sliding_stats.hpp.

◆ get_stats()

Stats rav::SlidingStats::get_stats ( ) const
inlinenodiscard
Returns
The statistics of the values in the window as a struct. Convenient when data needs to be copied.

Definition at line 141 of file sliding_stats.hpp.

◆ is_outlier_median()

bool rav::SlidingStats::is_outlier_median ( const double value,
const double threshold ) const
inlinenodiscard

Checks if the current value is an outlier compared to the median.

Parameters
valueThe value to check.
thresholdThe threshold for the outlier check.
Returns
True if the current value is an outlier.

Definition at line 152 of file sliding_stats.hpp.

◆ is_outlier_zscore()

bool rav::SlidingStats::is_outlier_zscore ( const double value,
const double threshold ) const
inlinenodiscard

Checks if the current value is an outlier compared to the average.

Parameters
valueThe value to check.
thresholdThe threshold for the outlier check.
Returns
True if the current value is an outlier.

Definition at line 162 of file sliding_stats.hpp.

◆ max()

double rav::SlidingStats::max ( ) const
inlinenodiscard
Returns
The maximum value in the window.

Definition at line 113 of file sliding_stats.hpp.

◆ mean()

double rav::SlidingStats::mean ( ) const
inlinenodiscard
Returns
The last calculated average of the values in the window.

Definition at line 71 of file sliding_stats.hpp.

◆ median()

double rav::SlidingStats::median ( ) const
inlinenodiscard
Returns
The last calculated median of the values in the window.

Definition at line 78 of file sliding_stats.hpp.

◆ min()

double rav::SlidingStats::min ( ) const
inlinenodiscard
Returns
The minimum value in the window.

Definition at line 106 of file sliding_stats.hpp.

◆ peak_deviation_from_mean()

double rav::SlidingStats::peak_deviation_from_mean ( ) const
inlinenodiscard
Returns
The peak deviation from mean (or some form of jitter).

Definition at line 134 of file sliding_stats.hpp.

◆ reset()

void rav::SlidingStats::reset ( )
inline

Resets the sliding window average.

Definition at line 185 of file sliding_stats.hpp.

◆ standard_deviation()

double rav::SlidingStats::standard_deviation ( ) const
inlinenodiscard
Returns
The standard deviation of the values in the window.

Definition at line 99 of file sliding_stats.hpp.

◆ to_string()

std::string rav::SlidingStats::to_string ( const double multiply_factor = 1.0) const
inlinenodiscard
Parameters
multiply_factorThe factor to multiply the values with.
Returns
The values in the window as a string.

Definition at line 174 of file sliding_stats.hpp.

◆ variance()

double rav::SlidingStats::variance ( ) const
inlinenodiscard
Returns
The variance of the values in the window.

Definition at line 85 of file sliding_stats.hpp.


The documentation for this class was generated from the following file: