Computation of running average and variance using Welford's algorithm. More...
#include <running_stats.hpp>
Public Member Functions | |
void | addSample (T x) |
Add a new sample to the statistics. More... | |
size_t | getCount () const |
Get the number of stored samples. More... | |
T | getMean () const |
Get the mean of stored samples. More... | |
T | getSampleVariance () const |
Get the sample variance of stored samples (like variance, but divided by count-1 instead of count, should be unbiased estimator). More... | |
T | getStandardDeviation () const |
Get standard deviation of stored samples. More... | |
T | getVariance () const |
Get the variance of stored samples. More... | |
RunningStats< T > | operator+ (const RunningStats< T > &other) const |
Combine the two sequences represented by this and other and represent their joint stats. More... | |
RunningStats< T > | operator+ (const T &sample) const |
Return a copy of this with the added sample. More... | |
RunningStats< T > & | operator+= (const RunningStats< T > &other) |
Combine the two sequences represented by this and other and represent their joint stats. More... | |
RunningStats< T > & | operator+= (const T &sample) |
Add the sample to the stats. More... | |
RunningStats< T > | operator- (const RunningStats< T > &other) const |
Subtract the sequence represented by other from the sequence represented by this and return the updated stats. More... | |
RunningStats< T > | operator- (const T &sample) const |
Remove a sample from the statistics. More... | |
RunningStats< T > & | operator-= (const RunningStats< T > &other) |
Subtract the sequence represented by other from the sequence represented by this and update the stats. More... | |
RunningStats< T > & | operator-= (const T &sample) |
Remove a sample from the statistics. More... | |
void | removeSample (T x) |
Remove a sample from the statistics. More... | |
void | reset () |
Reset the statistics to represent an empty sequence. More... | |
Protected Member Functions | |
ros::Duration | multiply (const ::ros::Duration &val1, const ::ros::Duration &val2) |
ros::WallDuration | multiply (const ::ros::WallDuration &val1, const ::ros::WallDuration &val2) |
ros::Duration | sqrt (const ::ros::Duration &val) |
ros::WallDuration | sqrt (const ::ros::WallDuration &val) |
ros::Duration | zero () |
ros::WallDuration | zero () |
Static Protected Member Functions | |
static T | multiply (const T &val1, const T &val2) |
val1 * val2 More... | |
static T | multiplyScalar (const T &val, double scalar) |
val * scalar More... | |
static T | sqrt (const T &val) |
Return the square root of the given value (whatever meaning that might have). More... | |
static T | zero () |
Return a T value representing zero. More... | |
Protected Attributes | |
size_t | count {0u} |
Number of represented samples. More... | |
T | mean {RunningStats<T>::zero()} |
Mean of represented samples. More... | |
T | var {RunningStats<T>::zero()} |
Sk term of the computation such that var(X0...Xk) = this->var/this->count. More... | |
Computation of running average and variance using Welford's algorithm.
T | Type of the values. It has to support operator+ and operator- with T. |
This class can keep track of mean and variance of a stream of data using an efficient online algorithm. The required memory is constant, and time to insert a new value and update the stats is also constant.
You can also add and subtract instances of this class which behaves as if you merged / diffed the streams that created the stats.
Definition at line 28 of file running_stats.hpp.
void cras::RunningStats< T >::addSample | ( | T | x | ) |
Add a new sample to the statistics.
[in] | x | The sample to add. |
size_t cras::RunningStats< T >::getCount | ( | ) | const |
Get the number of stored samples.
T cras::RunningStats< T >::getMean | ( | ) | const |
Get the mean of stored samples.
T cras::RunningStats< T >::getSampleVariance | ( | ) | const |
Get the sample variance of stored samples (like variance, but divided by count-1 instead of count, should be unbiased estimator).
T cras::RunningStats< T >::getStandardDeviation | ( | ) | const |
Get standard deviation of stored samples.
T cras::RunningStats< T >::getVariance | ( | ) | const |
Get the variance of stored samples.
|
protected |
Definition at line 21 of file running_stats_duration.hpp.
|
protected |
Definition at line 43 of file running_stats_duration.hpp.
|
staticprotected |
val1 * val2
[in] | val1 | Multiplicand. |
[in] | val2 | Multiplicand. |
|
staticprotected |
val * scalar
[in] | val | The value to multiply. |
[in] | scalar | The scalar to multiply with. |
RunningStats<T> cras::RunningStats< T >::operator+ | ( | const RunningStats< T > & | other | ) | const |
Combine the two sequences represented by this and other and represent their joint stats.
[in] | other | The other stats to merge. |
RunningStats<T> cras::RunningStats< T >::operator+ | ( | const T & | sample | ) | const |
Return a copy of this with the added sample.
[in] | sample | The sample to add. |
RunningStats<T>& cras::RunningStats< T >::operator+= | ( | const RunningStats< T > & | other | ) |
Combine the two sequences represented by this and other and represent their joint stats.
[in] | other | The other stats to merge. |
RunningStats<T>& cras::RunningStats< T >::operator+= | ( | const T & | sample | ) |
Add the sample to the stats.
[in] | sample | The sample to add. |
RunningStats<T> cras::RunningStats< T >::operator- | ( | const RunningStats< T > & | other | ) | const |
Subtract the sequence represented by other from the sequence represented by this and return the updated stats.
[in] | other | The stats to subtract. |
RunningStats<T> cras::RunningStats< T >::operator- | ( | const T & | sample | ) | const |
Remove a sample from the statistics.
[in] | sample | The sample to remove. |
RunningStats<T>& cras::RunningStats< T >::operator-= | ( | const RunningStats< T > & | other | ) |
Subtract the sequence represented by other from the sequence represented by this and update the stats.
[in] | other | The stats to subtract. |
RunningStats<T>& cras::RunningStats< T >::operator-= | ( | const T & | sample | ) |
Remove a sample from the statistics.
[in] | sample | The sample to remove. |
void cras::RunningStats< T >::removeSample | ( | T | x | ) |
Remove a sample from the statistics.
[in] | x | The sample to remove. |
void cras::RunningStats< T >::reset | ( | ) |
Reset the statistics to represent an empty sequence.
|
protected |
Definition at line 31 of file running_stats_duration.hpp.
|
protected |
Definition at line 54 of file running_stats_duration.hpp.
|
staticprotected |
Return the square root of the given value (whatever meaning that might have).
[in] | val | The value to take root of. |
|
protected |
Definition at line 37 of file running_stats_duration.hpp.
|
protected |
Definition at line 60 of file running_stats_duration.hpp.
|
staticprotected |
Return a T value representing zero.
|
protected |
Number of represented samples.
Definition at line 193 of file running_stats.hpp.
|
protected |
Mean of represented samples.
Definition at line 196 of file running_stats.hpp.
|
protected |
Sk term of the computation such that var(X0...Xk) = this->var/this->count.
Definition at line 199 of file running_stats.hpp.