Changeset 731


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

added test for multidimensional weighted and straight version

Location:
trunk
Files:
6 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)
  • trunk/yat/regression/MultiDimensional.cc

    r727 r731  
    2626#include "yat/utility/vector.h"
    2727
     28#include <cassert>
     29
    2830namespace theplu {
    2931namespace yat {
     
    5254  void MultiDimensional::fit(const utility::matrix& x, const utility::vector& y)
    5355  {
     56    assert(x.rows()==y.size());
    5457    covariance_=utility::matrix(x.columns(),x.columns());
    5558    fit_parameters_=utility::vector(x.columns());
     
    7679  double MultiDimensional::predict(const utility::vector& x) const
    7780  {
     81    assert(x.size()==fit_parameters_.size());
    7882    return fit_parameters_ * x;
    7983  }
  • trunk/yat/regression/MultiDimensional.h

    r727 r731  
    6868
    6969    /**
    70        @brief Mean Squared Error
     70       @brief Summed Squared Error
    7171     */
    7272    double chisq(void) const;
  • trunk/yat/regression/MultiDimensionalWeighted.cc

    r718 r731  
    6262  double MultiDimensionalWeighted::predict(const utility::vector& x) const
    6363  {
     64    assert(x.size()==fit_parameters_.size());
    6465    return fit_parameters_ * x;
    6566  }
     
    7879
    7980
    80   double MultiDimensionalWeighted::standard_error(const utility::vector& x) const
     81  double
     82  MultiDimensionalWeighted::standard_error2(const utility::vector& x) const
    8183  {
    8284    double s2 = 0;
     
    8688        s2 += 2*covariance_(i,j)*x(i)*x(j);
    8789    }
    88     return sqrt(s2);
     90    return s2;
    8991  }
    9092
  • trunk/yat/regression/MultiDimensionalWeighted.h

    r718 r731  
    7070    /// @return error of model value in @a x
    7171    ///
    72     double standard_error(const utility::vector& x) const;
     72    double standard_error2(const utility::vector& x) const;
    7373
    7474    ///
  • trunk/yat/regression/PolynomialWeighted.cc

    r729 r731  
    8181    for (size_t i=1; i<=power_; ++i)
    8282      vec(i) = vec(i-1)*x;
    83     return md_.standard_error(vec);
     83    return md_.standard_error2(vec);
    8484  }
    8585
Note: See TracChangeset for help on using the changeset viewer.