Changeset 1295


Ignore:
Timestamp:
May 12, 2008, 10:35:10 AM (13 years ago)
Author:
Jari Häkkinen
Message:

Fixes #361. Averager and AveragerPair? accepts negative n for data removal.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/averager_test.cc

    r1275 r1295  
    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
     
    198209  delete ap2;
    199210
     211  for (int i=0; i<8; i++)
     212    ap.add(static_cast<double>(i),i,-1);
     213  if (std::abs(ap.correlation()-1)>tol) {
     214    suite.add(false);
     215    suite.err() << "correlation after removal of data: " << ap.correlation()
     216                << std::endl;
     217    suite.err() << "error: correlation between identical vectors is unity"
     218                << std::endl;
     219  }
     220  ap.add(static_cast<double>(1),1,-4);
     221  if (std::abs(ap.correlation()+1)>tol || ap.n()!=-2) {
     222    suite.add(false);
     223    suite.err() << "AveragerPair error: add with negatibe n\n";
     224  }
     225
     226
    200227  suite.out() << "testing AveragerPairWeighted" << std::endl;
    201228  AveragerPairWeighted apw;
  • trunk/yat/statistics/Averager.cc

    r1275 r1295  
    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_;
  • trunk/yat/statistics/Averager.h

    r1275 r1295  
    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  };
  • trunk/yat/statistics/AveragerPair.cc

    r1275 r1295  
    44  Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
    55  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, 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
     
    4544  }
    4645
    47   void AveragerPair::add(const double x, const double y, const unsigned long n)
     46  void AveragerPair::add(const double x, const double y, const long n)
    4847  {
    4948    x_.add(x,n); y_.add(y,n); xy_ += n*x*y;
     
    7675  }
    7776
    78   unsigned long AveragerPair::n(void) const
     77  long AveragerPair::n(void) const
    7978  {
    8079    return x_.n();
  • trunk/yat/statistics/AveragerPair.h

    r1275 r1295  
    77  Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
    88  Copyright (C) 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
     
    6968    /// Adding \a n pairs of data points with value \a x and \a y.
    7069    ///
    71     void add(const double x, const double y, const unsigned long n=1);
     70    void add(const double x, const double y, const long n=1);
    7271
    7372    /**
     
    111110    /// @return The number of pair of data points.
    112111    ///
    113     unsigned long n(void) const;
     112    long n(void) const;
    114113
    115114    ///
Note: See TracChangeset for help on using the changeset viewer.