Changeset 626


Ignore:
Timestamp:
Sep 5, 2006, 4:54:31 AM (15 years ago)
Author:
Peter
Message:

fixes #113 and #114 removed Featureselection from NCC and SupervisedClassifier?

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

Legend:

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

    r616 r626  
    66#include <c++_tools/classifier/DataLookup2D.h>
    77#include <c++_tools/classifier/MatrixLookup.h>
    8 #include <c++_tools/classifier/InputRanker.h>
     8#include <c++_tools/classifier/MatrixLookupWeighted.h>
    99#include <c++_tools/classifier/SubsetGenerator.h>
    1010#include <c++_tools/classifier/Target.h>
     
    3838
    3939
    40   NCC::NCC(const MatrixLookup& data, const Target& target,
    41            const statistics::Distance& distance,
    42            statistics::Score& score, size_t nof_inputs)
    43     : SupervisedClassifier(target, &score, nof_inputs),
    44       distance_(distance), matrix_(data),weighted_(false),
    45       weights_(new MatrixLookup(data.rows(),data.columns(),1.0))
    46   {
    47   }
    48 
    49   NCC::NCC(const MatrixLookup& data, const Target& target,
    50            const statistics::Distance& distance,
    51            const MatrixLookup& weights,
    52            statistics::Score& score, size_t nof_inputs)
    53     : SupervisedClassifier(target, &score, nof_inputs),
    54       distance_(distance), matrix_(data),weighted_(true),
    55       weights_(&weights)
    56   {
    57   }
    58 
    59 
    6040  NCC::~NCC()   
    6141  {
     
    8464      ncc= new NCC(training_data,cs.training_target(),this->distance_);
    8565    }
    86     ncc->score_=this->score_;
    87     ncc->nof_inputs_=this->nof_inputs_;
    8866    return ncc;
    8967  }
     
    9270  bool NCC::train()
    9371  {
    94     // If score is set calculate centroids only for nof_inputs_ number
    95     // of top ranked inputs. Otherwise calculate centroids based on
     72    // Calculate centroids based on
    9673    // all inputs ( = all rows in data matrix).
    97     if(ranker_)
    98       delete ranker_;
    99     size_t rows=matrix_.rows();
    100     if(score_) {
    101       ranker_=new InputRanker(matrix_, target_, *score_, *weights_);
    102       rows=nof_inputs_;
    103     }
    104     centroids_=utility::matrix(rows, target_.nof_classes());
    105     utility::matrix nof_in_class(rows, target_.nof_classes());
    106     for(size_t i=0; i<rows; i++) {
     74    centroids_=utility::matrix(matrix_.rows(), target_.nof_classes());
     75    utility::matrix nof_in_class(matrix_.rows(), target_.nof_classes());
     76    for(size_t i=0; i<matrix_.rows(); i++) {
    10777      for(size_t j=0; j<matrix_.columns(); j++) {
    108         double value=matrix_(i,j);
    109         double weight=(*weights_)(i,j);
    110         if(score_) {
    111           value=matrix_(ranker_->id()[i],j);
    112           weight=(*weights_)(ranker_->id()[i],j);
    113         }
    114         if(weight) {
    115           centroids_(i,target_(j)) += value*weight;
    116           nof_in_class(i,target_(j))+=weight;
     78        if((*weights_)(i,j)) {
     79          centroids_(i,target_(j)) += matrix_(i,j)*(*weights_)(i,j);
     80          nof_in_class(i,target_(j))+=(*weights_)(i,j);
    11781        }
    11882      }
     
    12892  {
    12993    prediction=utility::vector(centroids_.columns());   
    130     size_t size=input.size();
    131     if(ranker_)
    132       size=nof_inputs_;
    133     utility::vector w(size,0);
    134     utility::vector value(size,0);
    135     for(size_t i=0; i<size; i++)  { // take care of missing values
     94    utility::vector w(input.size(),0);
     95    utility::vector value(input.size(),0);
     96    for(size_t i=0; i<input.size(); i++)  { // take care of missing values
    13697      value(i)=input(i);
    137       if(ranker_)
    138         value(i)=input(ranker_->id()[i]);
    13998      if(!std::isnan(value(i)))
    14099        w(i)=1.0;
  • trunk/c++_tools/classifier/NCC.h

    r616 r626  
    1818  namespace statistics {
    1919    class Distance;
    20     class Score;
    2120  }
    2221
     
    5251
    5352   
    54 
    55     ///
    56     /// Constructor taking the training data, the target vector, the
    57     /// distance measure, the score used to rank data inputs, and the
    58     /// number of top ranked data inputs to use in the classification
    59     /// as input
    60     ///
    61     NCC(const MatrixLookup&, const Target&, const statistics::Distance&,
    62         statistics::Score&, const size_t);
    63 
    64     ///
    65     /// Constructor taking the training data, the target vector, the
    66     /// distance measure, a weight matrix for the training data, the
    67     /// score used to rank data inputs, and the number of top ranked
    68     /// data inputs to use in the classification as input
    69     ///
    70     NCC(const MatrixLookup&, const Target&, const statistics::Distance&,
    71         const MatrixLookup&, statistics::Score&, const size_t);
    72 
    7353
    7454    virtual ~NCC();
  • trunk/c++_tools/classifier/SVM.cc

    r625 r626  
    44
    55#include <c++_tools/classifier/DataLookup2D.h>
    6 #include <c++_tools/classifier/InputRanker.h>
    76#include <c++_tools/classifier/SubsetGenerator.h>
    87#include <c++_tools/random/random.h>
    98#include <c++_tools/statistics/Averager.h>
    10 #include <c++_tools/statistics/Score.h>
    119#include <c++_tools/utility/matrix.h>
    1210#include <c++_tools/utility/vector.h>
  • trunk/c++_tools/classifier/SupervisedClassifier.cc

    r608 r626  
    88
    99  SupervisedClassifier::SupervisedClassifier(const Target& target)
    10     : target_(target), score_(0), ranker_(0), nof_inputs_(0),
    11       trained_(false)
    12   {
    13   }
    14 
    15   SupervisedClassifier::SupervisedClassifier(const Target& target,
    16                statistics::Score* score,
    17                const size_t nof_inputs)
    18     : target_(target), score_(score), ranker_(0), nof_inputs_(nof_inputs),
    19       trained_(false)
     10    : target_(target), trained_(false)
    2011  {
    2112  }
     
    2314  SupervisedClassifier::~SupervisedClassifier()
    2415  {
    25     if(ranker_)
    26       delete ranker_;
    2716  }
    2817
  • trunk/c++_tools/classifier/SupervisedClassifier.h

    r616 r626  
    1212  }
    1313
    14   namespace statistics {
    15     class Score;
    16   }
    17 
    18 
    1914namespace classifier { 
    2015
    2116  class DataLookup2D;
    22   class InputRanker;
    2317  class SubsetGenerator;
    2418  class Target;
     
    3731    SupervisedClassifier(const Target&);
    3832   
    39 
    40     ///
    41     /// Constructor. Taking a vector of target values, a score used to
    42     /// rank data inputs, and the number of top ranked inputs to use
    43     /// in classification.
    44     ///
    45     SupervisedClassifier(const Target&, statistics::Score*, const size_t);
    4633
    4734    ///
     
    7663   
    7764    const Target& target_;
    78     statistics::Score* score_;
    79     classifier::InputRanker* ranker_;
    80     size_t nof_inputs_;
    8165    bool trained_;
    8266   
Note: See TracChangeset for help on using the changeset viewer.