Changeset 482


Ignore:
Timestamp:
Jan 2, 2006, 8:10:10 PM (16 years ago)
Author:
Peter
Message:

modified interface to CrossSplitter?, added functions to DataLookup2D
that extracts trainingdata and validation data. For the time being
weights are not supported in CrossSplitter?.

Location:
trunk
Files:
15 edited
2 moved

Legend:

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

    r475 r482  
    44#include <c++_tools/classifier/ConsensusInputRanker.h>
    55
    6 #include <c++_tools/classifier/CrossSplitting.h>
     6#include <c++_tools/classifier/CrossSplitter.h>
    77#include <c++_tools/classifier/MatrixLookup.h>
    88#include <c++_tools/classifier/InputRanker.h>
     
    1212#include <c++_tools/gslapi/matrix.h>
    1313
     14#include <cassert>
     15#include <iostream>
    1416#include <utility>
    1517#include <vector>
    16 #include <iostream>
     18
    1719
    1820namespace theplu {
     
    2022
    2123  ConsensusInputRanker::ConsensusInputRanker
    22   (const MatrixLookup& data, const Target& target,
    23    statistics::Score& score_object, CrossSplitting& sampler,
    24    const size_t n)
    25     : nof_rankers_(n)
     24  (CrossSplitter& sampler, statistics::Score& score_object)
     25  {
     26    assert(sampler.size());
     27    size_t nof_inputs = sampler.training_data().rows();
     28    while (sampler.end()){
     29      // Peter, should support weights also (in sampler???)
     30      input_rankers_.push_back(InputRanker(sampler.training_data(),
     31                                           sampler.training_target(),
     32                                           score_object));
     33      sampler.next();
     34    }
    2635
    27   {
    28     for (size_t i=0; i<nof_rankers_; i++){
    29       std::vector<size_t> index=sampler.next();
    30       input_rankers_.push_back(InputRanker(MatrixLookup(data,index),
    31                                            Target(target,index),
    32                                            score_object)  );
    33     }
     36
     37
    3438    // Sorting with respect to median rank
    35     std::vector<std::pair<double,size_t> > medians(data.rows());
    36     for (size_t i=0; i<data.rows(); i++){
    37       std::vector<size_t> ranks(nof_rankers_);
    38       for (size_t j=0; j<nof_rankers_; j++) {
     39    std::vector<std::pair<double,size_t> > medians(nof_inputs);
     40    for (size_t i=0; i<nof_inputs; i++){
     41      std::vector<size_t> ranks(sampler.size());
     42      for (size_t j=0; j<sampler.size(); j++) {
    3943        ranks[j]=input_rankers_[j].rank(i);
    4044      }
     
    4549    //sort medians and assign id_ and rank_
    4650    sort(medians.begin(), medians.end());
    47     id_.resize(data.rows());
    48     rank_.resize(data.rows());
    49     for (size_t i=0; i<data.rows(); i++){
     51    id_.resize(nof_inputs);
     52    rank_.resize(nof_inputs);
     53    for (size_t i=0; i<nof_inputs; i++){
    5054      id_[i]=medians[i].second;
    5155      rank_[id_[i]]=i;
     
    5458  }
    5559
    56   ConsensusInputRanker::ConsensusInputRanker
    57   (const MatrixLookup& data, const Target& target, const MatrixLookup& weight,
    58    statistics::Score& score_object, CrossSplitting& sampler,const size_t n)
    59     : nof_rankers_(n)
    60   {
    61     for (size_t i=0; i<nof_rankers_; i++){
    62       std::vector<size_t> index = sampler.next();
    63       input_rankers_.push_back(InputRanker(MatrixLookup(data,index),
    64                                            Target(target,index),
    65                                            score_object,
    66                                            MatrixLookup(weight,index)));
    67     }
    68    
    69     // Sorting with respect to median rank
    70     std::vector<std::pair<double, size_t> > median(data.rows());
    71     for (size_t i=0; i<data.rows(); i++){
    72       std::vector<size_t> ranks(nof_rankers_);
    73       for (size_t j=0; j<nof_rankers_; j++)
    74         ranks[j]=input_rankers_[j].rank(i);
    75       median[i].first = statistics::median(ranks);
    76       median[i].second = i;
    77     }
    78    
    79     //sort medians and assign id_ and rank_
    80     sort(median.begin(), median.end());
    81     id_.resize(data.rows());
    82     rank_.resize(data.rows());
    83     for (size_t i=0; i<data.rows(); i++){
    84       id_[i]=median[i].second;
    85       rank_[id_[i]]=i;           
    86     }
    87 
    88   }
    89    
    9060
    9161}} // of namespace classifier and namespace theplu
  • trunk/lib/classifier/ConsensusInputRanker.h

    r475 r482  
    1010namespace classifier { 
    1111
    12   class CrossSplitting;
    13   class MatrixLookup;
    14   class Target;
     12  class CrossSplitter;
    1513
    1614  ///
    17   /// Class for ranking rows in a data matrix versus a target vector
    18   /// in a cross validation manner. The rows are sorted with respect
     15  /// Class for ranking rows in a data matrix versus a target vector.
     16  /// The rows are sorted with respect
    1917  /// to median of their ranks.
    2018  ///   
     
    2422  public:
    2523    ///
    26     /// Constructor taking \a data, \a target, Score object. The
    27     /// constructor creates ranklists in a \a k fold crossvalidation
    28     /// manner, and in total there is \a n times \a k ranklists.
     24    /// Constructor
    2925    ///
    30     ConsensusInputRanker(const MatrixLookup& data,
    31                          const Target& target,
    32                          statistics::Score&,
    33                          CrossSplitting&,
    34                          const size_t n);
    35 
    36     ///
    37     /// Constructor taking \a data, \a target, \a weight and Score object. The
    38     /// constructor creates ranklists in a \a k fold crossvalidation
    39     /// manner, and in total there is \a n times \a k ranklists.
    40     ///
    41     ConsensusInputRanker(const MatrixLookup& data,
    42                          const Target& target,
    43                          const MatrixLookup& weight,
    44                          statistics::Score&,
    45                          CrossSplitting&,
    46                          const size_t n);
     26    ConsensusInputRanker(CrossSplitter&, statistics::Score&);
    4727
    4828    ///
     
    6242    std::vector<size_t> id_;
    6343    std::vector<InputRanker> input_rankers_;
    64     u_int nof_rankers_;
    6544    std::vector<size_t> rank_;
    6645  };
  • trunk/lib/classifier/CrossSplitter.cc

    r481 r482  
    22
    33
     4#include <c++_tools/classifier/CrossSplitter.h>
     5#include <c++_tools/classifier/DataLookup2D.h>
    46#include <c++_tools/classifier/Target.h>
    5 #include <c++_tools/classifier/CrossSplitting.h>
    67#include <c++_tools/random/random.h>
    78
     
    1112namespace classifier { 
    1213
    13   CrossSplitting::CrossSplitting(const Target& target, const size_t k)
    14     :count_(0), k_(k)
    15  
     14  CrossSplitter::CrossSplitter(const Target& target, const DataLookup2D& data,
     15                               const u_int N, const size_t k)
     16  : k_(k), state_(0)
    1617  {
     18    std::vector<size_t> index_pos;
     19    std::vector<size_t> index_neg;
     20
    1721    for (size_t i=0; i<target.size(); i++){
    1822      if (target(i)==1)
    19         index_positive_.push_back(i);
     23        index_pos.push_back(i);
    2024      else
    21         index_negative_.push_back(i);
     25        index_neg.push_back(i);
    2226    }
    2327
    24     random::DiscreteUniform a;
    25     random_shuffle(index_negative_.begin(), index_negative_.end(), a);
    26     random_shuffle(index_positive_.begin(), index_positive_.end(), a);
     28    std::vector<size_t> part_pos(index_pos.size()); // [0,k-1]
     29    for (size_t i=0; i<part_pos.size(); i++)
     30      part_pos[i] = int(i*k/part_pos.size());
     31
     32    std::vector<size_t> part_neg(index_neg.size()); // [0,k-1]
     33    for (size_t i=0; i<part_pos.size(); i++)
     34      part_neg[i] = int(i*k/part_neg.size());
     35
     36    random::DiscreteUniform rnd;
     37
     38
     39    for (size_t i=0; i<N; ) {
     40      random_shuffle(index_neg.begin(), index_neg.end(), rnd);
     41      random_shuffle(index_pos.begin(), index_pos.end(), rnd);
     42     
     43      std::vector<size_t> training_index;
     44      std::vector<size_t> validation_index;
     45
     46      for (size_t part=0; part<k && i<N; i++, part++) {
     47       
     48        training_index.clear();
     49        training_index.clear();
     50        for (size_t j=0; j<index_neg.size(); j++) {
     51          if (part_neg[j]==part)
     52            validation_index.push_back(index_neg[j]);
     53          else
     54            training_index.push_back(index_neg[j]);
     55        }
     56        for (size_t j=0; j<index_pos.size(); j++) {
     57          if (part_pos[j]==part)
     58            validation_index.push_back(index_pos[j]);
     59          else
     60            training_index.push_back(index_pos[j]);
     61        }
     62
     63        // Dynamically allocated. Must be deleted in destructor.
     64
     65        training_data_.push_back(data.training_data(training_index));
     66        training_target_.push_back(Target(target,training_index));
     67        validation_data_.push_back(data.validation_data(training_index,
     68                                                        validation_index));
     69        validation_target_.push_back(Target(target,validation_index));
     70       
     71      }
     72    }
     73   
    2774  }
    2875
    29   std::vector<size_t> CrossSplitting::next()
     76  CrossSplitter::~CrossSplitter()
    3077  {
    31     random::DiscreteUniform a;
    32     if (count_==k_){
    33       count_=0;
    34       random_shuffle(index_negative_.begin(), index_negative_.end(), a);
    35       random_shuffle(index_positive_.begin(), index_positive_.end(), a);
    36     }
    37      
    38     count_++;
    39     std::vector<size_t> training_set;
     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  }
    4083
    41     size_t begin = int(index_positive_.size()*(count_-1)/k_);
    42     size_t end = int(index_positive_.size()*count_/k_);
    43     for (size_t i=0; i<index_positive_.size(); i++)
    44       if (i<begin || i>=end){
    45         training_set.push_back(index_positive_[i]);
    46       }
    47    
    48     begin = int(index_negative_.size()*(count_-1)/k_);
    49     end = int(index_negative_.size()*count_/k_);
    50     for (size_t i=0; i<index_negative_.size(); i++)
    51       if (i<begin || i>=end)
    52         training_set.push_back(index_negative_[i]);
    53    
    54     return training_set ;
    55    
    56   }
    57  
    5884}} // of namespace classifier and namespace theplu
  • trunk/lib/classifier/CrossSplitter.h

    r481 r482  
    11// $Id$
    22
    3 #ifndef _theplu_classifier_cross_splitting_
    4 #define _theplu_classifier_cross_splitting_
     3#ifndef _theplu_classifier_cross_splitter_
     4#define _theplu_classifier_cross_splitter_
    55
     6#include <c++_tools/classifier/Target.h>
     7
     8
     9#include <cassert>
    610#include <vector>
    711
    812namespace theplu {
    913namespace classifier { 
    10   class Target;
     14  class DataLookup2D;
    1115
    12   ///
    13   /// Class splitting a set into training set and validation set in a
    14   /// crossvalidation manner.
     16
     17  ///
     18  /// Class splitting a set into training set and validation set in a
     19  /// crossvalidation manner. This is done in a balanced way, meaning
     20  /// the proportions between the classes in the trainingset is close
     21  /// to the proportions in the whole dataset. In the first \a k
     22  /// rounds each sample is returned k-1 times, for next round the
     23  /// samples are shuffled and...
    1524  ///   
    16   /// @note The interface of this class will most likely change pretty soon.
    17   ///
    18   class CrossSplitting
     25
     26  class CrossSplitter
    1927  {
    2028 
    2129  public:
    2230    ///
    23     /// Constructor taking \a target and \a k for k-fold cross validation
     31    /// Constructor taking \a target and \a k for k-fold cross
     32    /// validation
    2433    ///
    25     CrossSplitting(const theplu::classifier::Target& target, const size_t k);
    2634
    27     ///
    28     /// Function generating a training set. This is done in a balanced
    29     /// way, meaning the proportions between the classes the
    30     /// trainingset is close to the proportions in the whole
    31     /// dataset. In the first \a k rounds each sample is returned k-1
    32     /// times, for next round the samples are shuffled and...
     35    CrossSplitter(const Target& target, const DataLookup2D&,
     36                   const size_t N, const size_t k);
     37
    3338    ///
    34     std::vector<size_t> next();
     39    /// Destructor
     40    ///
     41    ~CrossSplitter();
     42
     43    ///
     44    /// @return true if valid state
     45    ///
     46    inline bool end(void) const { return state_<size(); }
     47
     48    ///
     49    /// Function turning the object to the next state.
     50    ///
     51    /// @return false if there are no more state.
     52    ///
     53    inline void next(void) { state_++; }
     54
     55    ///
     56    /// rewind the sampler to initial state
     57    ///
     58    inline void reset(void) { state_=0; }
     59
     60    ///
     61    /// @return number of partitions
     62    ///
     63    inline u_long size(void) const { return training_data_.size(); }
     64
     65    ///
     66    /// @return training data
     67    ///
     68    /// @note if state is invalid the result is undefined
     69    ///
     70    inline const DataLookup2D& training_data(void) const
     71    { assert(end()); return *(training_data_[state_]); }
     72
     73    ///
     74    /// @return training target
     75    ///
     76    /// @note if state is invalid the result is undefined
     77    ///
     78    inline const Target& training_target(void) const
     79    { assert(end()); return training_target_[state_]; }
     80
     81    ///
     82    /// @return validation data
     83    ///
     84    /// @note if state is invalid the result is undefined
     85    ///
     86    inline const DataLookup2D& validation_data(void) const
     87    { assert(end()); return *(validation_data_[state_]); }
     88
     89    ///
     90    /// @return training target
     91    ///
     92    /// @note if state is invalid the result is undefined
     93    ///
     94    inline const Target& validation_target(void) const
     95    { assert(end()); return validation_target_[state_]; }
    3596
    3697  private:
    37     int count_;
    38     std::vector<size_t> index_negative_;
    39     std::vector<size_t> index_positive_;
    40     int k_;
    41 
     98    const size_t k_;
     99    u_long state_;
     100    std::vector<const DataLookup2D*> training_data_;
     101    std::vector<Target> training_target_;
     102    std::vector<const DataLookup2D*> validation_data_;
     103    std::vector<Target> validation_target_;
    42104         
    43105  };
  • trunk/lib/classifier/DataLookup2D.h

    r475 r482  
    6161
    6262    ///
     63    /// @return sub-Lookup of the DataLookup2D
     64    ///
     65    /// @Note Returns a dynamically allocated DataLookup2D, which has
     66    /// to be deleted by the caller to avoid memory leaks.
     67    ///
     68    virtual const DataLookup2D*
     69    training_data(const std::vector<size_t>&) const=0;
     70
     71    ///
    6372    /// @return number of rows
    6473    ///
    6574    inline size_t rows(void) const { return row_index_.size(); }
     75
     76    ///
     77    /// @return sub-Lookup of the DataLookup2D
     78    ///
     79    /// @Note Returns a dynamically allocated DataLookup2D, which has
     80    /// to be deleted by the caller to avoid memory leaks.
     81    ///
     82    virtual const DataLookup2D*
     83    validation_data(const std::vector<size_t>& train,
     84                    const std::vector<size_t>& val) const=0;
    6685
    6786    ///
  • trunk/lib/classifier/InputRanker.cc

    r475 r482  
    1818
    1919
    20   InputRanker::InputRanker(const MatrixLookup& data,
     20  InputRanker::InputRanker(const DataLookup2D& data,
    2121                           const Target& target,
    2222                           statistics::Score& score_object)
     
    4848
    4949
    50   InputRanker::InputRanker(const MatrixLookup& data,
     50  InputRanker::InputRanker(const DataLookup2D& data,
    5151                           const Target& target,
    5252                           statistics::Score& score_object,
  • trunk/lib/classifier/InputRanker.h

    r475 r482  
    1616namespace classifier { 
    1717
     18  class DataLookup2D;
    1819  class MatrixLookup;
    1920  class Target;
     
    3233    /// use all samples)
    3334    ///
    34     InputRanker(const MatrixLookup&, const Target&, statistics::Score&);
     35    InputRanker(const DataLookup2D&, const Target&, statistics::Score&);
    3536
    3637
     
    4041    /// use all samples)
    4142    ///
    42     InputRanker(const MatrixLookup&, const Target&, statistics::Score&,
     43    InputRanker(const DataLookup2D&, const Target&, statistics::Score&,
    4344                const MatrixLookup&);
    4445
  • trunk/lib/classifier/KernelLookup.cc

    r475 r482  
    33#include <c++_tools/classifier/KernelLookup.h>
    44#include <c++_tools/classifier/DataLookup2D.h>
     5
    56
    67
     
    1112    : DataLookup2D(), kernel_(&kernel)
    1213  {
    13     for(size_t i=0;i<(*kernel_).size();i++)
     14    column_index_.reserve(kernel.size());
     15    for(size_t i=0; i<kernel.size(); i++)
    1416      column_index_.push_back(i);
    1517    row_index_=column_index_;
    1618  }
    1719 
    18   KernelLookup::KernelLookup(const Kernel& kernel,
     20  KernelLookup::KernelLookup(const KernelLookup& kernel,
    1921                         const std::vector<size_t>& row,
    2022                         const std::vector<size_t>& column)
    21     : DataLookup2D(row,column), kernel_(&kernel)
     23    : DataLookup2D(kernel,row,column), kernel_(kernel.kernel_)
    2224  {
    2325  }
    2426 
     27  const KernelLookup*
     28  KernelLookup::training_data(const std::vector<size_t>& train) const
     29  {
     30    return new KernelLookup(*this,train,train);
     31  }
     32
     33
     34  const KernelLookup*
     35  KernelLookup::validation_data(const std::vector<size_t>& train,
     36                                const std::vector<size_t>& validation) const
     37  {
     38    return new KernelLookup(*this,train,validation);
     39  }
     40
    2541
    2642}} // of namespace classifier and namespace theplu
  • trunk/lib/classifier/KernelLookup.h

    r475 r482  
    3434    ///
    3535    KernelLookup(const Kernel& kernel, const std::vector<size_t>& row,
    36                const std::vector<size_t>& column);
     36                 const std::vector<size_t>& column);
     37   
     38    ///
     39    /// Contructor building a sub-KernelLookup from a KernelLookup
     40    /// defined by row index vector and column index vector. The
     41    /// resulting KernelLookup is independent of the old KernelLookup,
     42    /// but is undefined in case underlying Kernel is destroyed.
     43    ///
     44    /// @note For training usage row index shall always be equal to
     45    /// column index.
     46    ///
     47    KernelLookup(const KernelLookup& kernel, const std::vector<size_t>& row,
     48                 const std::vector<size_t>& column);
    3749   
    3850    ///
     
    4052    ///
    4153    KernelLookup(const KernelLookup&);
     54
     55
     56    ///
     57    /// @return sub-Lookup of the DataLookup2D
     58    ///
     59    /// @Note Returns a dynamically allocated DataLookup2D, which has
     60    /// to be deleted by the caller to avoid memory leaks.
     61    ///
     62    const KernelLookup* training_data(const std::vector<size_t>& train) const;
     63
     64
     65    ///
     66    /// In returned kernel each row corresponds to a training sample
     67    /// and each column corresponds to a validation sample.
     68    ///
     69    /// @return sub-Lookup of the DataLookup2D
     70    ///
     71    /// @Note Returns a dynamically allocated DataLookup2D, which has
     72    /// to be deleted by the caller to avoid memory leaks.
     73    ///
     74    const KernelLookup*
     75    validation_data(const std::vector<size_t>& train,
     76                    const std::vector<size_t>& validation) const;
     77
    4278
    4379    ///
  • trunk/lib/classifier/Makefile.am

    r476 r482  
    1010libclassifier_la_SOURCES = \
    1111  ConsensusInputRanker.cc \
    12   CrossSplitting.cc \
     12  CrossSplitter.cc \
    1313  DataLookup1D.cc \
    1414  DataLookup2D.cc \
     
    3131include_classifier_HEADERS = \
    3232  ConsensusInputRanker.h \
    33   CrossSplitting.h \
     33  CrossSplitter.h \
    3434  DataLookup2D.h \
    3535  GaussianKernelFunction.h \
  • trunk/lib/classifier/MatrixLookup.cc

    r475 r482  
    7272
    7373
     74  const MatrixLookup*
     75  MatrixLookup::training_data(const std::vector<size_t>& i) const
     76  {
     77    return new MatrixLookup(*this,i);
     78  }
     79
     80
     81
     82  const MatrixLookup*
     83  MatrixLookup::validation_data(const std::vector<size_t>& train,
     84                                const std::vector<size_t>& val) const
     85  {
     86    return new MatrixLookup(*this,train);
     87  }
     88
     89
     90
    7491  std::ostream& operator<<(std::ostream& s, const MatrixLookup& m)
    7592  {
  • trunk/lib/classifier/MatrixLookup.h

    r475 r482  
    5858    /// as input.
    5959    ///
    60     MatrixLookup(const MatrixLookup&, const std::vector<size_t>&, const bool row=false);
     60    MatrixLookup(const MatrixLookup&, const std::vector<size_t>&,
     61                 const bool row=false);
    6162
    6263    ///
     
    6667
    6768   
     69    ///
     70    /// @return pointer to sub-Lookup of the MatrixLookup
     71    ///
     72    const MatrixLookup* training_data(const std::vector<size_t>& i) const;
     73   
     74    ///
     75    /// @return pointer to sub-Lookup of the MatrixLookup
     76    ///
     77    const MatrixLookup* validation_data(const std::vector<size_t>&,
     78                                        const std::vector<size_t>&) const;
     79    ///
     80    /// Access operator
     81    ///
     82    /// @return element
     83    ///
    6884    inline double operator()(const size_t row, const size_t column) const
    6985    { return (*data_)(row_index_[row], column_index_[column]); }
  • trunk/lib/classifier/Target.cc

    r475 r482  
    2626  }
    2727
     28
     29  // Peter to Markus, align with gslapi
    2830  Target::Target(std::istream& is, char sep)
    2931    throw (utility::IO_error,std::exception)
     
    112114  }
    113115
     116  const Target& Target::operator=(const Target& other)
     117  {
     118    vector_=other.vector_;
     119    return *this;
     120  }
     121
    114122  std::ostream& operator<<(std::ostream& s, const Target& a)
    115123  {
  • trunk/lib/classifier/Target.h

    r475 r482  
    3434    /// The istream constructor.
    3535    ///
    36     Target(std::istream&, char sep='\0') throw (utility::IO_error,std::exception);
     36    Target(std::istream&, char sep='\0')
     37      throw (utility::IO_error,std::exception);
    3738
    3839    ///
     
    5758
    5859    ///
    59     /// sort
     60    /// @brief sort
    6061    ///
    6162    inline void sort(void) { std::sort(vector_.begin(), vector_.end()); }
     
    6768    const Target& operator*=(const int d);
    6869
     70    const Target& operator=(const Target& other);
     71
    6972  private:
     73    std::vector<int> vector_;
    7074
    71 
    72     std::vector<int> vector_;
    7375  }; 
    7476 
  • trunk/test/consensus_inputranker_test.cc

    r475 r482  
    77#include <c++_tools/gslapi/matrix.h>
    88#include <c++_tools/classifier/MatrixLookup.h>
    9 #include <c++_tools/classifier/CrossSplitting.h>
     9#include <c++_tools/classifier/CrossSplitter.h>
    1010
    1111#include <cstdlib>
     
    2424    error = new std::ofstream("/dev/null");
    2525    if (argc>1)
    26       std::cout << "consensus_inputranker_test -v : for printing extra information\n";
     26      std::cout << "consensus_inputranker_test -v : for printing extra "
     27                << "information\n";
    2728  }
    2829  *error << "testing consensus_inputranker" << std::endl;
     
    4041 
    4142  theplu::statistics::ROC roc;
    42   theplu::classifier::CrossSplitting sampler(target,3);
    43   theplu::classifier::ConsensusInputRanker cir(data,target,roc,sampler,30);
     43  theplu::classifier::CrossSplitter sampler(target,data,30,3);
     44  theplu::classifier::ConsensusInputRanker cir(sampler,roc);
    4445
    4546  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
     
    5455
    5556  theplu::gslapi::matrix flag(data.rows(),data.columns(),1);
    56   theplu::classifier::ConsensusInputRanker
    57     cir2(data,target,flag,roc,sampler,30);
     57  sampler.reset();  // Peter, fix weighted version instead
     58  theplu::classifier::ConsensusInputRanker cir2(sampler,roc);
    5859
    5960  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
     
    6667    ok=false;
    6768  }
    68 
     69 
    6970 
    7071  if (error!=&std::cerr)
  • trunk/test/crossvalidation_test.cc

    r475 r482  
    11// $Id$
    22
    3 #include <c++_tools/classifier/CrossSplitting.h>
     3#include <c++_tools/classifier/CrossSplitter.h>
     4#include <c++_tools/classifier/MatrixLookup.h>
    45#include <c++_tools/classifier/Target.h>
    5 //#include <c++_tools/gslapi/vector.h>
     6#include <c++_tools/gslapi/matrix.h>
    67
    78#include <cstdlib>
     
    2324      std::cout << "crossvalidation_test -v : for printing extra information\n";
    2425  }
    25   *error << "testing crosssplitting" << std::endl;
     26  *error << "testing crosssplitter" << std::endl;
    2627  bool ok = true;
    2728  classifier::Target target(10,1);
     
    2930    target(i)=-1;
    3031
    31   classifier::CrossSplitting cv(target,3);
    32   std::vector<size_t> training_set;
    33   std::vector<size_t> count(10);
    34   training_set = cv.next();
    35   for (unsigned int i=0; i<training_set.size(); i++)
    36     count[training_set[i]]++;
    37   training_set = cv.next();
    38   for (unsigned int i=0; i<training_set.size(); i++)
    39     count[training_set[i]]++;
    40   training_set = cv.next();
    41   for (unsigned int i=0; i<training_set.size(); i++)
    42     count[training_set[i]]++;
    43   for (unsigned int i=0; i<10 ; i++)
    44     ok = ok && (count[i]==2);
    45   if (!ok)
    46     *error << "Each sample did not occur twice in 3-fold cross-splitting"
    47            << std::endl;
    48 
    49   classifier::CrossSplitting cv2(target,3);
    50   training_set = cv2.next();
    51   if (target(training_set[0])*target(training_set[1]) == 1){
    52     *error << "Error: Two samples from same class"
    53            << std::endl;
    54     ok=false;
    55   }
     32  gslapi::matrix raw_data(10,10);
     33  classifier::MatrixLookup data(raw_data);
     34  classifier::CrossSplitter cv(target,data,3,3);
    5635
    5736  if (error!=&std::cerr)
    5837    delete error;
    59   return 0;
     38
     39  if (ok)
     40    return 0;
     41  return -1;
    6042}
  • trunk/test/kernel_test.cc

    r475 r482  
    3636  index[1]=2;
    3737  index[2]=3;
    38   classifier::KernelLookup kv(kernel,index,index);
     38  classifier::KernelLookup kv_raw(kernel);
     39  classifier::KernelLookup kv(kv_raw,index,index);
    3940  if (kv.rows()!=index.size()){
    4041    *error << "Error: KernelLookup(kernel, index)\n" << std::endl
     
    7172  index[1]=2;
    7273  index[2]=3;
    73   classifier::KernelLookup kv(kernel,index, index);
     74  classifier::KernelLookup kv(classifier::KernelLookup(kernel),index, index);
    7475  if (kv.rows()!=index.size()){
    7576    *error << "Error: KernelLookup(kernel, index)\n" << std::endl
Note: See TracChangeset for help on using the changeset viewer.