OpenMPCD
|
Computes sample means and variances "on-the-fly" or "online", i.e. More...
#include <OnTheFlyStatistics.hpp>
Public Member Functions | |
OnTheFlyStatistics () | |
The constructor. More... | |
std::size_t | getSampleSize () const |
Returns the number of data points added so far. More... | |
const T | getSampleMean () const |
Returns the mean of all the values added so far. More... | |
const T | getSampleStandardDeviation () const |
Returns the unbiased sample variance of all the values added so far. More... | |
const T | getStandardErrorOfTheMean () const |
Returns the standard error of the mean, i.e. More... | |
void | addDatum (const T &datum) |
Adds a datum to the sample. More... | |
const std::string | serializeToString () const |
Returns a string that contains the state of this instance. More... | |
void | unserializeFromString (const std::string &state) |
Discards the current state, and loads the state specified in the given string instead. More... | |
Computes sample means and variances "on-the-fly" or "online", i.e.
without storing the individual data points.
For a description of the algorithm used, see "Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments" by Philippe Pébay, Sandia Report SAND2008-6212, 2008.
T | The data type. It must support addition and multiplication of two objects of this type, and division by an unsigned long int . |
Definition at line 34 of file OnTheFlyStatistics.hpp.
|
inline |
The constructor.
Definition at line 40 of file OnTheFlyStatistics.hpp.
|
inline |
Adds a datum to the sample.
[in] | datum | The datum to add. |
Definition at line 116 of file OnTheFlyStatistics.hpp.
|
inline |
Returns the mean of all the values added so far.
If no values have been added yet, returns 0
.
Definition at line 59 of file OnTheFlyStatistics.hpp.
|
inline |
Returns the number of data points added so far.
Definition at line 49 of file OnTheFlyStatistics.hpp.
|
inline |
Returns the unbiased sample variance of all the values added so far.
The returned value contains Bessel's correction, i.e. the sum of squares of differences is divided by \( n - 1 \) rather than \( n \), where $ n \( is the sample size. If fewer than two values have been added so far, returns `0`. */ const T getSampleVariance() const { if(getSampleSize() < 2) return 0; return varianceHelper / (getSampleSize() - 1); } /** Returns the unbiased sample standard deviation of all the values added so far. The returned value contains Bessel's correction, i.e. the sum of squares of differences is divided by \) n - 1 \( rather than \) n \(, where \$ n \) is the sample size.
If fewer than two values have been added so far, returns 0
.
Definition at line 91 of file OnTheFlyStatistics.hpp.
|
inline |
Returns the standard error of the mean, i.e.
the unbiased sample standard deviation divided by the square root of the sample size.
OpenMPCD::InvalidCallException | If OPENMPCD_DEBUG is defined, throws if getSampleSize()==0 . |
Definition at line 103 of file OnTheFlyStatistics.hpp.
const std::string OpenMPCD::OnTheFlyStatistics< T >::serializeToString |
Returns a string that contains the state of this instance.
Since the serialized state is stored a string, it is representing the state only approximately.
Currently, this is implemented only for the cases where boost::is_arithmetic<T>::value
is true
.
Definition at line 23 of file ImplementationDetails/OnTheFlyStatistics.hpp.
void OpenMPCD::OnTheFlyStatistics< T >::unserializeFromString | ( | const std::string & | state | ) |
Discards the current state, and loads the state specified in the given string instead.
Currently, this is implemented only for the cases where boost::is_arithmetic<T>::value
is true
.
The user is responsible for attempting to load only such serialized states that have been generated with a compatible with T
.
InvalidArgumentException | Throws if state does not encode a valid state. |
[in] | state | The state to load. Must be a string created by serializeToString . |
Definition at line 40 of file ImplementationDetails/OnTheFlyStatistics.hpp.