Changeset 1050
- Timestamp:
- Feb 7, 2008, 7:47:34 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/knn_test.cc
r1031 r1050 66 66 67 67 classifier::MatrixLookupWeighted dataviewweighted(data,weights); 68 classifier::KNN<statistics:: pearson_distance_tag> knn(dataviewweighted,targets);68 classifier::KNN<statistics::PearsonDistance> knn(dataviewweighted,targets); 69 69 *error << "training KNN" << std::endl; 70 70 knn.train(); -
trunk/test/ncc_test.cc
r1031 r1050 78 78 vec[3]="bjds"; 79 79 classifier::Target target(vec); 80 classifier::NCC<statistics:: pearson_distance_tag> ncctmp(ml,target);80 classifier::NCC<statistics::EuclideanDistance> ncctmp(ml,target); 81 81 *error << "training...\n"; 82 82 ncctmp.train(); … … 100 100 classifier::Target target1(vec1); 101 101 102 classifier::NCC<statistics:: euclidean_distance_tag> ncc1(ml1,target1);102 classifier::NCC<statistics::EuclideanDistance> ncc1(ml1,target1); 103 103 ncc1.train(); 104 104 utility::matrix prediction1; … … 150 150 151 151 classifier::MatrixLookupWeighted dataviewweighted(data,weights); 152 classifier::NCC<statistics:: pearson_distance_tag> ncc(dataviewweighted,targets);152 classifier::NCC<statistics::EuclideanDistance> ncc(dataviewweighted,targets); 153 153 *error << "training...\n"; 154 154 ncc.train(); -
trunk/test/vector_distance_test.cc
r1031 r1050 58 58 59 59 double tolerance=1e-4; 60 61 double dist=statistics::distance(a.begin(),a.end(),b.begin(), 62 statistics::euclidean_distance_tag()); 60 statistics::EuclideanDistance eucl_dist; 61 double dist=eucl_dist(a.begin(),a.end(),b.begin()); 63 62 if(fabs(dist-2.23607)>tolerance) { 64 63 *error << "Error in unweighted Euclidean distance " << std::endl; … … 66 65 } 67 66 68 dist=statistics::distance(a.begin(),a.end(),b.begin(),69 statistics::pearson_distance_tag());67 statistics::PearsonDistance pear_dist; 68 dist=pear_dist(a.begin(),a.end(),b.begin()); 70 69 if(fabs(dist-1.5)>tolerance) { 71 70 *error << "Error in unweighted Pearson distance " << std::endl; … … 85 84 classifier::DataLookupWeighted1D bw(mw,1,true); 86 85 87 dist=statistics::distance(aw.begin(),aw.end(),bw.begin(), 88 statistics::euclidean_distance_tag()); 86 dist=eucl_dist(aw.begin(),aw.end(),bw.begin()); 89 87 90 88 if(fabs(dist-sqrt(6))>tolerance) { … … 93 91 } 94 92 95 dist=statistics::distance(aw.begin(),aw.end(),bw.begin(), 96 statistics::pearson_distance_tag()); 93 dist=pear_dist(aw.begin(),aw.end(),bw.begin()); 97 94 98 95 if(fabs(dist-2)>tolerance) { … … 108 105 sb[2] = 1; 109 106 110 dist=statistics::distance(sa.begin(),sa.end(),sb.begin(), 111 statistics::euclidean_distance_tag()); 107 dist=eucl_dist(sa.begin(),sa.end(),sb.begin()); 112 108 if(fabs(dist-2.23607)>tolerance) { 113 109 *error << "Error in distance for std::vector " << std::endl; … … 118 114 std::list<double> la; 119 115 std::copy(sa.begin(),sa.end(),std::back_inserter<std::list<double> >(la)); 120 dist=statistics::distance(la.begin(),la.end(),sb.begin(), 121 statistics::euclidean_distance_tag()); 116 dist=eucl_dist(la.begin(),la.end(),sb.begin()); 122 117 if(fabs(dist-2.23607)>tolerance) { 123 118 *error << "Error in distance for std::list " << std::endl; -
trunk/yat/classifier/IGP.h
r1031 r1050 30 30 #include "yat/utility/vector.h" 31 31 #include "yat/utility/yat_assert.h" 32 #include "yat/statistics/distance.h"33 32 34 33 #include <cmath> … … 71 70 private: 72 71 utility::vector igp_; 72 Distance distance_; 73 73 74 74 const MatrixLookup& matrix_; … … 94 94 for(u_int j=0; j<target_.size(); j++) { 95 95 DataLookup1D b(matrix_,j,false); 96 double dist=statistics:: 97 distance(a.begin,a.end(),b.begin(), 98 statistics::distance_traits<Distance>::distace()); 96 double dist=distance_(a.begin, a.end(), b.begin()); 99 97 if(j!=i && dist<mindist) { 100 98 mindist=dist; -
trunk/yat/classifier/KNN.h
r1042 r1050 25 25 */ 26 26 27 #include "DataLookup1D.h" 27 28 #include "DataLookupWeighted1D.h" 28 29 #include "MatrixLookup.h" … … 30 31 #include "SupervisedClassifier.h" 31 32 #include "Target.h" 32 #include "yat/statistics/distance.h"33 33 #include "yat/utility/matrix.h" 34 34 #include "yat/utility/yat_assert.h" … … 113 113 u_int k_; 114 114 115 Distance distance_; 115 116 /// 116 117 /// Calculates the distances between a data set and the training … … 156 157 for(size_t j=0; j<test.columns(); j++) { 157 158 classifier::DataLookup1D test(*test_unweighted,j,false); 158 (*distances)(i,j) = 159 statistics::distance(classifier::DataLookup1D(data_, 160 i,false).begin(), 161 classifier::DataLookup1D(data_, 162 i,false).end(), 163 test.begin(), 164 typename statistics:: 165 distance_traits<Distance>::distance()); 159 classifier::DataLookup1D tmp(data_,i,false); 160 (*distances)(i,j) = distance_(tmp.begin(), tmp.end(), test.begin()); 166 161 utility::yat_assert<std::runtime_error>(!std::isnan((*distances)(i,j))); 167 162 } … … 180 175 classifier::DataLookupWeighted1D test(*test_weighted,j,false); 181 176 utility::yat_assert<std::runtime_error>(training.size()==test.size()); 182 (*distances)(i,j) = 183 statistics::distance(training.begin(),training.end(), 184 test.begin(), typename statistics::distance_traits<Distance>::distance()); 177 (*distances)(i,j) = distance_(training.begin(), training.end(), 178 test.begin()); 185 179 utility::yat_assert<std::runtime_error>(!std::isnan((*distances)(i,j))); 186 180 } -
trunk/yat/classifier/NCC.h
r1042 r1050 37 37 #include "yat/statistics/Averager.h" 38 38 #include "yat/statistics/AveragerWeighted.h" 39 #include "yat/statistics/distance.h"40 41 39 #include "yat/utility/Iterator.h" 42 40 #include "yat/utility/IteratorWeighted.h" … … 112 110 utility::matrix* centroids_; 113 111 bool centroids_nan_; 112 Distance distance_; 114 113 115 114 // data_ has to be of type DataLookup2D to accomodate both … … 270 269 DataLookup1D centroid(unweighted_centroids,k,false); 271 270 utility::yat_assert<std::runtime_error>(in.size()==centroid.size()); 272 prediction(k,j)=statistics:: 273 distance(in.begin(),in.end(),centroid.begin(), 274 typename statistics::distance_traits<Distance>::distance()); 271 prediction(k,j) = distance_(in.begin(), in.end(), centroid.begin()); 275 272 } 276 273 } … … 287 284 DataLookupWeighted1D centroid(weighted_centroids,k,false); 288 285 utility::yat_assert<std::runtime_error>(in.size()==centroid.size()); 289 prediction(k,j)=statistics:: 290 distance(in.begin(),in.end(),centroid.begin(), 291 typename statistics::distance_traits<Distance>::distance()); 286 prediction(k,j) = distance_(in.begin(), in.end(), centroid.begin()); 292 287 } 293 288 } -
trunk/yat/statistics/Makefile.am
r1031 r1050 40 40 include_statistics_HEADERS = AUC.h Averager.h AveragerPair.h \ 41 41 AveragerWeighted.h AveragerPairWeighted.h \ 42 distance.heuclidean_distance.h Fisher.h \42 euclidean_distance.h Fisher.h \ 43 43 FoldChange.h Histogram.h \ 44 44 KolmogorovSmirnov.h \ -
trunk/yat/statistics/euclidean_distance.h
r1031 r1050 6 6 /* 7 7 Copyright (C) 2007 Peter Johansson, Markus Ringnér 8 Copyright (C) 2008 Peter Johansson 8 9 9 10 This file is part of the yat library, http://trac.thep.lu.se/yat … … 27 28 #include "AveragerPair.h" 28 29 #include "AveragerPairWeighted.h" 29 #include "distance.h"30 30 #include "yat/utility/iterator_traits.h" 31 31 … … 34 34 namespace theplu { 35 35 namespace yat { 36 37 36 namespace statistics { 38 37 39 /// 40 /// Provides a "label" for 41 /// the Euclidean distance measure. 42 /// 43 struct euclidean_distance_tag 44 : public distance_tag 38 struct EuclideanDistance 45 39 { 46 /// \brief tag for euclidean distance 47 typedef euclidean_distance_tag distance; 40 template <typename Iter1, typename Iter2> 41 double operator() 42 (Iter1 beg1,Iter1 end1, Iter2 beg2) const 43 { 44 return this->distance(beg1, end1, beg2, 45 typename utility::weighted_if_any2<Iter1,Iter2>::type()); 46 } 47 48 private: 49 template <typename Iter1, typename Iter2> 50 double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 51 utility::unweighted_type) const 52 { 53 AveragerPair ap; 54 add(ap,beg1,end1,beg2); 55 return sqrt(ap.sum_squared_deviation()); 56 } 57 58 template <typename Iter1, typename Iter2> 59 double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 60 utility::weighted_type) const 61 { 62 AveragerPairWeighted ap; 63 add(ap,beg1,end1,beg2); 64 return sqrt(std::distance(beg1,end1)*ap.msd()); 65 } 66 48 67 }; 49 68 50 51 ///52 /// implementation for distances between vectors53 /// (containers with random access iterators) using a Euclidean54 /// distance measure and iterators to unweighted containers.55 ///56 template <typename Iter1, typename Iter2>57 double distance(Iter1 beg1,Iter1 end1, Iter2 beg2,58 const euclidean_distance_tag& disttype,59 utility::unweighted_type)60 {61 AveragerPair ap;62 add(ap,beg1,end1,beg2);63 return sqrt(ap.sum_squared_deviation());64 }65 66 67 ///68 /// implementation for distances between vectors69 /// (containers with random access iterators) using a Euclidean70 /// distance measure and iterators to weighted containers.71 ///72 template <typename Iter1, typename Iter2>73 double distance(Iter1 beg1, Iter1 end1, Iter2 beg2,74 const euclidean_distance_tag& disttype,75 utility::weighted_type)76 {77 AveragerPairWeighted ap;78 add(ap,beg1,end1,beg2);79 return sqrt(std::distance(beg1,end1)*ap.msd());80 }81 82 83 69 }}} // of namespace statistics, yat, and theplu 84 70 -
trunk/yat/statistics/pearson_distance.h
r1031 r1050 6 6 /* 7 7 Copyright (C) 2007 Peter Johansson, Markus Ringnér 8 Copyright (C) 2008 Peter Johansson 8 9 9 10 This file is part of the yat library, http://trac.thep.lu.se/yat … … 25 26 */ 26 27 27 #include "distance.h"28 29 28 #include "AveragerPair.h" 30 29 #include "AveragerPairWeighted.h" … … 33 32 namespace theplu { 34 33 namespace yat { 35 36 34 namespace statistics { 37 35 38 /// 39 /// Provides a "label" for 40 /// the Pearson distance measure. 41 /// 42 struct pearson_distance_tag 43 : public distance_tag 36 struct PearsonDistance 44 37 { 45 /// \brief tag for pearson distance 46 typedef pearson_distance_tag distance; 38 template <typename Iter1, typename Iter2> 39 double operator() 40 (Iter1 beg1,Iter1 end1, Iter2 beg2) const 41 { 42 return this->distance(beg1, end1, beg2, 43 typename utility::weighted_if_any2<Iter1,Iter2>::type()); 44 } 45 46 private: 47 template <typename Iter1, typename Iter2> 48 double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 49 utility::unweighted_type) const 50 { 51 AveragerPairWeighted ap; 52 add(ap,beg1,end1,beg2); 53 return 1-ap.correlation(); 54 } 55 56 template <typename Iter1, typename Iter2> 57 double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 58 utility::weighted_type) const 59 { 60 AveragerPairWeighted ap; 61 add(ap,beg1,end1,beg2); 62 return 1-ap.correlation(); 63 } 64 47 65 }; 48 66 49 50 ///51 /// implementation for distances between vectors52 /// (containers with random access iterators) using a Pearson53 /// distance measure and iterators to unweighted containers.54 ///55 template <class Iter>56 double distance(Iter beg1,Iter end1, Iter beg2,57 const pearson_distance_tag& disttype,58 utility::unweighted_type)59 {60 AveragerPair ap;61 add(ap,beg1,end1,beg2);62 return 1-ap.correlation();63 }64 65 ///66 /// implementation for distances between vectors67 /// (containers with random access iterators) using a Pearson68 /// distance measure and iterators to unweighted containers.69 ///70 template <class Iter>71 double distance(Iter beg1,Iter end1, Iter beg2,72 const pearson_distance_tag& disttype,73 utility::weighted_type)74 {75 AveragerPairWeighted ap;76 add(ap,beg1,end1,beg2);77 return 1-ap.correlation();78 }79 80 81 67 }}} // of namespace statistics, yat, and theplu 82 68 -
trunk/yat/utility/SmartPtr.h
r1048 r1050 39 39 /** 40 40 \brief Constructor 41 42 \param p underlying pointer 43 \param owner if true SmartPtr will be owner of pointer and if 44 there is no more owner delete it in destructor. 45 46 Never use this constructor to create two SmartPtr to the same 47 pointer such as 48 \code 49 MyClass* my_pointer = new MyClass; 50 SmartPtr<MyClass> sp(my_pointer); 51 SmartPtr<MyClass> sp2(my_pointer); // this is evil 52 \endcode 53 since this will cause multiple deletion. Instead use copy constructor 54 \code 55 MyClass* my_pointer = new MyClass; 56 SmartPtr<MyClass> sp(my_pointer); 57 SmartPtr<MyClass> sp2(sp); 58 \endcode 59 so the internal reference counter is updated. 41 60 */ 42 61 explicit SmartPtr(T* p=NULL, bool owner=true)
Note: See TracChangeset
for help on using the changeset viewer.