# Changeset 731

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

added test for multidimensional weighted and straight version

Location:
trunk
Files:
6 edited

Unmodified
Removed
• ## trunk/test/regression_test.cc

 r730 bool equal(regression::OneDimensional&, regression::OneDimensionalWeighted&, std::ostream*); bool multidim(std::ostream* error); bool unity_weights(regression::OneDimensional&, *error << "  testing regression::PolynomialWeighted" << std::endl; regression::PolynomialWeighted pol_weighted(2); // ok = equal(polynomial, pol_weighted, error) && ok; ok = multidim(error) && ok; if (error!=&std::cerr) if (r.predict(2000) != rw.predict(2000)){ ok = false; *error << "Error: predict not equal" << std::endl; *error << "Error: predict not equal\n" << "   weighted: " << rw.predict(2000) << "\n" << "   non-weighted: " << r.predict(2000) << std::endl; } if (fabs(r.prediction_error2(2000)-rw.prediction_error2(2000))>10e-7){ bool multidim(std::ostream* error) { bool ok = true; *error << "  testing regression::MultiDimensionalWeighted" << std::endl; utility::vector x(5); x(0)=1970; x(1)=1980; x(2)=1990; x(3)=2000; x(4)=2010; utility::vector y(5); y(0)=12;   y(1)=11;   y(2)=14;   y(3)=13;   y(4)=15; utility::vector w(5,1.0); utility::matrix data(5,3); for (size_t i=0; i
• ## trunk/yat/regression/MultiDimensional.cc

 r727 #include "yat/utility/vector.h" #include namespace theplu { namespace yat { void MultiDimensional::fit(const utility::matrix& x, const utility::vector& y) { assert(x.rows()==y.size()); covariance_=utility::matrix(x.columns(),x.columns()); fit_parameters_=utility::vector(x.columns()); double MultiDimensional::predict(const utility::vector& x) const { assert(x.size()==fit_parameters_.size()); return fit_parameters_ * x; }
• ## trunk/yat/regression/MultiDimensional.h

 r727 /** @brief Mean Squared Error @brief Summed Squared Error */ double chisq(void) const;
• ## trunk/yat/regression/MultiDimensionalWeighted.cc

 r718 double MultiDimensionalWeighted::predict(const utility::vector& x) const { assert(x.size()==fit_parameters_.size()); return fit_parameters_ * x; } double MultiDimensionalWeighted::standard_error(const utility::vector& x) const double MultiDimensionalWeighted::standard_error2(const utility::vector& x) const { double s2 = 0; s2 += 2*covariance_(i,j)*x(i)*x(j); } return sqrt(s2); return s2; }
• ## trunk/yat/regression/MultiDimensionalWeighted.h

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

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