Changeset 1244


Ignore:
Timestamp:
Mar 17, 2008, 1:40:12 PM (13 years ago)
Author:
Peter
Message:

working in #223

Location:
trunk/test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Suite.cc

    r1239 r1244  
    7575
    7676
    77   bool Suite::equal(double a, double b, u_int n)
     77  bool Suite::equal(double a, double b, unsigned long int n)
    7878  {
    7979    double last_error_bound = n*std::numeric_limits<double>().epsilon()*
  • trunk/test/Suite.h

    r1239 r1244  
    5757       where \f$ \epsilon \f$ is std::numeric_limits<double>().epsilon()
    5858    */
    59     bool equal(double a, double b, unsigned int N=1);
     59    bool equal(double a, double b, unsigned long int N=1);
    6060
    6161    template<typename Iterator1, typename Iterator2>
  • trunk/test/regression_test.cc

    r1234 r1244  
    33/*
    44  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2008 Peter Johansson
    56
    67  This file is part of the yat library, http://trac.thep.lu.se/yat
     
    8182  regression::Polynomial polynomial(1);
    8283  polynomial.fit(x,y);
    83   if ( suite.equal(linear.beta(),polynomial.fit_parameters()(1)) ){
     84  if ( !suite.equal(linear.beta(),polynomial.fit_parameters()(1), 1000) ){
    8485    suite.err() << "error: beta and fit_parameters(1) not equal" << std::endl;
    8586    suite.err() << "       beta = " << linear.beta() << std::endl;
     
    8889    suite.add(false);
    8990  }
    90   if (suite.equal(polynomial.fit_parameters()(0),
    91                   linear.alpha()-linear.beta()*1985)){
     91  if (!suite.equal(polynomial.fit_parameters()(0),
     92                   linear.alpha()-linear.beta()*1985, 1000)){
    9293    suite.err() << "error: fit_parameters(0) = "
    9394           << polynomial.fit_parameters()(0)<< std::endl;
     
    9697    suite.add(false);
    9798  }
    98   if ( std::abs(polynomial.chisq()-linear.chisq())>0.0001){
     99  if ( !suite.equal(polynomial.chisq(), linear.chisq(), 100) ){
    99100    suite.err() << "error: chisq not same in linear and polynomial(1)"
    100101           << std::endl;
    101102    suite.add(false);
    102103  }
    103   if ( std::abs(polynomial.predict(1.0)-linear.predict(1.0))>0.0001){
     104  if ( !suite.equal(polynomial.predict(1.0),linear.predict(1.0), 1000) ){
    104105    suite.err() << "error: predict not same in linear and polynomial(1)"
    105106           << std::endl;
    106107    suite.add(false);
    107108  }
    108   if ( std::abs(polynomial.standard_error2(1985)-linear.standard_error2(1985))
    109        >0.0001){
     109  if (!suite.equal(polynomial.standard_error2(1985),
     110                   linear.standard_error2(1985), 1e5)){
    110111    suite.err() << "error: standard_error not same in linear and polynomial(1)"
    111            << "\n  polynomial: " << polynomial.standard_error2(1985)
    112            << "\n  linear: " << linear.standard_error2(1985)
    113            << std::endl;
     112                << "\n  polynomial: " << polynomial.standard_error2(1985)
     113                << "\n  linear: " << linear.standard_error2(1985)
     114                << std::endl;
    114115    suite.add(false);
    115116  }
     
    121122  double y_predicted = linear_w.predict(1990);
    122123  double y_predicted_err = linear_w.prediction_error2(1990);
    123   if (std::abs(y_predicted-12.8)>0.001){
     124  if (!suite.equal(y_predicted,12.8) ){
    124125    suite.err() << "error: cannot reproduce fit." << std::endl;
    125126    suite.err() << "predicted value: " << y_predicted << " expected 12.8"
     
    134135  regression::PolynomialWeighted polynomial_w(1);
    135136  polynomial_w.fit(x,y,w);
    136   if ( std::abs(linear_w.beta()-polynomial_w.fit_parameters()(1))>10e-7 ){
     137  if ( !suite.equal(linear_w.beta(), polynomial_w.fit_parameters()(1),100) ){
    137138    suite.err() << "error: beta and fit_parameters(1) not equal" << std::endl;
    138139    suite.err() << "       beta = " << linear_w.beta() << std::endl;
     
    141142    suite.add(false);
    142143  }
    143   if ( std::abs(polynomial_w.fit_parameters()(0)-linear_w.alpha()+
    144             linear_w.beta()*1990)>0.0001){
     144  if ( !suite.equal(polynomial_w.fit_parameters()(0),
     145                    linear_w.alpha()-linear_w.beta()*1990, 100) ){
    145146    suite.err() << "error: fit_parameters(0) = "
    146147           << polynomial.fit_parameters()(0)<< std::endl;
     
    149150    suite.add(false);
    150151  }
    151   if ( std::abs(polynomial_w.s2()-linear_w.s2())>0.0001){
     152  if ( !suite.equal(polynomial_w.s2(),linear_w.s2(), 10) ){
    152153    suite.err() << "error: chisq not same in linear and polynomial(1)"
    153154           << std::endl;
    154155    suite.add(false);
    155156  }
    156   if ( std::abs(polynomial_w.predict(1.0)-linear_w.predict(1.0))>0.0001){
     157  if ( !suite.equal(polynomial_w.predict(1.0), linear_w.predict(1.0), 100) ){
    157158    suite.err() << "error: predict not same in linear and polynomial(1)"
    158159           << std::endl;
    159160    suite.add(false);
    160161  }
    161   if ( std::abs(polynomial_w.standard_error2(1985)-linear_w.standard_error2(1985))
    162        >0.0001){
     162  if ( !suite.equal(polynomial_w.standard_error2(1985),
     163                    linear_w.standard_error2(1985), 1e5) ){
    163164    suite.err() << "error: standard_error not same in linear and polynomial(1)"
    164            << "\n  polynomial: " << polynomial.standard_error2(1985)
    165            << "\n  linear: " << linear.standard_error2(1985)
     165           << "\n  polynomial: " << polynomial_w.standard_error2(1985)
     166           << "\n  linear: " << linear_w.standard_error2(1985)
    166167           << std::endl;
    167168    suite.add(false);
     
    214215    utility::Vector fit=polynomialfit.fit_parameters();
    215216    if (std::abs(fit(0)-1.012229646706 + fit(1)-0.012561322528 +
    216             fit(2)+1.159674470130)>1e-11) {
     217                fit(2)+1.159674470130)>1e-11) {
    217218      suite.err() << "regression_Polynomial: cannot reproduce fit." << std::endl;
    218219      suite.add(false);
     
    253254  r.fit(x,y);
    254255  rw.fit(x,y,w);
    255   if (std::abs(r.predict(2000) - rw.predict(2000))>1e-15) {
     256  if (!suite.equal(r.predict(2000), rw.predict(2000)) ) {
    256257    suite.add(false);
    257258    suite.err() << "Error: predict not equal\n"
     
    260261           << std::endl;
    261262  }
    262   if (std::abs(r.s2()-rw.s2(1.0))>10E-7){
     263  if (!suite.equal(r.s2(), rw.s2(1.0)) ){
    263264    suite.add(false);
    264265    suite.err() << "Error: s2 not equal non-weighted version." << std::endl;
     
    266267    suite.err() << "non-weighted s2 = " << r.s2() << std::endl;
    267268  }
    268   if (std::abs(r.standard_error2(2000)-rw.standard_error2(2000))>10e-7){
     269  if (!suite.equal(r.standard_error2(2000), rw.standard_error2(2000), 10) ){
    269270    suite.add(false);
    270271    suite.err() << "Error: standard_error not equal non-weighted version."
    271272           << std::endl;
    272273  }
    273   if (std::abs(r.r2()-rw.r2())>10E-7){
     274  if (!suite.equal(r.r2(), rw.r2()) ){
    274275    suite.add(false);
    275276    suite.err() << "Error: r2 not equal non-weighted version." << std::endl;
     
    277278    suite.err() << "non-weighted r2 = " << r.r2() << std::endl;
    278279  }
    279   if (std::abs(r.prediction_error2(2000)-rw.prediction_error2(2000,1))>10e-7){
     280  if (!suite.equal(r.prediction_error2(2000), rw.prediction_error2(2000,1),
     281                   100) ){
    280282    suite.add(false);
    281283    suite.err() << "Error: prediction_error2 not equal non-weighted version.\n"
     
    302304  w*=2;
    303305  wr.fit(x,y,w);
    304   if (std::abs(wr.predict(2000)-predict)>10e-11){
     306  if (!suite.equal(wr.predict(2000), predict, 1e4) ){
    305307    suite.add(false);
    306308    suite.err() << "Error: predict not equal after rescaling.\n";
     
    309311    suite.err() << "       predict = " << wr.predict(2000) << "\n";
    310312  }
    311   if (std::abs(wr.s2(2)-s2)>10e-11){
     313  if (!suite.equal(wr.s2(2), s2, 1000) ){
    312314    suite.add(false);
    313315    suite.err() << "Error: s2 not equal after rescaling.\n";
     
    316318    suite.err() << "difference " << s2-wr.s2(2.0) << std::endl;
    317319  }
    318   if (std::abs(wr.standard_error2(2000)-standard_error2)>10e-6){
     320  if (!suite.equal(wr.standard_error2(2000), standard_error2, 1e9) ){
    319321    suite.add(false);
    320322    suite.err() << "Error: standard_error2 not equal after rescaling.\n";
     
    326328           << std::endl;
    327329  }
    328   if (std::abs(wr.r2()-r2)>10e-6){
     330  if (!suite.equal(wr.r2(), r2, 1000) ){
    329331    suite.add(false);
    330332    suite.err() << "Error: r2 not equal after rescaling.\n";
    331333  }
    332   if (std::abs(wr.prediction_error2(2000,2)-prediction_error2)>10e-6){
     334  if (!suite.equal(wr.prediction_error2(2000,2), prediction_error2, 1e8) ){
    333335    suite.add(false);
    334336    suite.err() << "Error: prediction_error2 not equal after rescaling.\n";
     
    364366
    365367  wr.fit(x2,y2,w2);
    366   if (std::abs(wr.predict(2000) - predict)>1e-10) {
     368  if (!suite.equal(wr.predict(2000), predict) ) {
    367369    suite.add(false);
    368370    suite.err() << "Error: predict not equal.\n";
     
    372374
    373375  }
    374   if (std::abs(wr.prediction_error2(2000) - prediction_error2)>1e-13) {
     376  if (!suite.equal(wr.prediction_error2(2000), prediction_error2) ) {
    375377    suite.add(false);
    376378    suite.err() << "Error: prediction_error2 not equal.\n";
    377379  }
    378   if (std::abs(wr.r2() - r2)>1e-15) {
     380  if (!suite.equal(wr.r2(), r2) ) {
    379381    suite.add(false);
    380382    suite.err() << "Error: r2 not equal.\n";
     
    382384    suite.err() << "   r2: " << wr.r2() << "\n";
    383385  }
    384   if (std::abs(wr.s2() - s2)>1e-15) {
     386  if (!suite.equal(wr.s2(), s2) ) {
    385387    suite.add(false);
    386388    suite.err() << "Error: s2 not equal.\n";
    387389  }
    388   if (std::abs(wr.standard_error2(2000) - standard_error2)>1e-15) {
     390  if (!suite.equal(wr.standard_error2(2000), standard_error2) ) {
    389391    suite.add(false);
    390392    suite.err() << "Error: standard_error2 not equal.\n";
     
    421423  }
    422424
    423   if (std::abs(md.standard_error2(z)-mdw.standard_error2(z))>10e-6){
     425  if (!suite.equal(md.standard_error2(z), mdw.standard_error2(z)) ){
    424426    suite.add(false);
    425427    suite.err() << "Error: standard_error2 not equal\n"
     
    428430           << std::endl;
    429431  }
    430   if (std::abs(md.prediction_error2(z)-mdw.prediction_error2(z,1.0))>10e-7){
     432  if (!suite.equal(md.prediction_error2(z), mdw.prediction_error2(z,1.0)) ){
    431433    suite.add(false);
    432434    suite.err() << "Error: prediction_error2 not equal\n"
     
    445447  w*=2;
    446448  mdw.fit(data,y,w);
    447   if (std::abs(mdw.predict(z)-predict)>10e-10){
     449  if (!suite.equal(mdw.predict(z), predict, 1e4) ){
    448450    suite.add(false);
    449451    suite.err() << "Error: predict not equal after rescaling.\n";
     
    451453    suite.err() << "   predict = " << mdw.predict(z) << "\n";
    452454  }
    453   if (std::abs(mdw.prediction_error2(z,2)-prediction_error2)>10e-7){
     455  if (!suite.equal(mdw.prediction_error2(z,2), prediction_error2, 1e8) ){
    454456    suite.add(false);
    455457    suite.err() << "Error: prediction_error2 not equal after rescaling.\n";
    456458    suite.err() << "       predict_error2 = " << prediction_error2
    457459           << " and after doubling weights.\n";
    458     suite.err() << "       predict_error2 = " << mdw.prediction_error2(z,2) << "\n";
    459   }
    460   if (std::abs(mdw.s2(2)-s2)>10e-10){
     460    suite.err() << "       predict_error2 = "
     461                << mdw.prediction_error2(z,2) << "\n";
     462  }
     463  if (!suite.equal(mdw.s2(2), s2, 1000) ){
    461464    suite.add(false);
    462465    suite.err() << "Error: s2 not equal after rescaling.\n";
     
    464467    suite.err() << "       s2 = " << mdw.s2(2) << "\n";
    465468  }
    466   if (std::abs(mdw.standard_error2(z)-standard_error2)>10e-7){
     469  if (!suite.equal(mdw.standard_error2(z), standard_error2, 1e9) ){
    467470    suite.add(false);
    468471    suite.err() << "Error: standard_error2 not equal after rescaling.\n";
Note: See TracChangeset for help on using the changeset viewer.