Changeset 636


Ignore:
Timestamp:
Sep 6, 2006, 3:51:13 AM (15 years ago)
Author:
Peter
Message:

closes #120 removed weights from SubsetGenerator?

Location:
trunk/c++_tools/classifier
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/classifier/SubsetGenerator.cc

    r632 r636  
    2626
    2727    training_data_.reserve(sampler_.size());
    28     training_weight_.reserve(sampler_.size());
    2928    validation_data_.reserve(sampler_.size());
    30     validation_weight_.reserve(sampler_.size());
    3129    for (size_t i=0; i<sampler_.size(); ++i){
    3230      // Dynamically allocated. Must be deleted in destructor.
    3331      training_data_.push_back(data.training_data(sampler.training_index(i)));
    34       training_weight_.push_back
    35         (new MatrixLookup(training_data_.back()->rows(),
    36                           training_data_.back()->columns(),1));
    3732      validation_data_.push_back(data.validation_data(sampler.training_index(i),
    3833                                                      sampler.validation_index(i)));
    39       validation_weight_.push_back
    40         (new MatrixLookup(validation_data_.back()->rows(),
    41                           validation_data_.back()->columns(),1));
    4234
    4335      training_target_.push_back(Target(target(),sampler.training_index(i)));
     
    4537                                          sampler.validation_index(i)));
    4638      assert(training_data_.size()==i+1);
    47       assert(training_weight_.size()==i+1);
    4839      assert(training_target_.size()==i+1);
    4940      assert(validation_data_.size()==i+1);
    50       assert(validation_weight_.size()==i+1);
    5141      assert(validation_target_.size()==i+1);
    5242    }
     
    6050
    6151    assert(training_data_.size()==size());
    62     assert(training_weight_.size()==size());
    6352    assert(training_target_.size()==size());
    6453    assert(validation_data_.size()==size());
    65     assert(validation_weight_.size()==size());
    6654    assert(validation_target_.size()==size());
    67   }
    68 
    69   SubsetGenerator::SubsetGenerator(const Sampler& sampler,
    70                                    const DataLookup2D& data,
    71                                    const MatrixLookup& weight)
    72     : f_selector_(NULL),sampler_(sampler), state_(0), weighted_(true)
    73   {
    74     assert(target().size()==data.columns());
    75     training_data_.reserve(size());
    76     training_weight_.reserve(size());
    77     validation_data_.reserve(size());
    78     validation_weight_.reserve(size());
    79     for (reset(); more(); next()){
    80      
    81       // Dynamically allocated. Must be deleted in destructor.
    82       training_data_.push_back(data.training_data(training_index()));
    83       validation_data_.push_back(data.validation_data(training_index(),
    84                                                     validation_index()));
    85       training_weight_.push_back(weight.training_data(training_index()));
    86       validation_weight_.push_back(weight.validation_data(training_index(),
    87                                                           validation_index()));
    88 
    89 
    90       training_target_.push_back(Target(target(),training_index()));
    91       validation_target_.push_back(Target(target(),validation_index()));
    92     }
    93     // No feature selection, hence features same for all partitions
    94     // and can be stored in features_[0]
    95     features_.resize(1);
    96     features_[0].reserve(data.rows());
    97     for (size_t i=0; i<data.rows(); ++i)
    98       features_[0].push_back(i);
    99 
    100     assert(training_data_.size()==size());
    101     assert(training_weight_.size()==size());
    102     assert(training_target_.size()==size());
    103     assert(validation_data_.size()==size());
    104     assert(validation_weight_.size()==size());
    105     assert(validation_target_.size()==size());
    106     reset();
    10755  }
    10856
     
    11765    features_.reserve(size());
    11866    training_data_.reserve(size());
    119     training_weight_.reserve(size());
    12067    validation_data_.reserve(size());
    121     validation_weight_.reserve(size());
    122 
    12368
    12469    // Taking care of three different case.
     
    14085        training_data_.push_back(ml->training_data(features_.back(),
    14186                                                    training_index()));
    142         training_weight_.push_back
    143           (new MatrixLookup(training_data_.back()->rows(),
    144                             training_data_.back()->columns(),1));
    14587        validation_data_.push_back(ml->validation_data(features_.back(),
    14688                                                        training_index(),
    14789                                                        validation_index()));
    148         validation_weight_.push_back
    149           (new MatrixLookup(validation_data_.back()->rows(),
    150                             validation_data_.back()->columns(),1));
    151        
    15290
    15391        training_target_.push_back(Target(target(),training_index()));
     
    174112          training_data_.push_back(ml->training_data(features_.back(),
    175113                                                     training_index()));
    176           training_weight_.push_back
    177             (new MatrixLookup(training_data_.back()->rows(),
    178                               training_data_.back()->columns(),1));
    179114          validation_data_.push_back(ml->validation_data(features_.back(),
    180115                                                         training_index(),
    181116                                                         validation_index()));
    182           validation_weight_.push_back
    183             (new MatrixLookup(validation_data_.back()->rows(),
    184                               validation_data_.back()->columns(),1));
    185          
    186117         
    187118          training_target_.push_back(Target(target(),training_index()));
     
    225156            training_data_.push_back(kl->training_data(features_.back(),
    226157                                                       training_index()));
    227             training_weight_.push_back
    228               (new MatrixLookup(training_data_.back()->rows(),
    229                                 training_data_.back()->columns(),1));
    230158            validation_data_.push_back(kl->validation_data(features_.back(),
    231159                                                           training_index(),
    232160                                                           validation_index()));
    233             validation_weight_.push_back
    234               (new MatrixLookup(validation_data_.back()->rows(),
    235                                 validation_data_.back()->columns(),1));
    236            
    237161           
    238162            training_target_.push_back(Target(target(),training_index()));
     
    250174    }
    251175    assert(training_data_.size()==size());
    252     assert(training_weight_.size()==size());
    253176    assert(training_target_.size()==size());
    254177    assert(validation_data_.size()==size());
    255     assert(validation_weight_.size()==size());
    256178    assert(validation_target_.size()==size());
    257179    reset();
     
    266188    for (size_t i=0; i<validation_data_.size(); i++)
    267189      delete validation_data_[i];
    268     for (size_t i=0; i<training_weight_.size(); i++)
    269       delete training_weight_[i];
    270     for (size_t i=0; i<validation_weight_.size(); i++)
    271       delete validation_weight_[i];
    272190  }
    273191
  • trunk/c++_tools/classifier/SubsetGenerator.h

    r632 r636  
    5151    ///
    5252    SubsetGenerator(const Sampler& sampler, const DataLookup2D& data);
    53 
    54 
    55     ///
    56     /// @brief Constructor with weights
    57     /// 
    58     /// @parameter data data to split up in validation and training.
    59     /// @parameter weights accompanying data.
    60     ///
    61     /// @todo This most likely be removed.
    62     SubsetGenerator(const Sampler& sampler, const DataLookup2D& data,
    63                     const MatrixLookup& weight);
    6453
    6554
     
    136125
    137126    ///
    138     /// @return training data weight
    139     /// @todo remove this function
    140     inline const MatrixLookup& training_weight(void) const
    141     { return *(training_weight_[state_]); }
    142 
    143     ///
    144127    /// @return validation data
    145128    ///
     
    160143
    161144    ///
    162     /// @return validation data weights
    163     /// @todo remove this function
    164     inline const MatrixLookup& validation_weight(void) const
    165     { return *(validation_weight_[state_]); }
    166 
    167     ///
    168145    /// @return true if weighted
    169146    /// @todo remove this function
    170     inline bool weighted(void) const { return weighted_; }
     147    //inline bool weighted(void) const { return weighted_; }
    171148
    172149  private:
     
    180157    std::vector<const DataLookup2D*> training_data_;
    181158    std::vector<Target> training_target_;
    182     std::vector<const MatrixLookup*> training_weight_;
    183159    std::vector<const DataLookup2D*> validation_data_;
    184160    std::vector<Target> validation_target_;
    185     std::vector<const MatrixLookup*> validation_weight_;
    186161    const bool weighted_;
    187162
Note: See TracChangeset for help on using the changeset viewer.