Changeset 890 for trunk/test/vector_distance_test.cc
 Timestamp:
 Sep 25, 2007, 11:35:25 AM (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/vector_distance_test.cc
r889 r890 1 1 // $Id$ 2 2 3 #include "yat/classifier/DataLookupWeighted1D.h" 4 #include "yat/classifier/MatrixLookupWeighted.h" 3 5 #include "yat/statistics/euclidean_vector_distance.h" 4 6 #include "yat/statistics/pearson_vector_distance.h" 7 #include "yat/utility/matrix.h" 5 8 #include "yat/utility/vector.h" 6 9 … … 23 26 std::cout << "vector_distance_test v : for printing extra information\n"; 24 27 } 25 *error << "testing distance" << std::endl;28 *error << "testing vector_distance" << std::endl; 26 29 bool ok = true; 27 30 … … 31 34 b(2) = 1; 32 35 33 *error << "testing Euclidean vector_distance" << std::endl; 36 double tolerance=1e4; 37 34 38 double dist=statistics::vector_distance(a.begin(),a.end(),b.begin(), 35 39 statistics::euclidean_vector_distance_tag()); 40 if(fabs(dist2.23607)>tolerance) { 41 *error << "Error in unweighted Euclidean vector_distance: " << std::endl; 42 ok=false; 43 } 36 44 37 *error << "Dist: " << dist << std::endl;38 39 40 *error << "testing Pearson vector_distance" << std::endl;41 45 dist=statistics::vector_distance(a.begin(),a.end(),b.begin(), 42 46 statistics::pearson_vector_distance_tag()); 43 *error << "Dist: " << dist << std::endl; 47 if(fabs(dist1.5)>tolerance) { 48 *error << "Error in unweighted Pearson vector_distance: " << std::endl; 49 ok=false; 50 } 44 51 52 53 // Testing weighted versions 54 utility::matrix m(2,3,1); 55 m(0,1)=2; 56 m(1,0)=0; 57 m(1,1)=0; 58 utility::matrix w(2,3,1); 59 w(0,0)=0; 60 classifier::MatrixLookupWeighted mw(m,w); 61 classifier::DataLookupWeighted1D aw(mw,0,true); 62 classifier::DataLookupWeighted1D bw(mw,1,true); 63 64 dist=statistics::vector_distance(aw.begin(),aw.end(),bw.begin(), 65 statistics::euclidean_vector_distance_tag()); 66 67 if(fabs(dist2)>tolerance) { 68 *error << "Error in weighted Euclidean vector_distance: " << std::endl; 69 ok=false; 70 } 71 72 dist=statistics::vector_distance(aw.begin(),aw.end(),bw.begin(), 73 statistics::pearson_vector_distance_tag()); 74 75 if(fabs(dist2)>tolerance) { 76 *error << "Error in weighted Pearson vector_distance: " << std::endl; 77 ok=false; 78 } 45 79 46 80 if (error!=&std::cerr)
Note: See TracChangeset
for help on using the changeset viewer.