Changeset 541


Ignore:
Timestamp:
Mar 5, 2006, 4:20:58 PM (16 years ago)
Author:
Peter
Message:

weights supported in CrossSplitter?

Location:
trunk/lib/classifier
Files:
2 edited

Legend:

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

    r540 r541  
    2828      // Dynamically allocated. Must be deleted in destructor.
    2929      training_data_.push_back(data.training_data(training_index_[i]));
     30      training_weight_.push_back
     31        (new MatrixLookup(training_data_.back()->rows(),
     32                          training_data_.back()->columns(),1));
    3033      validation_data_.push_back(data.validation_data(training_index_[i],
    3134                                                    validation_index_[i]));
    32       training_weight_.push_back(new MatrixLookup(0,1));
    33       validation_weight_.push_back(new MatrixLookup(0,1));
     35      validation_weight_.push_back
     36        (new MatrixLookup(validation_data_.back()->rows(),
     37                          validation_data_.back()->columns(),1));
     38
     39
     40      training_target_.push_back(Target(target,training_index_[i]));
     41      validation_target_.push_back(Target(target,validation_index_[i]));
     42    }
     43    assert(training_data_.size()==N);
     44    assert(training_weight_.size()==N);
     45    assert(training_target_.size()==N);
     46    assert(validation_data_.size()==N);
     47    assert(validation_weight_.size()==N);
     48    assert(validation_target_.size()==N);
     49  }
     50
     51  CrossSplitter::CrossSplitter(const Target& target, const DataLookup2D& data,
     52                               const MatrixLookup& weight,
     53                               const size_t N, const size_t k)
     54    : k_(k), state_(0), target_(target)
     55  {
     56    assert(target.size()>1);
     57    assert(target.size()==data.columns());
     58
     59    build(target, N, k);
     60
     61    for (size_t i=0; i<N; i++){
     62     
     63      // Dynamically allocated. Must be deleted in destructor.
     64      training_data_.push_back(data.training_data(training_index_[i]));
     65      validation_data_.push_back(data.validation_data(training_index_[i],
     66                                                    validation_index_[i]));
     67      training_weight_.push_back(weight.training_data(training_index_[i]));
     68      validation_weight_.push_back(weight.validation_data(training_index_[i],
     69                                                          validation_index_[i]));
    3470
    3571
     
    5288    for (size_t i=0; i<validation_data_.size(); i++)
    5389      delete validation_data_[i];
     90    for (size_t i=0; i<training_weight_.size(); i++)
     91      delete training_weight_[i];
     92    for (size_t i=0; i<validation_weight_.size(); i++)
     93      delete validation_weight_[i];
    5494  }
    5595
  • trunk/lib/classifier/CrossSplitter.h

    r540 r541  
    5151    ///
    5252    CrossSplitter(const Target& target, const DataLookup2D& data,
    53                   const DataLookup2D& weights,
     53                  const MatrixLookup& weight,
    5454                  const size_t N, const size_t k);
    5555
     
    111111
    112112    ///
     113    /// @return training data weight
     114    ///
     115    /// @note if state is invalid the result is undefined
     116    ///
     117    inline const DataLookup2D& training_weight(void) const
     118    { assert(more()); return *(training_weight_[state_]); }
     119
     120    ///
    113121    /// @return validation data
    114122    ///
     
    134142    { assert(more()); return validation_target_[state_]; }
    135143
     144    ///
     145    /// @return validation data weights
     146    ///
     147    /// @note if state is invalid the result is undefined
     148    ///
     149    inline const DataLookup2D& validation_weight(void) const
     150    { assert(more()); return *(validation_weight_[state_]); }
     151
    136152  private:
    137153    void build(const Target& target, size_t N, size_t k);
Note: See TracChangeset for help on using the changeset viewer.