Changeset 2755


Ignore:
Timestamp:
Jul 4, 2012, 12:13:08 PM (9 years ago)
Author:
Peter
Message:

fixes #709

Location:
branches/0.8-stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/0.8-stable/test/averager.cc

    r2608 r2755  
    5555           unsigned int, Suite& suite);
    5656
     57void test_plus_assign(test::Suite& suite);
    5758
    5859int main(int argc, char* argv[])
     
    268269  delete apw2;
    269270
     271  test_plus_assign(suite);
     272
    270273  return suite.return_value();
    271274}
     
    400403  return ok;
    401404}
     405
     406
     407void test_plus_assign(test::Suite& suite)
     408{
     409  suite.out() << "Testing plus assign\n";
     410  Averager a1;
     411  a1.add(1);
     412  a1.add(3);
     413  Averager a2;
     414  a2.add(-1);
     415  a2.add(-3);
     416  if (!suite.add(suite.equal(a2.mean(), (-1-3)/2)))
     417    suite.err() << "mean failed\n";
     418  if (!suite.add(suite.equal(a2.variance(), 1)))
     419    suite.err() << "variance failed\n";
     420  a2+=a1;
     421  if (!suite.add(suite.equal(a2.mean(), (1+3-1-3)/4)))
     422    suite.err() << "mean failed\n";
     423  if (!suite.add(suite.equal(a2.variance(), (1+9+1+9)/4)))
     424    suite.err() << "variance failed\n";
     425
     426  suite.out() << "Testing plus assign weighted\n";
     427  AveragerWeighted aw1;
     428  aw1.add(1);
     429  aw1.add(3);
     430  AveragerWeighted aw2;
     431  aw2.add(-1);
     432  aw2.add(-3,0.5);
     433  aw2.add(-3,0.5);
     434  aw2.add(42,0.0);
     435  aw1 += aw2;
     436  if (!suite.add(suite.equal(aw1.mean(), (1+3-1-3)/4)))
     437    suite.err() << "mean failed\n";
     438  if (!suite.add(suite.equal(aw1.variance(), (1+9+1+9)/4)))
     439    suite.err() << "variance failed\n";
     440
     441  suite.out() << "Testing plus assign AveragerPair\n";
     442  AveragerPair ap1;
     443  ap1.add(3,3);
     444  ap1.add(5,5);
     445  if (!suite.add(suite.equal(ap1.sum_xy_centered(), 2)))
     446    suite.err() << "sum_xy_centered failed\n";
     447  AveragerPair ap2;
     448  ap2.add(-3,-5);
     449  ap2.add(-5,-3);
     450  ap1 += ap2;
     451  if (!suite.add(suite.equal(ap1.sum_xy_centered(), 9+25+15+15)))
     452    suite.err() << "sum_xy_centered failed\n";
     453
     454  suite.out() << "Testing plus assign AveragerPairWeighted\n";
     455  AveragerPairWeighted apw1;
     456  apw1.add(3, 3, 1, 1);
     457  apw1.add(5, 5, 1, 1);
     458  if (!suite.add(suite.equal(apw1.sum_xy_centered(), 2)))
     459    suite.err() << "sum_xy_centered failed\n";
     460  AveragerPairWeighted apw2;
     461  apw2.add(1, 3, 1, 1);
     462  apw2.add(3, 1, 0.5, 1);
     463  apw2.add(3, 1, 1, 0.5);
     464  apw2.add(42, 99, 0, 0.5);
     465  apw1 += apw2;
     466  if (!suite.add(suite.equal(apw1.x_averager().mean(), 3)))
     467    suite.err() << "x_averager().mean() failed\n";
     468  if (!suite.add(suite.equal(apw1.y_averager().mean(), 3)))
     469    suite.err() << "y_averager().mean() failed\n";
     470  if (!suite.add(suite.equal(apw1.sum_xy(), 9+25+3+3)))
     471    suite.err() << "sum_xy failed\n";
     472  if (!suite.add(suite.equal(apw1.sum_xy_centered(), 0+4+0+0)))
     473    suite.err() << "sum_xy_centered failed\n";
     474}
  • branches/0.8-stable/yat/statistics/Averager.cc

    r2563 r2755  
    153153    if (!a.n())
    154154      return *this;
    155     mean_ += (sum_x() + a.sum_x()) / (n() + a.n());
    156     double delta = mean_ - a.mean();
     155    const double delta = mean_ - a.mean();
     156    mean_ = (sum_x() + a.sum_x()) / (n() + a.n());
    157157    m2_ += a.m2_ + n()*a.n()*delta*delta/(n()+a.n());
    158158    n_+=a.n_;
  • branches/0.8-stable/yat/statistics/AveragerWeighted.cc

    r2619 r2755  
    163163    if (!a.w_)
    164164      return *this;
    165     mean_ += (sum_wx() + a.sum_wx()) / (sum_w() + a.sum_w());
    166165    double delta = mean() - a.mean();
     166    mean_ = (sum_wx() + a.sum_wx()) / (sum_w() + a.sum_w());
    167167    m2_ += a.m2_ + sum_w()*a.sum_w()*delta*delta/(sum_w()+a.sum_w());
    168168    w_ += a.w_;
Note: See TracChangeset for help on using the changeset viewer.