1 #ifndef _theplu_yat_classifier_subset_generator_
2 #define _theplu_yat_classifier_subset_generator_
27 #include "FeatureSelector.h"
28 #include "KernelLookup.h"
29 #include "MatrixLookup.h"
30 #include "MatrixLookupWeighted.h"
33 #include "yat/utility/Index.h"
34 #include "yat/utility/yat_assert.h"
43 namespace classifier {
56 template <
typename Data>
142 size_t size(
void)
const;
202 std::vector<utility::Index > features_;
204 std::vector<const Data*> training_data_;
205 std::vector<Target> training_target_;
206 std::vector<const Data*> validation_data_;
207 std::vector<Target> validation_target_;
214 template<
typename Data>
217 : f_selector_(NULL), sampler_(sampler)
221 training_data_.reserve(sampler_.
size());
222 validation_data_.reserve(sampler_.
size());
224 YAT_ASSERT(training_data_.size()==
size());
225 YAT_ASSERT(training_target_.size()==
size());
226 YAT_ASSERT(validation_data_.size()==
size());
227 YAT_ASSERT(validation_target_.size()==
size());
231 template<
typename Data>
235 : f_selector_(&fs), sampler_(sampler)
238 features_.reserve(
size());
239 training_data_.reserve(
size());
240 validation_data_.reserve(
size());
242 YAT_ASSERT(training_data_.size()==
size());
243 YAT_ASSERT(training_target_.size()==
size());
244 YAT_ASSERT(validation_data_.size()==
size());
245 YAT_ASSERT(validation_target_.size()==
size());
249 template<
typename Data>
252 YAT_ASSERT(training_data_.size()==validation_data_.size());
253 for (
size_t i=0; i<training_data_.size(); i++)
254 delete training_data_[i];
255 for (
size_t i=0; i<validation_data_.size(); i++)
256 delete validation_data_[i];
260 template<
typename Data>
266 for (
size_t k=0; k<size(); k++){
267 training_target_.push_back(
Target(target(),training_index(k)));
268 validation_target_.push_back(
Target(target(),validation_index(k)));
274 YAT_ASSERT(train_data_all_feat);
275 f_selector_->update(*train_data_all_feat, training_target(k));
277 features_.push_back(f_selector_->features());
278 YAT_ASSERT(train_data_all_feat);
279 delete train_data_all_feat;
283 training_data_.push_back(
new MatrixLookup(ml,features_.back(),
285 validation_data_.push_back(
new MatrixLookup(ml,features_.back(),
286 validation_index(k)));
292 template<
typename Data>
293 void SubsetGenerator<Data>::build(
const MatrixLookupWeighted& ml)
296 features_.push_back(utility::Index(ml.rows()));
298 for (
unsigned long k=0; k<size(); k++){
299 training_target_.push_back(Target(target(),training_index(k)));
300 validation_target_.push_back(Target(target(),validation_index(k)));
303 const MatrixLookupWeighted* train_data_all_feat =
304 new MatrixLookupWeighted(ml, utility::Index(ml.rows()),
307 f_selector_->update(*train_data_all_feat, training_target(k));
309 features_.push_back(f_selector_->features());
310 delete train_data_all_feat;
315 training_data_.push_back(
new MatrixLookupWeighted(ml, features_.back(),
317 validation_data_.push_back(
new MatrixLookupWeighted(ml, features_.back(),
318 validation_index(k)));
322 template<
typename Data>
323 void SubsetGenerator<Data>::build(
const KernelLookup& kernel)
325 for (
unsigned long k=0; k<size(); k++){
326 training_target_.push_back(Target(target(),training_index(k)));
327 validation_target_.push_back(Target(target(),validation_index(k)));
330 if (kernel.weighted()){
331 MatrixLookupWeighted ml = kernel.data_weighted();
332 f_selector_->update(MatrixLookupWeighted(ml,
333 utility::Index(ml.rows()),
338 MatrixLookup ml=kernel.data();
339 f_selector_->update(MatrixLookup(ml,training_index(k),
false),
342 features_.push_back(f_selector_->features());
343 KernelLookup kl = kernel.selected(features_.back());
345 training_data_.push_back(
new KernelLookup(kl,training_index(k),
347 validation_data_.push_back(
new KernelLookup(kl, training_index(k),
348 validation_index(k)));
351 training_data_.push_back(
new KernelLookup(kernel, training_index(k),
353 validation_data_.push_back(
new KernelLookup(kernel,
355 validation_index(k)));
360 if (kernel.weighted())
361 features_.push_back(utility::Index(kernel.data_weighted().rows()));
363 features_.push_back(utility::Index(kernel.data().rows()));
368 template<
typename Data>
371 return sampler_.size();
375 template<
typename Data>
378 return sampler_.target();
382 template<
typename Data>
386 return *(training_data_[i]);
390 template<
typename Data>
394 YAT_ASSERT(features_.size());
395 return f_selector_ ? features_[i] : features_[0];
399 template<
typename Data>
403 return sampler_.training_index(i);
407 template<
typename Data>
411 return training_target_[i];
415 template<
typename Data>
419 return *(validation_data_[i]);
423 template<
typename Data>
427 return sampler_.validation_index(i);
431 template<
typename Data>
435 return validation_target_[i];
General view into utility::Matrix.
Definition: MatrixLookup.h:70
const utility::Index & training_index(size_t i) const
Definition: SubsetGenerator.h:401
const utility::Index & training_features(size_t i) const
Definition: SubsetGenerator.h:392
Class for containing sample labels.
Definition: Target.h:47
const Data & training_data(size_t i) const
Definition: SubsetGenerator.h:384
Data value_type
Definition: SubsetGenerator.h:63
const Target & target(void) const
Definition: SubsetGenerator.h:376
Interface class for FeatureSelection.
Definition: FeatureSelector.h:39
size_t size(void) const
Definition: SubsetGenerator.h:369
Class splitting Data into training and validation set.
Definition: SubsetGenerator.h:57
const Data & validation_data(size_t i) const
Definition: SubsetGenerator.h:417
~SubsetGenerator()
Definition: SubsetGenerator.h:250
Class for storing indices of, e.g., a MatrixLookup.
Definition: Index.h:41
General view into utility::MatrixWeighted.
Definition: MatrixLookupWeighted.h:63
Lookup into Kernel.
Definition: KernelLookup.h:67
SubsetGenerator(const Sampler &sampler, const Data &data)
Create SubDataSets.
Definition: SubsetGenerator.h:215
Interface class for dividing samples into training and validation.
Definition: Sampler.h:39
const utility::Index & validation_index(size_t i) const
Definition: SubsetGenerator.h:425
const Target & training_target(size_t i) const
Definition: SubsetGenerator.h:409
const Target & validation_target(size_t i) const
Definition: SubsetGenerator.h:433