18#ifndef _SIMPLESTATS_H_
19#define _SIMPLESTATS_H_
31 RunningStat() : m_n(0), m_oldM(0), m_newM(0), m_oldS(0), m_newS(0) {}
52 m_newM = m_oldM + (x - m_oldM)/m_n;
53 m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
61 int NumDataValues()
const
68 return (m_n > 0) ? m_newM : 0.0;
71 double Variance()
const
73 return ((m_n > 1) ? m_newS/(m_n - 1) : 0.0);
76 double StandardDeviation()
const
78 return sqrt(Variance());
83 double m_oldM, m_newM, m_oldS, m_newS;
91 return r.NumDataValues() == i;
96 stream <<
"N: " << s.NumDataValues()
97 <<
" Mean: " << s.Mean()
98 <<
" Standard Deviation: " << s.StandardDeviation();