Changeset 2803


Ignore:
Timestamp:
Jul 30, 2012, 7:18:25 AM (10 years ago)
Author:
Peter
Message:

fixed spurious test failures as well as a bug in operator+=. refs #705

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/averager4.cc

    r2799 r2803  
    5656  utility::Vector vec(10);
    5757  for (size_t i=0; i<vec.size(); ++i) {
    58     vec(i) = i;
     58    vec(i) = i*i;
    5959    a.add(vec(i), 1);
    6060  }
     
    6565    sum += std::pow(vec(i)-m, 3);
    6666  sum = sum/vec.size();
    67   if (!suite.equal(a.central_moment3(), sum)) {
     67  if (!suite.equal(a.central_moment3(), sum, 2)) {
    6868    suite.add(false);
    6969    suite.err() << "central moment3 failed: expected " << sum << "\n";
    7070  }
    71   return suite.return_value();
     71  //  return suite.return_value();
    7272
    7373  sum = 0;
     
    8080
    8181  suite.out() << "comparing against GSL implementations\n";
    82   double correct_factor = std::sqrt(static_cast<double>(vec.size())/
    83                                     (vec.size()-1.0));
     82  double correct_factor = std::sqrt((vec.size()-1.0)/vec.size());
    8483  if (!suite.add(suite.equal(a.skewness(),
    85                              std::pow(correct_factor,3)*skewness(vec),
     84                             skewness(vec)/std::pow(correct_factor,3),
    8685                             10))) {
    8786    suite.err() << "skewness failed\n";
     87    suite.err() << "Averager4: " << a.skewness() << "\n";
     88    suite.err() << "GSL:       " << skewness(vec) << "\n";
     89    suite.err() << "factor: " << std::pow(correct_factor,3) << "\n";
    8890  }
    8991
    9092  if (!suite.add(suite.equal(a.kurtosis(),
    91                              std::pow(correct_factor,4)*kurtosis(vec),
     93                             (kurtosis(vec)+3)/std::pow(correct_factor,4)-3,
    9294                             10))) {
    9395    suite.err() << "kurtosis failed\n";
     96    suite.err() << "Averager4: " << a.kurtosis() << "\n";
     97    suite.err() << "GSL:       " << kurtosis(vec) << "\n";
     98    suite.err() << "factor: " << std::pow(correct_factor,4) << "\n";
     99
     100    double var = a.averager().variance_unbiased();
     101    suite.err() << a.central_moment4()/(var*var) - 3 << "\n";
    94102  }
    95103
     
    103111  a2.add(6,1);
    104112
    105   // cm3 = (4*1 + 4^3)/5 = 68/5 = 13.6
    106   if (!suite.add(suite.equal(a2.central_moment3(), 13.6)))
     113  // cm3 = (-4*1 + 4^3)/5 = 60/5 = 12
     114  if (!suite.add(suite.equal(a2.central_moment3(), 12)))
    107115    suite.err() << "central moment3 failed\n";
    108116
     
    114122    suite.err() << "variance failed\n";
    115123  if (!suite.add(suite.equal(a1.central_moment3(),
    116                              (4*std::pow(2.5,3)+4+std::pow(6.0,3))/10)))
     124                             (4*std::pow(-2.5,3)+4+std::pow(6.0,3))/10)))
    117125    suite.err() << "central_moment3 failed\n";
    118126  if (!suite.add(suite.equal(a1.central_moment4(),
  • trunk/yat/statistics/Averager4.cc

    r2799 r2803  
    108108  Averager4& Averager4::operator+=(const Averager4& rhs)
    109109  {
    110     add(rhs.averager().mean(), rhs.averager().variance(),
     110    add(rhs.averager().mean(), rhs.averager().sum_xx_centered(),
    111111        rhs.cm3_, rhs.cm4_, rhs.averager().n());
    112112    averager_ += rhs.averager_;
Note: See TracChangeset for help on using the changeset viewer.