18 #ifndef MATHS_EXPONENTIAL_MOVING_VARIANCE
19 #define MATHS_EXPONENTIAL_MOVING_VARIANCE
56 template<
typename T =
float>
62 std::atomic<T> average;
64 std::atomic<T> variance = 0.f;
86 inline void reset(T observation = 0) {
87 average = observation;
114 T delta = observation - average;
115 average = average + alpha * delta;
116 variance = (
ALPHA_MAX - alpha) * (variance + alpha * delta * delta);
144 #endif // MATHS_EXPONENTIAL_MOVING_VARIANCE
T get_stddev() const
Return the current value of the exponential moving standard deviation .
Definition: exponential_moving_variance.hpp:139
static constexpr T ALPHA_MAX
the maximal value for alpha to take
Definition: exponential_moving_variance.hpp:70
ExponentialMovingVariance(T alpha_, T observation=0)
Initialize an exponential moving variance with given and .
Definition: exponential_moving_variance.hpp:78
A structure for calculating an exponential moving variance.
Definition: exponential_moving_variance.hpp:57
void set_alpha(T alpha_)
Set the parameter to a new value.
Definition: exponential_moving_variance.hpp:95
static constexpr T ALPHA_MIN
the minimal value for alpha to take
Definition: exponential_moving_variance.hpp:68
T get_alpha() const
Return the parameter.
Definition: exponential_moving_variance.hpp:104
T get_variance() const
Return the current value of the exponential moving variance .
Definition: exponential_moving_variance.hpp:132
T get_average() const
Return the current value of the exponential moving average .
Definition: exponential_moving_variance.hpp:125
Functions for doing maths.
Definition: exponential_moving_average.hpp:25
T process(T observation)
Calculate the next average and variance based on observation .
Definition: exponential_moving_variance.hpp:113
void reset(T observation=0)
Reset the average to initial state with observation . The initial variance is 0.
Definition: exponential_moving_variance.hpp:86