Loading...
Searching...
No Matches
RunningStat Class Reference

## Public Member Functions

void | Clear ()
void | Push (double x)
int | NumDataValues () const
double | Mean () const
double | Variance () const
double | StandardDeviation () const

## Detailed Description

Definition at line 28 of file SimpleStats.h.

## Constructor & Destructor Documentation

## RunningStat()

RunningStat::RunningStat | ( |  | ) |

inline

Definition at line 31 of file SimpleStats.h.

: m_n(0), m_oldM(0), m_newM(0), m_oldS(0), m_newS(0) {}

## Member Function Documentation

## Clear()

void RunningStat::Clear | ( |  | ) |

inline

Definition at line 33 of file SimpleStats.h.

{
m_n = 0;
}

## Mean()

double RunningStat::Mean | ( |  | ) | const

inline

Definition at line 66 of file SimpleStats.h.

{
return (m_n > 0) ? m_newM : 0.0;
}

## NumDataValues()

int RunningStat::NumDataValues | ( |  | ) | const

inline

Definition at line 61 of file SimpleStats.h.

{
return m_n;
}

## Push()

void RunningStat::Push | ( | double | x | ) |

inline

Definition at line 38 of file SimpleStats.h.

{
m_n++;
// See Knuth TAOCP vol 2, 3rd edition, page 232
if (m_n == 1)
{
m_oldM = x;
m_oldS = 0.0;
m_newM = x;
m_newS = 0.0;
}
else
{
m_newM = m_oldM + (x - m_oldM)/m_n;
m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
// set up for next iteration
m_oldM = m_newM;
m_oldS = m_newS;
}
}

## StandardDeviation()

double RunningStat::StandardDeviation | ( |  | ) | const

inline

Definition at line 76 of file SimpleStats.h.

{
return sqrt(Variance());
}

## Variance()

double RunningStat::Variance | ( |  | ) | const

inline

Definition at line 71 of file SimpleStats.h.

{
return ((m_n > 1) ? m_newS/(m_n - 1) : 0.0);
}

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

- general/SimpleStats.h