Changeset 740


Ignore:
Timestamp:
Jan 12, 2007, 4:17:22 PM (15 years ago)
Author:
Peter
Message:

added more test in MultiDimWeighted? and moved some stuff to be implemented in MultiDimWeighted? rather than in PolynomialWeighted?.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/regression_test.cc

    r739 r740  
    187187  *error << "  testing regression::PolynomialWeighted" << std::endl;
    188188  regression::PolynomialWeighted pol_weighted(2);
    189   // ok = equal(polynomial, pol_weighted, error) && ok;
     189  regression::Polynomial polynomial2(2);
     190  // ok = equal(polynomial2, pol_weighted, error) && ok;
    190191
    191192  ok = multidim(error) && ok;
     193
     194  if (!ok)
     195    *error << "Test failed\n" << std::endl;
    192196
    193197  if (error!=&std::cerr)
     
    392396  }
    393397
     398  w(0)=1.0;  w(1)=1.0;  w(2)=0.5;  w(3)=0.2;  w(4)=0.2;
     399  mdw.fit(data,y,w);
     400  double predict = mdw.predict(z);
     401  double prediction_error2 = mdw.prediction_error2(z, 1.0);
     402  double s2 = mdw.s2(1.0);
     403  double standard_error2 = mdw.standard_error2(z);
     404
     405  w.scale(2);
     406  mdw.fit(data,y,w);
     407  if (fabs(mdw.predict(z)-predict)>10e-10){
     408    ok = false;
     409    *error << "Error: predict not equal after rescaling.\n";
     410    *error << "   predict = " << predict << " and after doubling weights.\n";
     411    *error << "   predict = " << mdw.predict(z) << "\n";
     412  }
     413  if (fabs(mdw.prediction_error2(z,2)-prediction_error2)>10e-7){
     414    ok = false;
     415    *error << "Error: prediction_error2 not equal after rescaling.\n";
     416    *error << "       predict_error2 = " << prediction_error2
     417           << " and after doubling weights.\n";
     418    *error << "       predict_error2 = " << mdw.prediction_error2(z,2) << "\n";
     419  }
     420  if (fabs(mdw.s2(2)-s2)>10e-10){
     421    ok = false;
     422    *error << "Error: s2 not equal after rescaling.\n";
     423    *error << "       s2 = " << s2 << " and after doubling weights.\n";
     424    *error << "       s2 = " << mdw.s2(2) << "\n";
     425  }
     426  if (fabs(mdw.standard_error2(z)-standard_error2)>10e-7){
     427    ok = false;
     428    *error << "Error: standard_error2 not equal after rescaling.\n";
     429    *error << " standard_error2 = " << standard_error2
     430           << " and after doubling weights.\n";
     431    *error << " standard_error2 = " << mdw.standard_error2(z) << "\n";
     432  }
     433
    394434  return ok;
    395435}
  • trunk/yat/regression/MultiDimensionalWeighted.cc

    r739 r740  
    6666  }
    6767
     68
     69  const utility::vector& MultiDimensionalWeighted::fit_parameters(void) const
     70  {
     71    return fit_parameters_;
     72  }
     73
    6874  double MultiDimensionalWeighted::predict(const utility::vector& x) const
    6975  {
     
    7581                                                     const double w) const
    7682  {
    77     return standard_error2(x) + s2_/w;
     83    return standard_error2(x) + s2(w);
     84  }
     85
     86
     87  double MultiDimensionalWeighted::s2(const double w) const
     88  {
     89    return s2_/w;
    7890  }
    7991
  • trunk/yat/regression/MultiDimensionalWeighted.h

    r739 r740  
    6666    /// in @a x
    6767    ///
    68     double prediction_error2(const utility::vector& x, const double w) const;
     68    double prediction_error2(const utility::vector& x, const double w=1) const;
    6969
    7070    ///
     
    7676    /// @return parameters of fitted model
    7777    ///
    78     utility::vector fit_parameters(void) { return fit_parameters_; }
     78    const utility::vector& fit_parameters(void) const;
     79
     80    ///
     81    /// @return variance of residuals
     82    ///
     83    double s2(const double w=1.0) const;
    7984
    8085  private:
  • trunk/yat/regression/PolynomialWeighted.cc

    r739 r740  
    3333
    3434  PolynomialWeighted::PolynomialWeighted(size_t power)
    35     : OneDimensionalWeighted(), mse_(0), power_(power)
     35    : OneDimensionalWeighted(), power_(power)
    3636  {
    3737  }
     
    5454  }
    5555
    56   double PolynomialWeighted::s2(const double) const
     56
     57  const utility::vector& PolynomialWeighted::fit_parameters(void) const
    5758  {
    58     return mse_;
     59    return md_.fit_parameters();
     60  }
     61
     62
     63  double PolynomialWeighted::s2(const double w=1.0) const
     64  {
     65    return md_.s2(w);
    5966  }
    6067
  • trunk/yat/regression/PolynomialWeighted.h

    r739 r740  
    6363
    6464    ///
     65    /// @return parameters of the model
     66    ///
     67    /// @see MultiDimensional
     68    ///
     69    const utility::vector& fit_parameters(void) const;
     70
     71    ///
    6572    /// @return parameters for polynomial model
    6673    ///
     
    9097  private:
    9198    MultiDimensionalWeighted md_;
    92     double mse_;
    9399    size_t power_;
    94100
Note: See TracChangeset for help on using the changeset viewer.