OpenMPCD
Public Member Functions | List of all members
OpenMPCD::OnTheFlyStatistics< T > Class Template Reference

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...
 

Detailed Description

template<typename T>
class OpenMPCD::OnTheFlyStatistics< T >

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.

Template Parameters
TThe 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.

Constructor & Destructor Documentation

◆ OnTheFlyStatistics()

template<typename T >
OpenMPCD::OnTheFlyStatistics< T >::OnTheFlyStatistics ( )
inline

The constructor.

Definition at line 40 of file OnTheFlyStatistics.hpp.

Member Function Documentation

◆ addDatum()

template<typename T >
void OpenMPCD::OnTheFlyStatistics< T >::addDatum ( const T &  datum)
inline

Adds a datum to the sample.

Parameters
[in]datumThe datum to add.

Definition at line 116 of file OnTheFlyStatistics.hpp.

◆ getSampleMean()

template<typename T >
const T OpenMPCD::OnTheFlyStatistics< T >::getSampleMean ( ) const
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.

◆ getSampleSize()

template<typename T >
std::size_t OpenMPCD::OnTheFlyStatistics< T >::getSampleSize ( ) const
inline

Returns the number of data points added so far.

Definition at line 49 of file OnTheFlyStatistics.hpp.

◆ getSampleStandardDeviation()

template<typename T >
const T OpenMPCD::OnTheFlyStatistics< T >::getSampleStandardDeviation ( ) const
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.

◆ getStandardErrorOfTheMean()

template<typename T >
const T OpenMPCD::OnTheFlyStatistics< T >::getStandardErrorOfTheMean ( ) const
inline

Returns the standard error of the mean, i.e.

the unbiased sample standard deviation divided by the square root of the sample size.

Exceptions
OpenMPCD::InvalidCallExceptionIf OPENMPCD_DEBUG is defined, throws if getSampleSize()==0.

Definition at line 103 of file OnTheFlyStatistics.hpp.

◆ serializeToString()

template<typename T >
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.

See also
unserializeFromString

Definition at line 23 of file ImplementationDetails/OnTheFlyStatistics.hpp.

◆ unserializeFromString()

template<typename T >
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.

Exceptions
InvalidArgumentExceptionThrows if state does not encode a valid state.
Parameters
[in]stateThe state to load. Must be a string created by serializeToString.

Definition at line 40 of file ImplementationDetails/OnTheFlyStatistics.hpp.


The documentation for this class was generated from the following file: