running_stats.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <cmath>
12 #include <cstddef>
13 
14 namespace cras
15 {
16 
27 template<typename T>
29 {
30 public:
34  void reset();
35 
41  void addSample(T x);
42 
51  void removeSample(T x);
52 
57  size_t getCount() const;
58 
64  T getMean() const;
65 
71  T getVariance() const;
72 
79  T getSampleVariance() const;
80 
87  T getStandardDeviation() const;
88 
96 
103  RunningStats<T> operator+(const RunningStats<T>& other) const;
104 
111  RunningStats<T>& operator+=(const T& sample);
112 
119  RunningStats<T> operator+(const T& sample) const;
120 
129 
138  RunningStats<T> operator-(const RunningStats<T>& other) const;
139 
149  RunningStats<T>& operator-=(const T& sample);
150 
160  RunningStats<T> operator-(const T& sample) const;
161 
162 protected:
169  static T multiplyScalar(const T& val, double scalar);
170 
177  static T multiply(const T& val1, const T& val2);
178 
184  static T sqrt(const T& val);
185 
190  static T zero();
191 
193  size_t count {0u};
194 
197 
200 };
201 
202 }
203 
204 #include "impl/running_stats.hpp"
cras::RunningStats::sqrt
static T sqrt(const T &val)
Return the square root of the given value (whatever meaning that might have).
cras
Definition: any.hpp:15
cras::RunningStats
Computation of running average and variance using Welford's algorithm.
Definition: running_stats.hpp:28
cras::RunningStats::removeSample
void removeSample(T x)
Remove a sample from the statistics.
cras::RunningStats::operator-
RunningStats< T > operator-(const RunningStats< T > &other) const
Subtract the sequence represented by other from the sequence represented by this and return the updat...
cras::RunningStats::var
T var
Sk term of the computation such that var(X0...Xk) = this->var/this->count.
Definition: running_stats.hpp:199
cras::RunningStats::operator-=
RunningStats< T > & operator-=(const RunningStats< T > &other)
Subtract the sequence represented by other from the sequence represented by this and update the stats...
cras::RunningStats::zero
static T zero()
Return a T value representing zero.
cras::RunningStats::reset
void reset()
Reset the statistics to represent an empty sequence.
cras::RunningStats::getSampleVariance
T getSampleVariance() const
Get the sample variance of stored samples (like variance, but divided by count-1 instead of count,...
cras::RunningStats::getStandardDeviation
T getStandardDeviation() const
Get standard deviation of stored samples.
cras::RunningStats::getMean
T getMean() const
Get the mean of stored samples.
cras::RunningStats::mean
T mean
Mean of represented samples.
Definition: running_stats.hpp:196
cras::RunningStats::operator+=
RunningStats< T > & operator+=(const RunningStats< T > &other)
Combine the two sequences represented by this and other and represent their joint stats.
cras::RunningStats::getVariance
T getVariance() const
Get the variance of stored samples.
cras::RunningStats::multiply
static T multiply(const T &val1, const T &val2)
val1 * val2
cras::RunningStats::operator+
RunningStats< T > operator+(const RunningStats< T > &other) const
Combine the two sequences represented by this and other and represent their joint stats.
cras::RunningStats::getCount
size_t getCount() const
Get the number of stored samples.
cras::RunningStats::multiplyScalar
static T multiplyScalar(const T &val, double scalar)
val * scalar
cras::RunningStats::count
size_t count
Number of represented samples.
Definition: running_stats.hpp:193
cras::RunningStats::addSample
void addSample(T x)
Add a new sample to the statistics.


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04