Changeset 1290


Ignore:
Timestamp:
May 9, 2008, 1:44:25 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Addresses #361. Averager accepts negative n for removal of data from the Averager.

Location:
branches/0.4-stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/0.4-stable/test/averager_test.cc

    r1275 r1290  
    6969    suite.add(false);
    7070    suite.err() << "error: add\n";
     71  }
     72  Averager b(a);
     73  b.add(5,-1);
     74  if (b.n()!=2 || b.mean()!=2 || b.sum_xx()!=10){
     75    suite.add(false);
     76    suite.err() << "error: add with negative n\n";
     77  }
     78  b.add(5,-4);
     79  if (b.n()!=-2 || b.mean()!=8 || b.sum_xx()!=-90){
     80    suite.add(false);
     81    suite.err() << "error: add with negatibe n\n";
    7182  }
    7283
  • branches/0.4-stable/yat/statistics/Averager.cc

    r1275 r1290  
    44  Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
    55  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
    6   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    7   Copyright (C) 2008 Peter Johansson
     6  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    87
    98  This file is part of the yat library, http://trac.thep.lu.se/yat
     
    3938  }
    4039
    41   Averager::Averager(double x, double xx, unsigned long n)
     40  Averager::Averager(double x, double xx, long n)
    4241    : n_(n), x_(x), xx_(xx)
    4342  {
     
    4948  }
    5049
    51   void Averager::add(double d, unsigned long n)
     50  void Averager::add(double d, long n)
    5251  {
    5352    assert(!std::isnan(d));
    5453    n_  += n;
     54    assert(n>-1);
    5555    x_  += n*d;
    5656    xx_ += n*d*d;
     
    6767  }
    6868
    69   unsigned long Averager::n(void) const
     69  long Averager::n(void) const
    7070  {
    7171    return n_;
  • branches/0.4-stable/yat/statistics/Averager.h

    r1275 r1290  
    77  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
    88  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    9   Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    10   Copyright (C) 2008 Peter Johansson
     9  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    1110
    1211  This file is part of the yat library, http://trac.thep.lu.se/yat
     
    5655    /// number of samples \a n.
    5756    ///
    58     Averager(double x, double xx, unsigned long n);
     57    Averager(double x, double xx, long n);
    5958
    6059    ///
     
    6665    /// Adding \a n (default=1) number of data point(s) with value \a d.
    6766    ///
    68     void add(double d, unsigned long n=1);
     67    void add(double d, long n=1);
    6968
    7069    /**
     
    8685    /// @return Number of data points
    8786    ///
    88     unsigned long n(void) const;
     87    long n(void) const;
    8988
    9089    ///
     
    179178
    180179  private:
    181     unsigned long n_;
     180    long  n_;
    182181    double  x_, xx_;
    183182  };
Note: See TracChangeset for help on using the changeset viewer.