Changeset 1290

Ignore:
Timestamp:
May 9, 2008, 1:44:25 PM (15 years ago)
Message:

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

Location:
branches/0.4-stable
Files:
3 edited

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

 r1275 suite.add(false); suite.err() << "error: add\n"; } Averager b(a); b.add(5,-1); if (b.n()!=2 || b.mean()!=2 || b.sum_xx()!=10){ suite.add(false); suite.err() << "error: add with negative n\n"; } b.add(5,-4); if (b.n()!=-2 || b.mean()!=8 || b.sum_xx()!=-90){ suite.add(false); suite.err() << "error: add with negatibe n\n"; }
• branches/0.4-stable/yat/statistics/Averager.cc

 r1275 Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson Copyright (C) 2006 Jari Häkkinen, Markus Ringnér Copyright (C) 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson This file is part of the yat library, http://trac.thep.lu.se/yat } Averager::Averager(double x, double xx, unsigned long n) Averager::Averager(double x, double xx, long n) : n_(n), x_(x), xx_(xx) { } void Averager::add(double d, unsigned long n) void Averager::add(double d, long n) { assert(!std::isnan(d)); n_  += n; assert(n>-1); x_  += n*d; xx_ += n*d*d; } unsigned long Averager::n(void) const long Averager::n(void) const { return n_;
• branches/0.4-stable/yat/statistics/Averager.h

 r1275 Copyright (C) 2004 Jari Häkkinen, Peter Johansson Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér Copyright (C) 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson This file is part of the yat library, http://trac.thep.lu.se/yat /// number of samples \a n. /// Averager(double x, double xx, unsigned long n); Averager(double x, double xx, long n); /// /// Adding \a n (default=1) number of data point(s) with value \a d. /// void add(double d, unsigned long n=1); void add(double d, long n=1); /** /// @return Number of data points /// unsigned long n(void) const; long n(void) const; /// private: unsigned long n_; long  n_; double  x_, xx_; };
Note: See TracChangeset for help on using the changeset viewer.