Class MovingAverageStatistics

Class Documentation

class MovingAverageStatistics

A class for calculating moving average statistics. This operates in constant memory and constant time. Note: reset() must be called manually in order to start a new measurement window.

The statistics calculated are average, maximum, minimum, and standard deviation (population). All are calculated online without storing the observation data. Specifically, the average is a running sum and the variance is obtained by Welford’s online algorithm (reference: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford%27s_online_algorithm) for standard deviation.

When statistics are not available, e.g. no observations have been made, NaNs are returned.

Public Types

using StatisticData = libstatistics_collector::moving_average_statistics::StatisticData

Public Functions

MovingAverageStatistics() = default
~MovingAverageStatistics() = default
inline double get_average() const

Returns the arithmetic mean of all data recorded. If no observations have been made, returns NaN.

Returns:

The arithmetic mean of all data recorded, or NaN if the sample count is 0.

inline double get_max() const

Returns the maximum value recorded. If size of list is zero, returns NaN.

Returns:

The maximum value recorded, or NaN if size of data is zero.

inline double get_min() const

Returns the minimum value recorded. If size of list is zero, returns NaN.

Returns:

The minimum value recorded, or NaN if size of data is zero.

inline double get_standard_deviation() const

Returns the standard deviation (population) of all data recorded. If size of list is zero, returns NaN.

Variance is obtained by Welford’s online algorithm, see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford%27s_online_algorithm

Returns:

The standard deviation (population) of all data recorded, or NaN if size of data is zero.

inline const StatisticData &get_statistics_const_ptr() const

Return a StatisticData object, containing average, minimum, maximum, standard deviation (population), and sample count. For the case of no observations, the average, min, max, and standard deviation are NaN.

Returns:

StatisticData object, containing average, minimum, maximum, standard deviation (population), and sample count.

inline StatisticData get_statistics() const
inline const double &get_current_measurement_const_ptr() const

Get the current measurement value. This is the last value added to the statistics collector.

Returns:

The current measurement value, or NaN if no measurements have been made.

inline double get_current_measurement() const
inline void reset()

Reset all calculated values. Equivalent to a new window for a moving average.

inline void reset_current_measurement()
inline void add_measurement(const double item)

Observe a sample for the given window. The input item is used to calculate statistics. Note: any input values of NaN will be discarded and not added as a measurement.

Parameters:

item – The item that was observed

inline uint64_t get_count() const

Return the number of samples observed

Returns:

the number of samples observed