Changeset 925 for trunk/yat/classifier/IGP.h
 Timestamp:
 Oct 2, 2007, 4:02:08 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/IGP.h
r865 r925 25 25 */ 26 26 27 #include "DataLookup1D.h" 28 #include "MatrixLookup.h" 29 #include "Target.h" 27 30 #include "yat/utility/vector.h" 31 #include "yat/utility/yat_assert.h" 32 #include "yat/statistics/vector_distance.h" 33 34 #include <cmath> 35 #include <limits> 28 36 29 37 namespace theplu { 30 38 namespace yat { 31 32 namespace statistics {33 class Distance;34 }35 36 39 namespace classifier { 37 40 … … 43 46 /// See Kapp and Tibshirani, Biostatistics (2006). 44 47 /// 48 template <typename Distance> 45 49 class IGP 46 50 { … … 51 55 /// the distance measure as input. 52 56 /// 53 IGP(const MatrixLookup&, const Target& , const statistics::Distance&);57 IGP(const MatrixLookup&, const Target&); 54 58 55 59 /// … … 61 65 /// @return the IGP score for each class as elements in a vector. 62 66 /// 63 const utility::vector& score(void) const {return igp_;}67 const utility::vector& score(void) const; 64 68 65 69 … … 67 71 utility::vector igp_; 68 72 69 const statistics::Distance& distance_;70 73 const MatrixLookup& matrix_; 71 74 const Target& target_; 72 75 }; 76 77 78 // templates 79 80 template <typename Distance> 81 IGP<Distance>::IGP(const MatrixLookup& data, const Target& target) 82 : matrix_(data), target_(target) 83 { 84 yat_assert(target_.size()==matrix_.columns()); 85 86 // Calculate IGP for each class 87 igp_.clone(utility::vector(target_.nof_classes())); 88 89 for(u_int i=0; i<target_.size(); i++) { 90 u_int neighbor=i; 91 double mindist=std::numeric_limits<double>::max(); 92 const DataLookup1D a(matrix_,i,false); 93 for(u_int j=0; j<target_.size(); j++) { 94 DataLookup1D b(matrix_,j,false); 95 double dist=statistics:: 96 vector_distance(a.begin,a.end(),b.begin(), 97 statistics::vector_distance_traits<Distance>::distace()); 98 if(j!=i && dist<mindist) { 99 mindist=dist; 100 neighbor=j; 101 } 102 } 103 if(target_(i)==target_(neighbor)) 104 igp_(target_(i))++; 105 106 } 107 for(u_int i=0; i<target_.nof_classes(); i++) { 108 igp_(i)/=static_cast<double>(target_.size(i)); 109 } 110 } 111 112 template <typename Distance> 113 IGP<Distance>::~IGP() 114 { 115 } 116 117 118 template <typename Distance> 119 const utility::vector& IGP<Distance>::score(void) const 120 { 121 return igp_; 122 } 73 123 74 124 }}} // of namespace classifier, yat, and theplu
Note: See TracChangeset
for help on using the changeset viewer.