All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
variance.h
Go to the documentation of this file.
1 /* variance.h
2  */
3 #ifndef _VARIANCE_H
4 #define _VARIANCE_H
5 
6 #include "osl/stat/average.h"
7 namespace osl
8 {
9  namespace stat
10  {
14  class Variance : private Average
15  {
16  double m_variance;
17  typedef Average base_t;
18  public:
19  // CREATORS
21  {
22  }
23  // MANIPULATORS
24  void add(const double& x)
25  {
26  const double diff = base_t::add(x);
27  const double adjuster
28  = static_cast<double>(numElements()-1)/numElements();
29  m_variance += diff*diff*adjuster;
30  }
31 
32  // ACCESSORS
33  double variance() const { return m_variance/numElements(); }
34  using base_t::getAverage;
35  using base_t::average;
36  using base_t::numElements;
37  };
38  } // namespace stat
39 } // namespace osl
40 
41 
42 #endif /* _VARIANCE_H */
43 // ;;; Local Variables:
44 // ;;; mode:c++
45 // ;;; c-basic-offset:2
46 // ;;; End: