# Changeset 1234

Ignore:
Timestamp:
Mar 15, 2008, 5:00:54 PM (16 years ago)
Message:

working on #223

Location:
trunk/test
Files:
5 edited

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

 r1232 bool equal(double a, double b, u_int n) bool Suite::equal(double a, double b, u_int n) { return std::abs(a-b) <= n*std::numeric_limits().epsilon()*std::min(std::abs(a), std::abs(b)); last_error_bound_ = n*std::numeric_limits().epsilon()* std::min(std::abs(a), std::abs(b)); return std::abs(a-b) <= last_error_bound_; } double Suite::last_error_bound(void) const { return last_error_bound_; }
• ## trunk/test/Suite.h

 r1232 /** \return true if \f$|a-b| <= N * \epsilon * min(|a|,|b|) \f$ where \f$\epsilon \f$ is std::numeric_limits().epsilon() */ bool equal(double a, double b, unsigned int N=1); double last_error_bound(void) const; /** \return true if test is ok */ bool ok_; std::ofstream* dev_null_; double last_error_bound_; }; /** \return true if \f$|a-b| <= N * \epsilon * min(|a|,|b|) \f$ where \f$\epsilon \f$ is std::numeric_limits().epsilon() */ bool equal(double a, double b, unsigned int N=1); }}}
• ## trunk/test/averager_test.cc

 r1232 //  std::cout << (a.mean()==b.mean()) << std::endl; //  std::cout << (std::abs(a.variance()-b.variance()<1e-15)) << std::endl; return (a.n()==b.n() && test::equal(a.mean(),b.mean(),tol) && test::equal(a.variance(),b.variance(),tol)); return (a.n()==b.n() && suite.equal(a.mean(),b.mean(),tol) && suite.equal(a.variance(),b.variance(),tol)); } { bool equal = true; if  ( !test::equal(a.mean(),b.mean(),tol)){ if  ( !suite.equal(a.mean(),b.mean(),tol)){ equal=false; suite.err() << "mean:\t" << a.mean() << "\t" << b.mean() << std::endl; suite.err() << "difference:\t" << a.mean()-b.mean() << std::endl; } if ( !test::equal(a.variance(),b.variance(),tol) ) { if ( !suite.equal(a.variance(),b.variance(),tol) ) { equal=false; suite.err() << "error for variance:\t" << a.variance() << " " << b.variance() << std::endl; } if ( !test::equal(a.standard_error(),b.standard_error(),tol) ) { if ( !suite.equal(a.standard_error(),b.standard_error(),tol) ) { equal =false; suite.err() << "error for standard error:\t" << std::endl; { bool equal = true; if  ( !test::equal(a.mean(),b.mean(),tol)){ if  ( !suite.equal(a.mean(),b.mean(),tol)){ equal=false; suite.err() << "mean:\t" << a.mean() << "\t" << b.mean() << std::endl; } if ( !test::equal(a.variance(),b.variance(),tol) ) { if ( !suite.equal(a.variance(),b.variance(),tol) ) { equal=false; suite.err() << "error for variance:\t" << a.variance() << " " << b.variance() << std::endl; } if ( !test::equal(a.standard_error(), b.standard_error(),tol) ) { if ( !suite.equal(a.standard_error(), b.standard_error(),tol) ) { equal =false; suite.err() << "error for standard error:\t" << std::endl; { bool ok = true; if  ( !test::equal(a.covariance(),b.covariance(),tol) ){ if  ( !suite.equal(a.covariance(),b.covariance(),tol) ){ suite.add(false); suite.err() << "error covariance: " << a.covariance() << "\t" << b.covariance() << std::endl; } if ( !test::equal(a.correlation(), b.correlation(), tol) ) { if ( !suite.equal(a.correlation(), b.correlation(), tol) ) { suite.add(false); suite.err() << "error correlation" << std::endl;
