Changeset 714 for trunk/yat/classifier
- Timestamp:
- Dec 22, 2006, 1:10:54 AM (17 years ago)
- Location:
- trunk/yat/classifier
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/SVindex.cc
r680 r714 51 51 for (size_t i=0; i<vec_.size(); i++) 52 52 vec_[i]=i; 53 } 54 55 size_t SVindex::index_first(void) const 56 { 57 assert(index_first_<size()); 58 return index_first_; 59 } 60 61 size_t SVindex::index_second(void) const 62 { 63 assert(index_second_<size()); 64 return index_second_; 53 65 } 54 66 … … 70 82 } 71 83 72 void SVindex::sv_first(void) 73 { 74 // if already sv, do nothing 75 if (index_first_<nof_sv()) 76 return; 77 78 // swap elements 79 if(index_second_==nof_sv_){ 80 index_second_=index_first_; 81 } 82 vec_[index_first_]=vec_[nof_sv_]; 83 vec_[nof_sv_]=value_first_; 84 index_first_ = nof_sv_; 85 86 nof_sv_++; 87 88 } 89 90 void SVindex::sv_second(void) 91 { 92 // if already sv, do nothing 93 if (index_second_<nof_sv()) 94 return; 95 96 // swap elements 97 if(index_first_==nof_sv_){ 98 index_first_=index_second_; 99 } 100 101 vec_[index_second_]=vec_[nof_sv_]; 102 vec_[nof_sv_]=value_second_; 103 index_second_=nof_sv_; 104 105 nof_sv_++; 84 size_t SVindex::nof_sv(void) const 85 { 86 return nof_sv_; 106 87 } 107 88 … … 143 124 } 144 125 126 size_t SVindex::size(void) const 127 { 128 return vec_.size(); 129 } 130 131 void SVindex::sv_first(void) 132 { 133 // if already sv, do nothing 134 if (index_first_<nof_sv()) 135 return; 136 137 // swap elements 138 if(index_second_==nof_sv_){ 139 index_second_=index_first_; 140 } 141 vec_[index_first_]=vec_[nof_sv_]; 142 vec_[nof_sv_]=value_first_; 143 index_first_ = nof_sv_; 144 145 nof_sv_++; 146 147 } 148 149 void SVindex::sv_second(void) 150 { 151 // if already sv, do nothing 152 if (index_second_<nof_sv()) 153 return; 154 155 // swap elements 156 if(index_first_==nof_sv_){ 157 index_first_=index_second_; 158 } 159 160 vec_[index_second_]=vec_[nof_sv_]; 161 vec_[nof_sv_]=value_second_; 162 index_second_=nof_sv_; 163 164 nof_sv_++; 165 } 166 145 167 void SVindex::update_first(const size_t i) 146 168 { … … 157 179 } 158 180 181 size_t SVindex::value_first(void) const 182 { 183 assert(value_first_<size()); 184 return value_first_; 185 } 186 187 size_t SVindex::value_second(void) const 188 { 189 assert(value_second_<size()); 190 return value_second_; 191 } 192 193 size_t SVindex::operator()(size_t i) const 194 { 195 assert(i<size()); 196 assert(vec_[i]<size()); 197 return vec_[i]; 198 } 199 159 200 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/SVindex.h
r706 r714 50 50 51 51 // @return index_first 52 inline size_t index_first(void) const { return index_first_; }52 size_t index_first(void) const; 53 53 54 54 // @return index_second 55 inline size_t index_second(void) const { return index_second_; }55 size_t index_second(void) const; 56 56 57 57 // synch the object against alpha 58 58 void init(const utility::vector& alpha, const double); 59 59 60 // @return nof samples61 inline size_t size(void) const { return vec_.size(); }62 63 60 // @return nof support vectors 64 inline size_t nof_sv(void) const { return nof_sv_; }61 size_t nof_sv(void) const; 65 62 66 63 // making first to an nsv. If already sv, nothing happens. … … 73 70 // nof_sv_ (the first nsv) 74 71 void shuffle(void); 72 73 // @return nof samples 74 size_t size(void) const; 75 75 76 76 // making first to a sv. If already sv, nothing happens. … … 87 87 88 88 // @return value_first 89 inline size_t value_first(void) const { return value_first_; }89 size_t value_first(void) const; 90 90 91 91 // @return const ref value_second 92 inline size_t value_second(void) const { return value_second_; }92 size_t value_second(void) const; 93 93 94 inline size_t operator()(size_t i) const { return vec_[i]; }94 size_t operator()(size_t i) const; 95 95 96 96 private: -
trunk/yat/classifier/Target.cc
r680 r714 88 88 } 89 89 90 bool Target::binary(size_t i) const 91 { 92 assert(i<size()); 93 return binary_[operator()(i)]; 94 } 95 96 const std::map<std::string,size_t>& Target::classes(void) const 97 { 98 return class_map_; 99 } 100 90 101 void Target::init(const std::vector<std::string>& label) 91 102 { … … 118 129 } 119 130 131 const std::vector<std::string>& Target::labels(void) 132 { 133 return labels_; 134 } 135 136 const size_t Target::nof_classes(void) const 137 { 138 return classes().size(); 139 } 140 120 141 void Target::random_shuffle(void) 121 142 { 122 143 random::DiscreteUniform d; 123 144 std::random_shuffle(classes_.begin(), classes_.end(),d); 145 } 146 147 void Target::set_binary(size_t i, bool b) 148 { 149 assert(i<nof_classes()); 150 binary_[i]=b; 124 151 } 125 152 … … 133 160 } 134 161 162 size_t Target::size(void) const 163 { 164 return classes_.size(); 165 } 166 135 167 const size_t Target::size(size_t cl) const 136 168 { … … 138 170 } 139 171 140 141 std::ostream& operator<<(std::ostream& s, const Target& a) 142 { 143 for (size_t j = 0; j < a.size(); ++j) { 144 s << a(j); 145 if ( (j+1)<a.size() ) 146 s << " "; 147 } 148 149 return s; 150 } 151 172 size_t Target::operator()(size_t sample) const 173 { 174 assert(sample<size()); 175 return classes_[sample]; 176 } 177 178 size_t Target::operator[](size_t sample) const 179 { 180 return this->operator()(sample); 181 } 152 182 153 183 const Target& Target::operator=(const Target& other) … … 161 191 162 192 193 std::ostream& operator<<(std::ostream& s, const Target& a) 194 { 195 for (size_t j = 0; j < a.size(); ++j) { 196 s << a(j); 197 if ( (j+1)<a.size() ) 198 s << " "; 199 } 200 201 return s; 202 } 203 204 163 205 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/Target.h
r706 r714 80 80 /// @return a map with label as key and class as value. 81 81 /// 82 inline const std::map<std::string,size_t>& classes(void) const 83 { return class_map_; } 82 const std::map<std::string,size_t>& classes(void) const; 84 83 85 84 /// … … 88 87 /// @return number of classes 89 88 /// 90 inline const size_t nof_classes(void) const { return classes().size(); }89 const size_t nof_classes(void) const; 91 90 92 91 /// … … 98 97 /// @see set_binary 99 98 /// 100 inline bool binary(const size_t i) const { return binary_[operator()(i)]; }99 bool binary(size_t i) const; 101 100 102 101 /// 103 102 /// @return vector of labels for classes 104 103 /// 105 inline const std::vector<std::string>& labels() { return labels_; }104 const std::vector<std::string>& labels(void); 106 105 107 106 /// … … 110 109 /// 0 which is set to true. 111 110 /// 112 inline void set_binary(const size_t i, const bool b) { binary_[i]=b; }111 void set_binary(size_t i, bool b); 113 112 114 113 /// … … 123 122 /// @return number of samples 124 123 /// 125 inline size_t size(void) const { return classes_.size(); }124 size_t size(void) const; 126 125 127 126 /// … … 139 138 /// @return the class of @a sample 140 139 /// 141 inline size_t operator()(const size_t sample) const 142 { return classes_[sample]; } 140 size_t operator()(size_t sample) const; 143 141 144 142 /// 145 143 /// @return the class of @a sample 146 144 /// 147 inline size_t operator[](const size_t sample) const 148 { return this->operator()(sample); } 145 size_t operator[](size_t sample) const; 149 146 150 147 ///
Note: See TracChangeset
for help on using the changeset viewer.