RunningStat.h 825 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @file RunningStat.h
  3. * @brief B. P. Welford Computation of Mean and Variance download at: http://www.johndcook.com/standard_deviation.html
  4. * @author Michael Koch
  5. * @date 18/02/2009
  6. */
  7. #ifndef RunningStatINCLUDE
  8. #define RunningStatINCLUDE
  9. namespace OBJREC {
  10. /** @brief online statistics */
  11. class RunningStat
  12. {
  13. public:
  14. RunningStat() : m_n ( 0 ) {}
  15. /** clear the current statistics */
  16. void Clear();
  17. /** add a new data element */
  18. void Push ( double x );
  19. /** get number of data elements */
  20. size_t NumDataValues() const;
  21. /** get mean value */
  22. double Mean() const;
  23. /** get variance */
  24. double Variance() const;
  25. /** get standard deviation */
  26. double StandardDeviation() const;
  27. private:
  28. size_t m_n;
  29. double m_oldM, m_newM, m_oldS, m_newS;
  30. };
  31. }
  32. #endif