Changeset 197 for trunk/src/Averager.cc


Ignore:
Timestamp:
Oct 27, 2004, 9:04:22 PM (17 years ago)
Author:
Jari Häkkinen
Message:

Cleanup interfaces for Averager classes and move stuff into statsitics
namespace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Averager.cc

    r137 r197  
    99
    1010namespace theplu {
    11 namespace cpptools{
     11namespace statistics{
    1212 
    1313
     
    1717  }
    1818
    19   Averager::Averager(const double x)
    20     : n_(1), x_(x), xx_(x*x)
    21   {
    22   }
    23 
    2419  Averager::Averager(const double x,const double xx,const long n)
    2520    : n_(n), x_(x), xx_(xx)
    26   {
    27   }
    28 
    29   Averager::Averager(const gslapi::vector& vec)
    30     :n_(vec.size()), x_(vec.sum()), xx_(vec*vec)
    3121  {
    3222  }
     
    4535  }
    4636
    47   const Averager& Averager::operator*=(const Averager& N)
    48   {
    49     long    Rn=10;
    50     double  NM=N.mean();
    51     double  M=mean();
    52     double  x=M*NM;
    53     double  var=(variance()*NM*NM+N.variance()*M*M);
    54 
    55     *this=Averager(Rn*x ,var*Rn*(Rn-1)+x*x*Rn, Rn);
    56     return *this;
    57   }
    58 
    59   const Averager& Averager::operator/=(const Averager& N)
    60   {
    61     long    Rn=10;
    62     double  NM=N.mean();
    63    
    64     if(NM) {
    65       double x=mean()/NM;
    66       double var=(variance()+N.variance()*x*x)/(NM*NM);
    67       *this=Averager(Rn*x ,var*Rn*(Rn-1)+x*x*Rn, Rn);
    68     }
    69     else
    70       reset();
    71    
    72     return *this;
    73   }
    74  
    75   Averager operator*(double d,const Averager& a) {
    76     Averager tmp=a;
    77     return tmp*=d;
    78   }
    79 
    80   std::ostream& theplu::cpptools::operator<<(std::ostream& o, const Averager& a)
    81   {
    82     return o << a.mean() << ' ' << a.standard_error();
    83   }
    84 
    85 }} // of namespace cpptools and namespace theplu
     37}} // of namespace statistics and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.