Changeset 722


Ignore:
Timestamp:
Dec 27, 2006, 9:49:11 PM (15 years ago)
Author:
Markus Ringnér
Message:

Closes #129

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/ensemble_test.cc

    r704 r722  
    8484  classifier::SubsetGenerator cv(sampler,kernel_lookup);
    8585  *error << "create ensemble" << std::endl;
    86   classifier::EnsembleBuilder ensemble(svm,cv);
     86  classifier::EnsembleBuilder ensemble(svm,sampler);
    8787  *error << "build ensemble" << std::endl;
    8888  ensemble.build();
  • trunk/test/subset_generator_test.cc

    r680 r722  
    9090  //  classifier::EnsembleBuilder ensemble_ncc(ncc,subset_data);
    9191  //ensemble_ncc.build();
    92   classifier::EnsembleBuilder ensemble_svm(svm,subset_kernel);
     92  classifier::EnsembleBuilder ensemble_svm(svm,sampler);
    9393  ensemble_svm.build();
    9494 
  • trunk/yat/classifier/EnsembleBuilder.cc

    r720 r722  
    2525#include "DataLookup2D.h"
    2626#include "KernelLookup.h"
     27#include "Sampler.h"
    2728#include "SubsetGenerator.h"
    2829#include "SupervisedClassifier.h"
     
    3536
    3637  EnsembleBuilder::EnsembleBuilder(const SupervisedClassifier& sc,
    37                                    SubsetGenerator& subset)
    38     : mother_(sc), subset_(subset)
     38                                   const Sampler& sampler)
     39    : mother_(sc),subset_(new SubsetGenerator(sampler,sc.data()))
    3940  {
    4041  }
     
    4445    for(size_t i=0; i<classifier_.size(); i++)
    4546      delete classifier_[i];
     47    delete subset_;
    4648  }
    4749
    4850  void EnsembleBuilder::build(void)
    4951  {
    50     for(u_long i=0; i<subset_.size();++i) {
     52    for(u_long i=0; i<subset_->size();++i) {
    5153      SupervisedClassifier* classifier=
    52         mother_.make_classifier(subset_.training_data(i),
    53                                 subset_.training_target(i));
     54        mother_.make_classifier(subset_->training_data(i),
     55                                subset_->training_target(i));
    5456      classifier->train();
    5557      classifier_.push_back(classifier);
     
    7577  {
    7678    result.clear();
    77     result.reserve(subset_.target().nof_classes());   
    78     for(size_t i=0; i<subset_.target().nof_classes();i++)
     79    result.reserve(subset_->target().nof_classes());   
     80    for(size_t i=0; i<subset_->target().nof_classes();i++)
    7981      result.push_back(std::vector<statistics::Averager>(data.columns()));
    8082   
     
    8284    try {
    8385      const KernelLookup& kernel = dynamic_cast<const KernelLookup&>(data);
    84       for(u_long k=0;k<subset_.size();k++) {
    85         KernelLookup kernel_peter(kernel,subset_.training_index(k),true);
     86      for(u_long k=0;k<subset_->size();k++) {
     87        KernelLookup kernel_peter(kernel,subset_->training_index(k),true);
    8688        classifier(k).predict(kernel_peter,prediction);
    8789
     
    9294    }
    9395    catch (std::bad_cast) {
    94       for(u_long k=0;k<subset_.size();k++) {
     96      for(u_long k=0;k<subset_->size();k++) {
    9597        classifier(k).predict(data,prediction);
    9698        for(size_t i=0; i<prediction.rows();i++)
     
    108110    validation_result_.clear();
    109111
    110     validation_result_.reserve(subset_.target().nof_classes());   
    111     for(size_t i=0; i<subset_.target().nof_classes();i++)
    112       validation_result_.push_back(std::vector<statistics::Averager>(subset_.target().size()));
     112    validation_result_.reserve(subset_->target().nof_classes());   
     113    for(size_t i=0; i<subset_->target().nof_classes();i++)
     114      validation_result_.push_back(std::vector<statistics::Averager>(subset_->target().size()));
    113115   
    114116    utility::matrix prediction; 
    115     for(u_long k=0;k<subset_.size();k++) {
    116       classifier(k).predict(subset_.validation_data(k),prediction);
     117    for(u_long k=0;k<subset_->size();k++) {
     118      classifier(k).predict(subset_->validation_data(k),prediction);
    117119
    118120      for(size_t i=0; i<prediction.rows();i++)
    119121        for(size_t j=0; j<prediction.columns();j++) {
    120           validation_result_[i][subset_.validation_index(k)[j]].
     122          validation_result_[i][subset_->validation_index(k)[j]].
    121123            add(prediction(i,j));
    122124        }           
  • trunk/yat/classifier/EnsembleBuilder.h

    r720 r722  
    3333namespace classifier { 
    3434
     35  class Sampler;
    3536  class SubsetGenerator;
    3637  class DataLookup2D;
     
    4849    /// Constructor.
    4950    ///
    50     EnsembleBuilder(const SupervisedClassifier&, SubsetGenerator&);
     51    EnsembleBuilder(const SupervisedClassifier&, const Sampler&);
    5152
    5253    ///
     
    9091
    9192  private:
    92  
     93    EnsembleBuilder(const EnsembleBuilder&);
     94    const EnsembleBuilder& operator=(const EnsembleBuilder&);
     95   
     96
    9397    const SupervisedClassifier& mother_;
    94     SubsetGenerator& subset_;
     98    SubsetGenerator* subset_;
    9599    std::vector<SupervisedClassifier*> classifier_;
    96100    std::vector<std::vector<statistics::Averager> > validation_result_;
  • trunk/yat/classifier/NBC.cc

    r680 r722  
    5151
    5252
     53    const DataLookup2D& NBC::data(void) const
     54    {
     55    return data_;
     56    }
     57
     58
    5359  SupervisedClassifier*
    5460  NBC::make_classifier(const DataLookup2D& data, const Target& target) const
  • trunk/yat/classifier/NBC.h

    r680 r722  
    6060    virtual ~NBC();
    6161
     62    const DataLookup2D& data(void) const;
     63
     64
    6265    SupervisedClassifier* make_classifier(const DataLookup2D&,
    6366                                          const Target&) const;
  • trunk/yat/classifier/NCC.cc

    r720 r722  
    6464  }
    6565
     66    const DataLookup2D& NCC::data(void) const
     67    {
     68    return data_;
     69    }
    6670
    6771  SupervisedClassifier*
  • trunk/yat/classifier/NCC.h

    r720 r722  
    7777    const utility::matrix& centroids(void) const;
    7878
     79    const DataLookup2D& data(void) const;
     80
    7981    SupervisedClassifier* make_classifier(const DataLookup2D&,
    8082                                          const Target&) const;
     
    98100    utility::matrix centroids_;
    99101    const statistics::Distance& distance_;                 
     102
     103    // data_ has to be of type DataLookup2D to accomodate both
     104    // MatrixLookup and MatrixLookupWeighted
    100105    const DataLookup2D& data_;
    101106
  • trunk/yat/classifier/SVM.cc

    r720 r722  
    9898  }
    9999
     100  const DataLookup2D& SVM::data(void) const
     101  {
     102    return *kernel_;
     103  }
     104
     105
    100106  double SVM::kernel_mod(const size_t i, const size_t j) const
    101107  {
  • trunk/yat/classifier/SVM.h

    r720 r722  
    6666    ///
    6767    virtual ~SVM();
     68
     69    const DataLookup2D& data(void) const;
    6870
    6971    ///
  • trunk/yat/classifier/SupervisedClassifier.h

    r680 r722  
    5959
    6060    ///
     61    /// @brief Access to the training data
     62    ///
     63    virtual const DataLookup2D& data(void) const =0;
     64
     65
     66    ///
    6167    /// An interface for making new classifier objects. This function
    6268    /// allows for specification at run-time of which classifier to
     
    7076   
    7177
     78
     79    ///
     80    /// Generate output values for a data set
     81    ///
     82    virtual void predict(const DataLookup2D&, utility::matrix&) const =0;   
     83
     84
    7285    ///
    7386    /// Train the classifier.
    7487    ///
    7588    virtual bool train()=0;
    76 
    77     ///
    78     /// Generate output values for a data set
    79     ///
    80     virtual void predict(const DataLookup2D&, utility::matrix&) const =0;   
    8189
    8290   
Note: See TracChangeset for help on using the changeset viewer.