Changeset 388


Ignore:
Timestamp:
Aug 15, 2005, 11:41:58 AM (17 years ago)
Author:
Peter
Message:

added test on Regression::Linear

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/regression_test.cc

    r385 r388  
    2222int main(const int argc,const char* argv[])
    2323{
    24   bool print=((argc>1) && (argv[1]==std::string("-p")));
    25   if (print)
    26     std::cout << "regression: testing linear, local, naive, and polynomial fits"
    27               << std::endl;
     24  std::ostream* error;
     25  if (argc>1 && argv[1]==std::string("-p"))
     26    error = &std::cerr;
     27  else
     28    error = new std::ofstream("/dev/null");
     29
     30  *error << "regression: testing linear, local, naive, and polynomial fits"
     31         << std::endl;
    2832
    2933  bool ok=true;
     
    3640  // testing regression::Linear
    3741  statistics::regression::Linear linear;
    38   linear.fit(x,w,y);
     42  linear.fit(x,y,w);
    3943  double y_predicted=0;
    4044  double y_predicted_err=0;
    41   linear.predict(0,y_predicted,y_predicted_err);
    42   // Jari, check missing!
     45  linear.predict(1990,y_predicted,y_predicted_err);
     46  if (y_predicted!=12.8){
     47    *error << "regression_Linear: cannot reproduce fit." << std::endl;
     48    ok=false;
     49  }
    4350
    4451  // testing regression::Naive
     
    4956  naive.predict(0.0,y_predicted,y_predicted_err);
    5057  if (y_predicted!=(0.1*12+0.2*11+0.3*14+0.4*13)) {
    51     if (print)
    52       std::cerr << "regression_Naive: cannot reproduce fit." << std::endl;
     58    *error << "regression_Naive: cannot reproduce fit." << std::endl;
    5359    ok=false;
    5460  }
     
    5864  statistics::regression::Linear rl;
    5965  if (!Local_test(rl,kb)) {
    60     if (print)
    61       std::cerr << "regression_Local: Linear cannot reproduce fit." << std::endl;
     66    *error << "regression_Local: Linear cannot reproduce fit." << std::endl;
    6267    ok=false;
    6368  }
    6469  statistics::regression::Naive rn;
    6570  if (!Local_test(rn,kb)) {
    66     if (print)
    67       std::cerr << "regression_Local: Naive cannot reproduce fit." << std::endl;
     71    *error << "regression_Local: Naive cannot reproduce fit." << std::endl;
    6872    ok=false;
    6973  }
     
    8589    if (fabs(fit[0]-1.012229646706 + fit[1]-0.012561322528 +
    8690             fit[2]+1.159674470130)>1e-11) {  // Jari, fix number!
    87       if (print)
    88         std::cerr << "regression_Polynomial: cannot reproduce fit." << std::endl;
     91      *error << "regression_Polynomial: cannot reproduce fit." << std::endl;
    8992      ok=false;
    9093    }
    9194  }
     95
     96  if (error!=&std::cerr)
     97    delete error;
    9298
    9399  return (ok ? 0 : -1);
Note: See TracChangeset for help on using the changeset viewer.