Ignore:
Timestamp:
Sep 4, 2006, 5:16:57 PM (16 years ago)
Author:
Markus Ringnér
Message:

Fixed problems with Averager that sometimes appeared as failures in averager_test when optimization is turned on

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/statistics/Averager.h

    r616 r620  
    2424    /// Default constructor
    2525    ///
    26     inline Averager(void) : n_(0), x_(0), xx_(0) {}
     26    Averager(void);
    2727   
    2828    ///
     
    3030    /// number of samples \a n.
    3131    ///
    32     inline Averager(const double x,const double xx,const long n)
    33       : n_(n), x_(x), xx_(xx) {}
     32    Averager(double x, double xx, u_long n);
    3433
    3534    ///
    3635    /// Copy constructor
    3736    ///
    38     inline Averager(const Averager& a) : n_(a.n_), x_(a.x_), xx_(a.xx_) {}
     37    Averager(const Averager& a);
    3938
    4039    ///
    4140    /// Adding \a n (default=1) number of data point(s) with value \a d.
    4241    ///
    43     inline void add(const double d,const long n=1) { n_+=n; x_+=n*d; xx_+=n*d*d;}
     42    inline void add(double d, u_long n=1) { n_+=n; x_+=n*d; xx_+=n*d*d;}
    4443
    4544    ///
     
    5150    ///
    5251    template <typename T>
    53     void  add_values(const T& v, const long n=1);
     52    void  add_values(const T& v, u_long n=1);
    5453
    5554    ///
     
    6160    /// @return Number of data points
    6261    ///
    63     inline unsigned long  n(void) const { return n_; }
     62    inline u_long n(void) const { return n_; }
    6463
    6564    ///
     
    8988    /// @return Standard deviation around \a m, root of the variance(m).
    9089    ///
    91     inline double std(const double m) const { return sqrt(variance(m)); }
     90    inline double std(double m) const { return sqrt(variance(m)); }
    9291
    9392    ///
     
    111110    /// @return Variance when the mean is known to be \a m.
    112111    ///
    113     inline double variance(const double m) const
     112    inline double variance(double m) const
    114113    { return n_ ? (xx_ - 2*m*x_ + m*m*n()) /n_ : 0; }
    115114
     
    151150
    152151  private:
    153     unsigned long n_;
     152    u_long  n_;
    154153    double  x_, xx_;
    155154  };
     
    157156  // Template implementations
    158157  template <typename T>
    159   void  Averager::add_values(const T& v, const long n)
     158  void  Averager::add_values(const T& v, u_long n)
    160159  {
    161160    for (size_t i=0; i<v.size(); i++)
Note: See TracChangeset for help on using the changeset viewer.