Changeset 3316 for trunk/yat/classifier/IGP.h
- Timestamp:
- Sep 19, 2014, 7:38:10 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/IGP.h
r2384 r3316 1 #ifndef _theplu_yat_classifier_igp_ 2 #define _theplu_yat_classifier_igp_ 1 #ifndef _theplu_yat_classifier_igp_ 2 #define _theplu_yat_classifier_igp_ 3 3 4 4 // $Id$ … … 39 39 namespace theplu { 40 40 namespace yat { 41 namespace classifier { 41 namespace classifier { 42 42 43 43 class Target; … … 52 52 class IGP 53 53 { 54 54 55 55 public: 56 56 /// 57 57 /// Constructor taking the training data and the target vector and 58 /// as input. 58 /// as input. 59 59 /// 60 60 IGP(const MatrixLookup&, const Target&); … … 63 63 /// 64 64 /// Constructor taking the training data, the target vector and 65 /// the distance measure as input. 65 /// the distance measure as input. 66 66 /// 67 67 IGP(const MatrixLookup&, const Target&, const Distance&); … … 86 86 const MatrixLookup& matrix_; 87 87 const Target& target_; 88 }; 88 }; 89 89 90 90 91 91 // templates 92 92 93 93 template <typename Distance> 94 IGP<Distance>::IGP(const MatrixLookup& data, const Target& target) 94 IGP<Distance>::IGP(const MatrixLookup& data, const Target& target) 95 95 : matrix_(data), target_(target) 96 { 96 { 97 97 BOOST_CONCEPT_ASSERT((utility::DistanceConcept<Distance>)); 98 98 calculate(); … … 100 100 101 101 template <typename Distance> 102 IGP<Distance>::IGP(const MatrixLookup& data, const Target& target, const Distance& dist) 102 IGP<Distance>::IGP(const MatrixLookup& data, const Target& target, const Distance& dist) 103 103 : matrix_(data), target_(target), distance_(dist) 104 { 104 { 105 105 BOOST_CONCEPT_ASSERT((utility::DistanceConcept<Distance>)); 106 106 calculate(); 107 107 } 108 108 109 109 110 110 template <typename Distance> 111 IGP<Distance>::~IGP() 111 IGP<Distance>::~IGP() 112 112 { 113 113 } 114 114 115 115 template <typename Distance> 116 void IGP<Distance>::calculate() 116 void IGP<Distance>::calculate() 117 117 { 118 118 YAT_ASSERT(target_.size()==matrix_.columns()); 119 119 120 120 // Calculate IGP for each class 121 121 igp_ = utility::Vector(target_.nof_classes()); 122 122 123 123 for(size_t i=0; i<target_.size(); i++) { 124 124 size_t neighbor=i; 125 125 double mindist=std::numeric_limits<double>::max(); 126 for(size_t j=0; j<target_.size(); j++) { 126 for(size_t j=0; j<target_.size(); j++) { 127 127 if (i==j) // avoid self-self comparison 128 128 continue; 129 double dist = distance_(matrix_.begin_column(i), matrix_.end_column(i), 129 double dist = distance_(matrix_.begin_column(i), matrix_.end_column(i), 130 130 matrix_.begin_column(j)); 131 131 if(dist<mindist) { … … 136 136 if(target_(i)==target_(neighbor)) 137 137 igp_(target_(i))++; 138 138 139 139 } 140 140 for(size_t i=0; i<target_.nof_classes(); i++) { … … 143 143 } 144 144 145 145 146 146 template <typename Distance> 147 const utility::Vector& IGP<Distance>::score(void) const 147 const utility::Vector& IGP<Distance>::score(void) const 148 148 { 149 149 return igp_; 150 150 } 151 151 152 152 }}} // of namespace classifier, yat, and theplu 153 153
Note: See TracChangeset
for help on using the changeset viewer.