• ## trunk/test/distance_test.cc

 r1233 using namespace theplu::yat; void check_equality(double, double, test::Suite&, const std::string&, u_int N=1); utility::Matrix data(void); 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&); utility::Matrix weight(void); int main(int argc, char* argv[]) { double tolerance=1e-4; statistics::EuclideanDistance eucl_dist; suite.err() << "testing EuclideanDistance" << std::endl; test_distance(eucl_dist, suite); 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); dist=pear_dist(a.begin(),a.end(),b.begin()); if(std::abs(dist-1.5)>tolerance) { } return suite.return_value(); } void check_equality(double dist1, double dist2, test::Suite& suite, const std::string& msg, u_int N) { if (!suite.equal(dist1, dist2, N)) { suite.err() << "Error: " << msg << " failed.\n"; suite.err() << "  dist1: " << dist1 << "\n"; suite.err() << "  dist2: " << dist2 << "\n"; suite.err() << "  difference: " << dist1-dist2 << "\n"; suite.err() << "  error bound: " << suite.last_error_bound() << "\n"; suite.add(false); } } utility::Matrix data(void) { utility::Matrix res(2,10); for (size_t i = 0; i 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) { utility::Matrix x(data()); utility::Matrix x2(x.rows(), 2*x.columns()); for (size_t i=0; i void test_rescaling(Distance dist, theplu::yat::test::Suite& suite) { utility::Matrix x=data(); utility::Matrix w=weight(); classifier::MatrixLookupWeighted ml(x,w); double dist1 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1)); 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) { utility::Matrix x=data(); classifier::MatrixLookupWeighted ml(x); 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) { utility::Matrix x = data(); double self = dist(x.begin(), x.end(), x.begin()); if (!suite.equal(self, 0.0)){ suite.err() << "error: self distance is " << self << "\n" << "supposed to be zero.\n"; suite.add(false); } } template void test_symmetry(Distance dist, theplu::yat::test::Suite& suite) { 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) { utility::Matrix x=data(); utility::Matrix w=weight(); classifier::MatrixLookupWeighted ml(x,w); w(0,0) = 0.0; double dist1 = dist(ml.begin_row(0), ml.end_row(0), ml.begin_row(1)); 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); } utility::Matrix weight(void) { utility::Matrix res(2,10); for (size_t i = 0; i
• ## trunk/test/regression_test.cc

 r1232 bool Local_test(regression::OneDimensionalWeighted&, regression::Kernel&); regression::Kernel&, test::Suite&); int main(int argc, char* argv[]) regression::Polynomial polynomial(1); polynomial.fit(x,y); if ( test::equal(linear.beta(),polynomial.fit_parameters()(1)) ){ if ( suite.equal(linear.beta(),polynomial.fit_parameters()(1)) ){ suite.err() << "error: beta and fit_parameters(1) not equal" << std::endl; suite.err() << "       beta = " << linear.beta() << std::endl; suite.add(false); } if (test::equal(polynomial.fit_parameters()(0), if (suite.equal(polynomial.fit_parameters()(0), linear.alpha()-linear.beta()*1985)){ suite.err() << "error: fit_parameters(0) = " y_predicted=naive_w.predict(0.0); y_predicted_err=naive_w.prediction_error2(0.0); if (!test::equal(y_predicted,0.1*12+0.2*11+0.3*14+0.4*13)) { if (!suite.equal(y_predicted,0.1*12+0.2*11+0.3*14+0.4*13)) { suite.err() << "regression_NaiveWeighted: cannot reproduce fit.\n"; suite.err() << "returned value: " << y_predicted << std::endl; regression::KernelBox kb; regression::LinearWeighted rl; if (!Local_test(rl,kb)) { if (!Local_test(rl,kb, suite)) { suite.err() << "regression_Local: Linear cannot reproduce fit." << std::endl; suite.add(false); } regression::NaiveWeighted rn; if (!Local_test(rn,kb)) { if (!Local_test(rn,kb, suite)) { suite.err() << "regression_Local: Naive cannot reproduce fit." << std::endl; suite.add(false); z(1)=2000; z(2)=2000*2000; if (!test::equal(md.predict(z), mdw.predict(z))){ if (!suite.equal(md.predict(z), mdw.predict(z))){ suite.add(false); suite.err() << "Error: predict not equal\n" bool Local_test(regression::OneDimensionalWeighted& r, regression::Kernel& k) regression::Kernel& k, test::Suite& suite) { regression::Local rl(r,k); utility::Vector y(rl.y_predicted()); for (size_t i=0; i
Note: See TracChangeset for help on using the changeset viewer.