Changeset 731
- Timestamp:
- Jan 6, 2007, 5:06:19 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/regression_test.cc
r730 r731 43 43 bool equal(regression::OneDimensional&, regression::OneDimensionalWeighted&, 44 44 std::ostream*); 45 46 bool multidim(std::ostream* error); 45 47 46 48 bool unity_weights(regression::OneDimensional&, … … 185 187 *error << " testing regression::PolynomialWeighted" << std::endl; 186 188 regression::PolynomialWeighted pol_weighted(2); 189 // ok = equal(polynomial, pol_weighted, error) && ok; 190 191 ok = multidim(error) && ok; 187 192 188 193 if (error!=&std::cerr) … … 220 225 if (r.predict(2000) != rw.predict(2000)){ 221 226 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; 223 231 } 224 232 if (fabs(r.prediction_error2(2000)-rw.prediction_error2(2000))>10e-7){ … … 340 348 341 349 350 bool 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 342 391 bool Local_test(regression::OneDimensionalWeighted& r, 343 392 regression::Kernel& k) -
trunk/yat/regression/MultiDimensional.cc
r727 r731 26 26 #include "yat/utility/vector.h" 27 27 28 #include <cassert> 29 28 30 namespace theplu { 29 31 namespace yat { … … 52 54 void MultiDimensional::fit(const utility::matrix& x, const utility::vector& y) 53 55 { 56 assert(x.rows()==y.size()); 54 57 covariance_=utility::matrix(x.columns(),x.columns()); 55 58 fit_parameters_=utility::vector(x.columns()); … … 76 79 double MultiDimensional::predict(const utility::vector& x) const 77 80 { 81 assert(x.size()==fit_parameters_.size()); 78 82 return fit_parameters_ * x; 79 83 } -
trunk/yat/regression/MultiDimensional.h
r727 r731 68 68 69 69 /** 70 @brief MeanSquared Error70 @brief Summed Squared Error 71 71 */ 72 72 double chisq(void) const; -
trunk/yat/regression/MultiDimensionalWeighted.cc
r718 r731 62 62 double MultiDimensionalWeighted::predict(const utility::vector& x) const 63 63 { 64 assert(x.size()==fit_parameters_.size()); 64 65 return fit_parameters_ * x; 65 66 } … … 78 79 79 80 80 double MultiDimensionalWeighted::standard_error(const utility::vector& x) const 81 double 82 MultiDimensionalWeighted::standard_error2(const utility::vector& x) const 81 83 { 82 84 double s2 = 0; … … 86 88 s2 += 2*covariance_(i,j)*x(i)*x(j); 87 89 } 88 return s qrt(s2);90 return s2; 89 91 } 90 92 -
trunk/yat/regression/MultiDimensionalWeighted.h
r718 r731 70 70 /// @return error of model value in @a x 71 71 /// 72 double standard_error (const utility::vector& x) const;72 double standard_error2(const utility::vector& x) const; 73 73 74 74 /// -
trunk/yat/regression/PolynomialWeighted.cc
r729 r731 81 81 for (size_t i=1; i<=power_; ++i) 82 82 vec(i) = vec(i-1)*x; 83 return md_.standard_error (vec);83 return md_.standard_error2(vec); 84 84 } 85 85
Note: See TracChangeset
for help on using the changeset viewer.