variance.h
Go to the documentation of this file.
00001 /* variance.h
00002  */
00003 #ifndef _VARIANCE_H
00004 #define _VARIANCE_H
00005 
00006 #include "osl/stat/average.h"
00007 namespace osl
00008 {
00009   namespace stat
00010   {
00014     class Variance : private Average
00015     {
00016       double m_variance;
00017       typedef Average base_t;
00018     public:
00019       // CREATORS
00020       Variance() : m_variance(0)
00021       {
00022       }
00023       // MANIPULATORS
00024       void add(const double& x)
00025       {
00026         const double diff = base_t::add(x);
00027         const double adjuster 
00028           = static_cast<double>(numElements()-1)/numElements();
00029         m_variance += diff*diff*adjuster;
00030       }
00031 
00032       // ACCESSORS
00033       double variance() const { return m_variance/numElements(); }
00034       using base_t::getAverage;
00035       using base_t::numElements;
00036     };
00037   } // namespace stat
00038 } // namespace osl
00039 
00040 
00041 #endif /* _VARIANCE_H */
00042 // ;;; Local Variables:
00043 // ;;; mode:c++
00044 // ;;; c-basic-offset:2
00045 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines