Ignore:
Timestamp:
Jan 6, 2007, 5:06:19 PM (16 years ago)
Author:
Peter
Message:

added test for multidimensional weighted and straight version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/regression_test.cc

    r730 r731  
    4343bool equal(regression::OneDimensional&, regression::OneDimensionalWeighted&,
    4444           std::ostream*);
     45
     46bool multidim(std::ostream* error);
    4547
    4648bool unity_weights(regression::OneDimensional&,
     
    185187  *error << "  testing regression::PolynomialWeighted" << std::endl;
    186188  regression::PolynomialWeighted pol_weighted(2);
     189  // ok = equal(polynomial, pol_weighted, error) && ok;
     190
     191  ok = multidim(error) && ok;
    187192
    188193  if (error!=&std::cerr)
     
    220225  if (r.predict(2000) != rw.predict(2000)){
    221226    ok = false;
    222     *error << "Error: predict not equal" << std::endl;
     227    *error << "Error: predict not equal\n"
     228           << "   weighted: " << rw.predict(2000) << "\n"
     229           << "   non-weighted: " << r.predict(2000)
     230           << std::endl;
    223231  }
    224232  if (fabs(r.prediction_error2(2000)-rw.prediction_error2(2000))>10e-7){
     
    340348
    341349
     350bool multidim(std::ostream* error)
     351{
     352  bool ok = true;
     353  *error << "  testing regression::MultiDimensionalWeighted" << std::endl;
     354  utility::vector x(5); x(0)=1970; x(1)=1980; x(2)=1990; x(3)=2000; x(4)=2010;
     355  utility::vector y(5); y(0)=12;   y(1)=11;   y(2)=14;   y(3)=13;   y(4)=15;
     356  utility::vector w(5,1.0);
     357 
     358  utility::matrix data(5,3);
     359  for (size_t i=0; i<data.rows(); ++i){
     360    data(i,0)=1;
     361    data(i,1)=x(i);
     362    data(i,2)=x(i)*x(i);
     363  }
     364  regression::MultiDimensional md;
     365  md.fit(data,y);
     366  regression::MultiDimensionalWeighted mdw;
     367  mdw.fit(data,y,w);
     368  utility::vector z(3,1);
     369  z(1)=2000;
     370  z(2)=2000*2000;
     371  if (md.predict(z) != mdw.predict(z)){
     372    ok = false;
     373    *error << "Error: predict not equal\n"
     374           << "   weighted: " << mdw.predict(1) << "\n"
     375           << "   non-weighted: " << md.predict(1)
     376           << std::endl;
     377  }
     378  /*
     379  if (md.standard_error2(z) != mdw.standard_error2(z)){
     380    ok = false;
     381    *error << "Error: standard_error2 not equal\n"
     382           << "   weighted: " << mdw.standard_error2(z) << "\n"
     383           << "   non-weighted: " << md.standard_error2(z)
     384           << std::endl;
     385  }
     386  */
     387  return ok;
     388}
     389
     390
    342391bool Local_test(regression::OneDimensionalWeighted& r,
    343392                regression::Kernel& k)
Note: See TracChangeset for help on using the changeset viewer.