Changeset 2561


Ignore:
Timestamp:
Sep 25, 2011, 8:15:20 PM (10 years ago)
Author:
Peter
Message:

refs #671. Correct so mean is NaN when there is no data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/statistics/Averager.cc

    r2560 r2561  
    6969  double Averager::mean(void) const
    7070  {
    71     return mean_;
     71    if (n_)
     72      return mean_;
     73    return std::numeric_limits<double>::quiet_NaN();
    7274  }
    7375
     
    106108  double Averager::sum_x(void)  const
    107109  {
     110    if (!n_)
     111      return 0.0;
    108112    return n_*mean_;
    109113  }
     
    147151  const Averager& Averager::operator+=(const Averager& a)
    148152  {
    149     mean_ += (n()*mean() + a.n()*a.mean()) / (n() + a.n());
    150     double delta = mean_ = a.mean();
     153    mean_ += (sum_x() + a.sum_x()) / (n() + a.n());
     154    double delta = mean_ - a.mean();
    151155    m2_ += a.m2_ + n()*a.n()*delta*delta/(n()+a.n());
    152156    n_+=a.n_;
Note: See TracChangeset for help on using the changeset viewer.