# Changeset 1247 for trunk

Ignore:
Timestamp:
Mar 17, 2008, 3:54:10 PM (15 years ago)
Message:

refs #223

Location:
trunk/test
Files:
4 edited

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

 r1244 bool Suite::equal_sqrt(double a, double b, unsigned long int n) { double last_error_bound = n* std::sqrt(std::numeric_limits().epsilon())* std::min(std::abs(a), std::abs(b)); if (!(std::abs(a-b) <= last_error_bound)){ err() << "Error: Comparing " << a << " and " << b << "\n  Difference: " << a - b << "\n  expected difference to be at most " << last_error_bound << std::endl; return false; } return true; } bool Suite::ok(void) const {
• ## trunk/test/Suite.h

 r1244 bool equal(double a, double b, unsigned long int N=1); /** \return true if \f$|a-b| <= N * sqrt(\epsilon) * min(|a|,|b|) \f$ where \f$\epsilon \f$ is std::numeric_limits().epsilon() */ bool equal_sqrt(double a, double b, unsigned long int N=1); template bool equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2,
• ## trunk/test/distance_test.cc

 r1239 #include #include #include #include #include template void test_distance(Distance, theplu::yat::test::Suite&); template void test_duplicate(Distance, theplu::yat::test::Suite&); template void test_rescaling(Distance, theplu::yat::test::Suite&); template void test_unity_weights(Distance, theplu::yat::test::Suite&); template void test_self_distance(Distance, theplu::yat::test::Suite&); template void test_symmetry(Distance, theplu::yat::test::Suite&); template void test_zero_weight(Distance, theplu::yat::test::Suite&); void test_distance(Distance, theplu::yat::test::Suite&, unsigned long int N=1); template void test_duplicate(Distance, theplu::yat::test::Suite&, unsigned long int N=1); template void test_rescaling(Distance, theplu::yat::test::Suite&, unsigned long int N=1); template void test_unity_weights(Distance, theplu::yat::test::Suite&, unsigned long int N=1); template void test_self_distance(Distance, theplu::yat::test::Suite&, unsigned long int N=1); template void test_symmetry(Distance, theplu::yat::test::Suite&, unsigned long int N=1); template void test_zero_weight(Distance, theplu::yat::test::Suite&, unsigned long int N=1); utility::Matrix weight(void); statistics::EuclideanDistance eucl_dist; suite.err() << "testing EuclideanDistance" << std::endl; test_distance(eucl_dist, suite); test_distance(eucl_dist, suite, 100); double dist=eucl_dist(a.begin(),a.end(),b.begin()); if(std::abs(dist-2.23607)>tolerance) { statistics::PearsonDistance pear_dist; suite.err() << "testing PearsonDistance" << std::endl; test_distance(pear_dist, suite); test_distance(pear_dist, suite, 1000); dist=pear_dist(a.begin(),a.end(),b.begin()); if(std::abs(dist-1.5)>tolerance) { template void test_distance(Distance dist, theplu::yat::test::Suite& suite) { test_duplicate(dist, suite); test_rescaling(dist, suite); test_unity_weights(dist, suite); test_self_distance(dist, suite); test_symmetry(dist, suite); test_zero_weight(dist, suite); } template void test_duplicate(Distance dist, theplu::yat::test::Suite& suite) void test_distance(Distance dist, theplu::yat::test::Suite& suite, unsigned int long N) { test_duplicate(dist, suite, N); test_rescaling(dist, suite, N); test_unity_weights(dist, suite, N); test_self_distance(dist, suite, N); test_symmetry(dist, suite, N); test_zero_weight(dist, suite, N); } template void test_duplicate(Distance dist, theplu::yat::test::Suite& suite, unsigned long int N) { utility::Matrix x(data()); w2(0,i)=0.0; double dist2 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1)); check_equality(dist1, dist2, suite, "duplicate property"); } template void test_rescaling(Distance dist, theplu::yat::test::Suite& suite) check_equality(dist1, dist2, suite, "duplicate property", N); } template void test_rescaling(Distance dist, theplu::yat::test::Suite& suite, unsigned long int N) { utility::Matrix x=data(); w *= 2.13; double dist2 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1)); check_equality(dist1, dist2, suite, "rescaling", 10); } template void test_unity_weights(Distance dist, theplu::yat::test::Suite& suite) check_equality(dist1, dist2, suite, "rescaling", N); } template void test_unity_weights(Distance dist, theplu::yat::test::Suite& suite, unsigned long int N) { utility::Matrix x=data(); double dist1 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1)); double dist2 = dist(x.begin_row(0), x.end_row(0), x.begin_row(1)); check_equality(dist1, dist2, suite, "unity weights", 10); } template void test_self_distance(Distance dist, theplu::yat::test::Suite& suite) check_equality(dist1, dist2, suite, "unity weights", N); } template void test_self_distance(Distance dist, theplu::yat::test::Suite& suite, unsigned long int N) { utility::Matrix x = data(); double self = dist(x.begin(), x.end(), x.begin()); if (!suite.equal(self, 0.0)){ if (!(std::abs(self) <= N*std::numeric_limits().epsilon()) ){ suite.err() << "error: self distance is " << self << "\n" << "supposed to be zero.\n"; template void test_symmetry(Distance dist, theplu::yat::test::Suite& suite) void test_symmetry(Distance dist, theplu::yat::test::Suite& suite, unsigned long int N) { utility::Matrix x = data(); double distab = dist(x.begin_row(0), x.end_row(0), x.begin_row(1)); double distba = dist(x.begin_row(1), x.end_row(1), x.begin_row(0)); check_equality(distab, distba, suite, "symmetry test"); } template void test_zero_weight(Distance dist, theplu::yat::test::Suite& suite) check_equality(distab, distba, suite, "symmetry test", N); } template void test_zero_weight(Distance dist, theplu::yat::test::Suite& suite, unsigned long int N) { utility::Matrix x=data(); w(0,0) = 100*std::numeric_limits().epsilon(); double dist2 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1)); check_equality(dist1, dist2, suite, "zero weight", 1000); check_equality(dist1, dist2, suite, "zero weight", N); }
• ## trunk/test/regression_test.cc

 r1244 } if (!suite.equal(polynomial.fit_parameters()(0), linear.alpha()-linear.beta()*1985, 1000)){ linear.alpha()-linear.beta()*1985, 10000)){ suite.err() << "error: fit_parameters(0) = " << polynomial.fit_parameters()(0)<< std::endl; } if (!suite.equal(polynomial.standard_error2(1985), linear.standard_error2(1985), 1e5)){ linear.standard_error2(1985), 100000)){ suite.err() << "error: standard_error not same in linear and polynomial(1)" << "\n  polynomial: " << polynomial.standard_error2(1985) // Comparing LinearWeighted and PolynomialWeighted(1) suite.err() << "    comparing LinearWeighted and PolynomialWeighted(1)" << std::endl; << std::endl; linear_w.fit(x,y,w); regression::PolynomialWeighted polynomial_w(1); polynomial_w.fit(x,y,w); if ( !suite.equal(linear_w.beta(), polynomial_w.fit_parameters()(1),100) ){ if ( !suite.equal(linear_w.beta(), polynomial_w.fit_parameters()(1),10000) ){ suite.err() << "error: beta and fit_parameters(1) not equal" << std::endl; suite.err() << "       beta = " << linear_w.beta() << std::endl; } if ( !suite.equal(polynomial_w.fit_parameters()(0), linear_w.alpha()-linear_w.beta()*1990, 100) ){ linear_w.alpha()-linear_w.beta()*1990, 10000) ){ suite.err() << "error: fit_parameters(0) = " << polynomial.fit_parameters()(0)<< std::endl; suite.add(false); } if ( !suite.equal(polynomial_w.predict(1.0), linear_w.predict(1.0), 100) ){ if ( !suite.equal(polynomial_w.predict(1.0), linear_w.predict(1.0), 10000) ){ suite.err() << "error: predict not same in linear and polynomial(1)" << std::endl; } if ( !suite.equal(polynomial_w.standard_error2(1985), linear_w.standard_error2(1985), 1e5) ){ linear_w.standard_error2(1985), 100000) ){ suite.err() << "error: standard_error not same in linear and polynomial(1)" << "\n  polynomial: " << polynomial_w.standard_error2(1985) w*=2; wr.fit(x,y,w); if (!suite.equal(wr.predict(2000), predict, 1e4) ){ if (!suite.equal(wr.predict(2000), predict, 10000) ){ suite.add(false); suite.err() << "Error: predict not equal after rescaling.\n"; suite.err() << "difference " << s2-wr.s2(2.0) << std::endl; } if (!suite.equal(wr.standard_error2(2000), standard_error2, 1e9) ){ if (!suite.equal_sqrt(wr.standard_error2(2000), standard_error2, 10) ){ suite.add(false); suite.err() << "Error: standard_error2 not equal after rescaling.\n"; suite.err() << "Error: r2 not equal after rescaling.\n"; } if (!suite.equal(wr.prediction_error2(2000,2), prediction_error2, 1e8) ){ if (!suite.equal_sqrt(wr.prediction_error2(2000,2), prediction_error2, 10) ){ suite.add(false); suite.err() << "Error: prediction_error2 not equal after rescaling.\n"; wr.fit(x2,y2,w2); if (!suite.equal(wr.predict(2000), predict) ) { if (!suite.equal(wr.predict(2000), predict, 10000) ) { suite.add(false); suite.err() << "Error: predict not equal.\n"; w*=2; mdw.fit(data,y,w); if (!suite.equal(mdw.predict(z), predict, 1e4) ){ if (!suite.equal(mdw.predict(z), predict, 10000) ){ suite.add(false); suite.err() << "Error: predict not equal after rescaling.\n"; suite.err() << "   predict = " << predict << " and after doubling weights.\n"; suite.err() << "   predict = " << predict << " and after doubling weights.\n"; suite.err() << "   predict = " << mdw.predict(z) << "\n"; } if (!suite.equal(mdw.prediction_error2(z,2), prediction_error2, 1e8) ){ if (!suite.equal_sqrt(mdw.prediction_error2(z,2), prediction_error2,10) ){ suite.add(false); suite.err() << "Error: prediction_error2 not equal after rescaling.\n"; suite.err() << "       s2 = " << mdw.s2(2) << "\n"; } if (!suite.equal(mdw.standard_error2(z), standard_error2, 1e9) ){ if (!suite.equal_sqrt(mdw.standard_error2(z), standard_error2, 10) ){ suite.add(false); suite.err() << "Error: standard_error2 not equal after rescaling.\n";
Note: See TracChangeset for help on using the changeset viewer.