Changeset 485


Ignore:
Timestamp:
Jan 4, 2006, 5:17:43 PM (16 years ago)
Author:
Markus Ringnér
Message:

First draft of EnsembleBuilder?

Location:
trunk/lib/classifier
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/classifier/ConsensusInputRanker.cc

    r482 r485  
    2626    assert(sampler.size());
    2727    size_t nof_inputs = sampler.training_data().rows();
    28     while (sampler.end()){
     28    while (sampler.more()){
    2929      // Peter, should support weights also (in sampler???)
    3030      input_rankers_.push_back(InputRanker(sampler.training_data(),
  • trunk/lib/classifier/CrossSplitter.h

    r482 r485  
    4242
    4343    ///
    44     /// @return true if valid state
     44    /// @return true if in a valid state
    4545    ///
    46     inline bool end(void) const { return state_<size(); }
     46    inline bool more(void) const { return state_<size(); }
    4747
    4848    ///
    4949    /// Function turning the object to the next state.
    50     ///
    51     /// @return false if there are no more state.
    5250    ///
    5351    inline void next(void) { state_++; }
     
    6967    ///
    7068    inline const DataLookup2D& training_data(void) const
    71     { assert(end()); return *(training_data_[state_]); }
     69    { assert(more()); return *(training_data_[state_]); }
    7270
    7371    ///
     
    7775    ///
    7876    inline const Target& training_target(void) const
    79     { assert(end()); return training_target_[state_]; }
     77    { assert(more()); return training_target_[state_]; }
    8078
    8179    ///
     
    8583    ///
    8684    inline const DataLookup2D& validation_data(void) const
    87     { assert(end()); return *(validation_data_[state_]); }
     85    { assert(more()); return *(validation_data_[state_]); }
    8886
    8987    ///
    90     /// @return training target
     88    /// @return validation target
    9189    ///
    9290    /// @note if state is invalid the result is undefined
    9391    ///
    9492    inline const Target& validation_target(void) const
    95     { assert(end()); return validation_target_[state_]; }
     93    { assert(more()); return validation_target_[state_]; }
    9694
    9795  private:
  • trunk/lib/classifier/EnsembleBuilder.cc

    r481 r485  
    33#include <c++_tools/classifier/EnsembleBuilder.h>
    44
     5#include <c++_tools/classifier/CrossSplitter.h>
    56#include <c++_tools/classifier/DataLookup2D.h>
    67#include <c++_tools/classifier/SupervisedClassifier.h>
     
    1112
    1213  EnsembleBuilder::EnsembleBuilder(const SupervisedClassifier& sc,
    13                                    const CrossSplitter& cs)
     14                                   CrossSplitter& cs)
    1415    : mother_(sc), cross_splitter_(cs)
    1516  {
    1617  }
    1718
    18   EnsembleBuilder::~EnsembleBuilder()
     19  EnsembleBuilder::~EnsembleBuilder(void)
    1920  {
    20     // If we do not delete things in build, we have to loop over
    21     // vectors and delete the appropriate things here.
     21    for(size_t i=0; i<classifier_.size(); i++)
     22      delete classifier_[i];
    2223  }
    2324
    2425  void EnsembleBuilder::build(void)
    2526  {
    26     while(cross_splitter_.next()) {
    27       const DataLookup2D* training=cross_splitter_.training_set();
    28       const Target* targets=cross_splitter_.targets();
    29       const SupervisedClassifier* classifier=
    30         mother_.make_classifier(*training,*targets);
    31       classifier.train();
    32       classifier_.push_back(*classifier);
    33 
    34       const DataLookup2D* validation=cross_splitter_.validation_set();
    35       validation_set.push_back(*validation);
    36 
    37       // What can we delete here?  At some point we have to delete all
    38       // classifiers, training sets, validation sets, and targets
    39       // because they are dynamically allocated by CrossSplitter and
    40       // SupervisedClassifier. Also remember 'Effective STL' about
    41       // vectors of pointers (no good), so if we are making copies of
    42       // things we put into the vectors we can perhaps delete most
    43       // things here, but: 1) Do we want to make copies (slow) ? 2)
    44       // Will the copies be properly made (proper functionality
    45       // throughout all classes) ? Three alternatives: 1) we should
    46       // not use STL containers here, 2) Let things be copied into the
    47       // STL containers, 3) Adapt the code to use stl vectors of
    48       // (smart) pointers.
     27    while(cross_splitter_.more()) {
     28      const DataLookup2D& training=cross_splitter_.training_data();
     29      const Target& targets=cross_splitter_.training_target();
     30      SupervisedClassifier* classifier=
     31        mother_.make_classifier(training,targets);
     32      classifier->train();
     33      classifier_.push_back(classifier);
    4934    }   
    5035  }
  • trunk/lib/classifier/EnsembleBuilder.h

    r481 r485  
    55
    66
     7#include <vector>
     8
    79namespace theplu {
    810namespace classifier { 
    911
    10   class CrossSplitting;
     12  class CrossSplitter;
    1113  class DataLookup2D;
    1214  class SupervisedClassifier;
    13 
    1415
    1516  ///
     
    2728
    2829    ///
     30    /// Destructor.
     31    ///
     32    ~EnsembleBuilder();
     33
     34
     35    ///
    2936    /// Generate ensemble
    3037    ///
     
    3441 
    3542    const SupervisedClassifier& mother_;
    36     const CrossSplitter& cross_splitter_;
    37     vector<SupervisedClassifier> classifier_;
    38     vector<DataLookup2D> validation_set_
     43    CrossSplitter& cross_splitter_;
     44    std::vector<SupervisedClassifier*> classifier_;
    3945
    4046  };
  • trunk/lib/classifier/Makefile.am

    r482 r485  
    1313  DataLookup1D.cc \
    1414  DataLookup2D.cc \
     15  EnsembleBuilder.cc \
    1516  GaussianKernelFunction.cc \
    1617  InputRanker.cc \
     
    3334  CrossSplitter.h \
    3435  DataLookup2D.h \
     36  EnsembleBuilder.h \
    3537  GaussianKernelFunction.h \
    3638  InputRanker.h \
Note: See TracChangeset for help on using the changeset viewer.