libStatGen Software 1
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.

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

34 {
35 m_n = 0;
36 }

◆ Mean()

double RunningStat::Mean ( ) const
inline

Definition at line 66 of file SimpleStats.h.

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

◆ NumDataValues()

int RunningStat::NumDataValues ( ) const
inline

Definition at line 61 of file SimpleStats.h.

62 {
63 return m_n;
64 }

◆ Push()

void RunningStat::Push ( double  x)
inline

Definition at line 38 of file SimpleStats.h.

39 {
40 m_n++;
41
42 // See Knuth TAOCP vol 2, 3rd edition, page 232
43 if (m_n == 1)
44 {
45 m_oldM = x;
46 m_oldS = 0.0;
47 m_newM = x;
48 m_newS = 0.0;
49 }
50 else
51 {
52 m_newM = m_oldM + (x - m_oldM)/m_n;
53 m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
54
55 // set up for next iteration
56 m_oldM = m_newM;
57 m_oldS = m_newS;
58 }
59 }

◆ StandardDeviation()

double RunningStat::StandardDeviation ( ) const
inline

Definition at line 76 of file SimpleStats.h.

77 {
78 return sqrt(Variance());
79 }

◆ Variance()

double RunningStat::Variance ( ) const
inline

Definition at line 71 of file SimpleStats.h.

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

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