Changeset 1954 for trunk/yat/classifier/EnsembleBuilder.h
 Timestamp:
 May 7, 2009, 5:30:58 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/EnsembleBuilder.h
r1487 r1954 9 9 Copyright (C) 2007 Jari Häkkinen, Peter Johansson 10 10 Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér 11 Copyright (C) 2009 Jari Häkkinen 11 12 12 13 This file is part of the yat library, http://dev.thep.lu.se/yat … … 128 129 // implementation 129 130 130 template <class C, class D> 131 EnsembleBuilder<C,D>::EnsembleBuilder(const C& sc, const D& data, 132 const Sampler& sampler) 133 : mother_(sc),subset_(new SubsetGenerator<D>(sampler,data)) 134 { 135 } 136 137 138 template <class C, class D> 139 EnsembleBuilder<C, D>::EnsembleBuilder(const C& sc, const D& data, 140 const Sampler& sampler, 141 FeatureSelector& fs) 131 template <class Classifier, class Data> 132 EnsembleBuilder<Classifier, Data>::EnsembleBuilder(const Classifier& sc, 133 const Data& data, 134 const Sampler& sampler) 135 : mother_(sc),subset_(new SubsetGenerator<Data>(sampler,data)) 136 { 137 } 138 139 140 template <class Classifier, class Data> 141 EnsembleBuilder<Classifier, Data>::EnsembleBuilder(const Classifier& sc, 142 const Data& data, 143 const Sampler& sampler, 144 FeatureSelector& fs) 142 145 : mother_(sc), 143 subset_(new SubsetGenerator<D >(sampler,data,fs))144 { 145 } 146 147 148 template <class C , class D>149 EnsembleBuilder<C , D>::~EnsembleBuilder(void)146 subset_(new SubsetGenerator<Data>(sampler,data,fs)) 147 { 148 } 149 150 151 template <class Classifier, class Data> 152 EnsembleBuilder<Classifier, Data>::~EnsembleBuilder(void) 150 153 { 151 154 for(size_t i=0; i<classifier_.size(); i++) … … 155 158 156 159 157 template <class C , class D>158 void EnsembleBuilder<C , D>::build(void)160 template <class Classifier, class Data> 161 void EnsembleBuilder<Classifier, Data>::build(void) 159 162 { 160 163 if (classifier_.empty()){ 161 164 for(unsigned long i=0; i<subset_>size();++i) { 162 C * classifier = mother_.make_classifier();165 Classifier* classifier = mother_.make_classifier(); 163 166 classifier>train(subset_>training_data(i), 164 167 subset_>training_target(i)); … … 169 172 170 173 171 template <class C , class D>172 const C & EnsembleBuilder<C, D>::classifier(size_t i) const174 template <class Classifier, class Data> 175 const Classifier& EnsembleBuilder<Classifier, Data>::classifier(size_t i) const 173 176 { 174 177 return *(classifier_[i]); … … 176 179 177 180 178 template <class C , class D>179 void EnsembleBuilder<C , D>::predict180 (const D & data, std::vector<std::vector<statistics::Averager> >& result)181 template <class Classifier, class Data> 182 void EnsembleBuilder<Classifier, Data>::predict 183 (const Data& data, std::vector<std::vector<statistics::Averager> >& result) 181 184 { 182 185 result = std::vector<std::vector<statistics::Averager> > … … 187 190 188 191 for(unsigned long k=0;k<size();++k) { 189 D sub_data =test_data(data, k);192 Data sub_data = test_data(data, k); 190 193 classifier(k).predict(sub_data,prediction); 191 194 } … … 197 200 198 201 199 template <class C , class D>200 unsigned long EnsembleBuilder<C , D>::size(void) const202 template <class Classifier, class Data> 203 unsigned long EnsembleBuilder<Classifier, Data>::size(void) const 201 204 { 202 205 return classifier_.size(); … … 204 207 205 208 206 template <class C, class D> 207 MatrixLookup EnsembleBuilder<C, D>::test_data(const MatrixLookup& data, 209 template <class Classifier, class Data> 210 MatrixLookup EnsembleBuilder<Classifier, 211 Data>::test_data(const MatrixLookup& data, 208 212 size_t k) 209 213 { … … 212 216 213 217 214 template <class C , class D>218 template <class Classifier, class Data> 215 219 MatrixLookupWeighted 216 EnsembleBuilder<C, D>::test_data(const MatrixLookupWeighted& data, size_t k) 220 EnsembleBuilder<Classifier, Data>::test_data(const MatrixLookupWeighted& data, 221 size_t k) 217 222 { 218 223 return MatrixLookupWeighted(data, subset_>training_features(k), true); … … 220 225 221 226 222 template <class C , class D>227 template <class Classifier, class Data> 223 228 KernelLookup 224 EnsembleBuilder<C, D>::test_data(const KernelLookup& kernel, size_t k) 229 EnsembleBuilder<Classifier, Data>::test_data(const KernelLookup& kernel, 230 size_t k) 225 231 { 226 232 // weighted case … … 245 251 246 252 247 template <class C , class D>253 template <class Classifier, class Data> 248 254 const std::vector<std::vector<statistics::Averager> >& 249 EnsembleBuilder<C , D>::validate(void)255 EnsembleBuilder<Classifier, Data>::validate(void) 250 256 { 251 257 // Don't recalculate validation_result_
Note: See TracChangeset
for help on using the changeset viewer.