Changeset 1227 for trunk/yat/classifier/EnsembleBuilder.h
 Timestamp:
 Mar 13, 2008, 3:43:41 AM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/EnsembleBuilder.h
r1221 r1227 73 73 virtual ~EnsembleBuilder(void); 74 74 75 /// 76 /// Generate ensemble. Function trains each member of the Ensemble. 77 /// 75 /** 76 \brief Generate ensemble. 77 78 Function trains each member of the Ensemble. 79 */ 78 80 void build(void); 79 81 80 82 /// 81 /// @return classifier83 /// @return ith classifier 82 84 /// 83 85 const Classifier& classifier(size_t i) const; 84 86 85 87 /// 86 /// @return Number of classifiers in ensemble 88 /// @return Number of classifiers in ensemble. Prior build(void) 89 /// is issued size is zero. 87 90 /// 88 91 u_long size(void) const; … … 156 159 void EnsembleBuilder<C, D>::build(void) 157 160 { 158 for(u_long i=0; i<subset_>size();++i) { 159 C* classifier = mother_.make_classifier(); 160 classifier>train(subset_>training_data(i), 161 subset_>training_target(i)); 162 classifier_.push_back(classifier); 163 } 161 if (classifier_.empty()){ 162 for(u_long i=0; i<subset_>size();++i) { 163 C* classifier = mother_.make_classifier(); 164 classifier>train(subset_>training_data(i), 165 subset_>training_target(i)); 166 classifier_.push_back(classifier); 167 } 168 } 164 169 } 165 170 … … 176 181 (const D& data, std::vector<std::vector<statistics::Averager> >& result) 177 182 { 178 result.clear(); 179 result.reserve(subset_>target().nof_classes()); 180 for(size_t i=0; i<subset_>target().nof_classes();i++) 181 result.push_back(std::vector<statistics::Averager>(data.columns())); 183 result = std::vector<std::vector<statistics::Averager> > 184 (subset_>target().nof_classes(), 185 std::vector<statistics::Averager>(data.columns())); 182 186 183 187 utility::Matrix prediction; 184 188 185 for(u_long k=0;k<s ubset_>size();++k) {189 for(u_long k=0;k<size();++k) { 186 190 D sub_data = test_data(data, k); 187 191 classifier(k).predict(sub_data,prediction); … … 246 250 EnsembleBuilder<C, D>::validate(void) 247 251 { 248 validation_result_.clear(); 249 250 validation_result_.reserve(subset_>target().nof_classes()); 251 for(size_t i=0; i<subset_>target().nof_classes();i++) 252 validation_result_.push_back(std::vector<statistics::Averager>(subset_>target().size())); 253 252 // Don't recalculate validation_result_ 253 if (!validation_result_.empty()) 254 return validation_result_; 255 256 validation_result_ = std::vector<std::vector<statistics::Averager> > 257 (subset_>target().nof_classes(), 258 std::vector<statistics::Averager>(subset_>target().size())); 259 254 260 utility::Matrix prediction; 255 for(u_long k=0;k<s ubset_>size();k++) {261 for(u_long k=0;k<size();k++) { 256 262 classifier(k).predict(subset_>validation_data(k),prediction); 257 263
Note: See TracChangeset
for help on using the changeset viewer.