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"
T getVariance() const
Get the variance of stored samples.
void addSample(T x)
Add a new sample to the statistics.
RunningStats< T > operator-(const RunningStats< T > &other) const
Subtract the sequence represented by other from the sequence represented by this and return the updat...
T getMean() const
Get the mean of stored samples.
RunningStats< T > & operator-=(const RunningStats< T > &other)
Subtract the sequence represented by other from the sequence represented by this and update the stats...
void reset()
Reset the statistics to represent an empty sequence.
static T multiplyScalar(const T &val, double scalar)
val * scalar
T getSampleVariance() const
Get the sample variance of stored samples (like variance, but divided by count-1 instead of count...
Computation of running average and variance using Welford&#39;s algorithm.
size_t count
Number of represented samples.
static T sqrt(const T &val)
Return the square root of the given value (whatever meaning that might have).
T getStandardDeviation() const
Get standard deviation of stored samples.
size_t getCount() const
Get the number of stored samples.
Definition: any.hpp:15
void removeSample(T x)
Remove a sample from the statistics.
RunningStats< T > operator+(const RunningStats< T > &other) const
Combine the two sequences represented by this and other and represent their joint stats...
static T zero()
Return a T value representing zero.
static T multiply(const T &val1, const T &val2)
val1 * val2
T var
Sk term of the computation such that var(X0...Xk) = this->var/this->count.
T mean
Mean of represented samples.
RunningStats< T > & operator+=(const RunningStats< T > &other)
Combine the two sequences represented by this and other and represent their joint stats...


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:32:53