Changeset 540


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

added weights in CrossSplitter? - not supported in interface though.

Location:
trunk/lib/classifier
Files:
2 edited

Legend:

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

    r517 r540  
    2121    assert(target.size()>1);
    2222    assert(target.size()==data.columns());
     23
     24    build(target, N, k);
     25
     26    for (size_t i=0; i<N; i++){
     27     
     28      // Dynamically allocated. Must be deleted in destructor.
     29      training_data_.push_back(data.training_data(training_index_[i]));
     30      validation_data_.push_back(data.validation_data(training_index_[i],
     31                                                    validation_index_[i]));
     32      training_weight_.push_back(new MatrixLookup(0,1));
     33      validation_weight_.push_back(new MatrixLookup(0,1));
     34
     35
     36      training_target_.push_back(Target(target,training_index_[i]));
     37      validation_target_.push_back(Target(target,validation_index_[i]));
     38    }
     39    assert(training_data_.size()==N);
     40    assert(training_weight_.size()==N);
     41    assert(training_target_.size()==N);
     42    assert(validation_data_.size()==N);
     43    assert(validation_weight_.size()==N);
     44    assert(validation_target_.size()==N);
     45  }
     46
     47  CrossSplitter::~CrossSplitter()
     48  {
     49    assert(training_data_.size()==validation_data_.size());
     50    for (size_t i=0; i<training_data_.size(); i++)
     51      delete training_data_[i];
     52    for (size_t i=0; i<validation_data_.size(); i++)
     53      delete validation_data_[i];
     54  }
     55
     56  void CrossSplitter::build(const Target& target, size_t N, size_t k)
     57  {
    2358    std::vector<std::pair<size_t,size_t> > v;
    2459    for (size_t i=0; i<target.size(); i++)
     
    5388        }
    5489
    55         // Dynamically allocated. Must be deleted in destructor.
    56         training_data_.push_back(data.training_data(training_index));
    57         validation_data_.push_back(data.validation_data(training_index,
    58                                                         validation_index));
    59 
    60         training_target_.push_back(Target(target,training_index));
    61         validation_target_.push_back(Target(target,validation_index));
    6290        training_index_.push_back(training_index);
    6391        validation_index_.push_back(validation_index);
    64 
    6592      }
    6693    }
    67     assert(training_data_.size()==N);
    68     assert(training_target_.size()==N);
    6994    assert(training_index_.size()==N);
    70     assert(validation_data_.size()==N);
    71     assert(validation_target_.size()==N);
    7295    assert(validation_index_.size()==N);
    73   }
    74 
    75   CrossSplitter::~CrossSplitter()
    76   {
    77     assert(training_data_.size()==validation_data_.size());
    78     for (size_t i=0; i<training_data_.size(); i++)
    79       delete training_data_[i];
    80     for (size_t i=0; i<validation_data_.size(); i++)
    81       delete validation_data_[i];
    82   }
     96}
    8397
    8498}} // of namespace classifier and namespace theplu
  • trunk/lib/classifier/CrossSplitter.h

    r515 r540  
    55
    66#include <c++_tools/classifier/Target.h>
     7#include <c++_tools/classifier/MatrixLookup.h>
    78
    89
     
    3839    ///
    3940    CrossSplitter(const Target& target, const DataLookup2D& data,
     41                  const size_t N, const size_t k);
     42
     43    ///
     44    /// @brief Constructor with weights
     45    /// 
     46    /// @parameter Target targets
     47    /// @parameter data data to split up in validation and training.
     48    /// @parameter weights accompanying data.
     49    /// @parameter N total number of partitions
     50    /// @parameter k for k-fold crossvalidation
     51    ///
     52    CrossSplitter(const Target& target, const DataLookup2D& data,
     53                  const DataLookup2D& weights,
    4054                  const size_t N, const size_t k);
    4155
     
    121135
    122136  private:
     137    void build(const Target& target, size_t N, size_t k);
     138
    123139    const size_t k_;
    124140    u_long state_;
     
    126142   
    127143    std::vector<const DataLookup2D*> training_data_;
     144    std::vector<const MatrixLookup*> training_weight_;
    128145    std::vector<std::vector<size_t> > training_index_;
    129146    std::vector<Target> training_target_;
    130147
    131148    std::vector<const DataLookup2D*> validation_data_;
     149    std::vector<const MatrixLookup*> validation_weight_;
    132150    std::vector<std::vector<size_t> > validation_index_;
    133151    std::vector<Target> validation_target_;
Note: See TracChangeset for help on using the changeset viewer.