Changeset 525


Ignore:
Timestamp:
Feb 24, 2006, 5:29:22 PM (16 years ago)
Author:
Markus Ringnér
Message:

Added structure to Supervised classifier and NCC to support ranking inputs with a statistics::Score and using only top-scoring inputs in classification.

Location:
trunk/lib/classifier
Files:
4 edited

Legend:

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

    r523 r525  
    55#include <c++_tools/classifier/DataLookup1D.h>
    66#include <c++_tools/classifier/DataLookup2D.h>
     7#include <c++_tools/classifier/InputRanker.h>
    78#include <c++_tools/classifier/Target.h>
    89#include <c++_tools/gslapi/vector.h>
     
    2425  }
    2526
     27  NCC::NCC(const DataLookup2D& data, const Target& target,
     28           const statistics::Distance& distance,
     29           statistics::Score& score, size_t nof_inputs)
     30    : SupervisedClassifier(target, &score, nof_inputs),
     31      distance_(distance), matrix_(data)
     32  {
     33  }
     34
     35  NCC::~NCC()   
     36  {
     37    if(ranker_)
     38      delete ranker_;
     39  }
     40
     41
    2642  SupervisedClassifier*
    2743  NCC::make_classifier(const DataLookup2D& data,
    2844                       const Target& target) const
    2945  {     
    30     NCC* sc= new NCC(data,target,this->distance_);
    31     return sc;
     46    NCC* ncc= new NCC(data,target,this->distance_);
     47    ncc->score_=this->score_;
     48    ncc->nof_inputs_=this->nof_inputs_;
     49    return ncc;
    3250  }
    3351
     
    3553  bool NCC::train()
    3654  {
     55    if(ranker_)
     56      delete ranker_;
     57    if(score_)
     58      ranker_=new InputRanker(matrix_, target_, *score_);
     59    // Markus : ranker_ should be taken into account if used!!!
     60
    3761    // Calculate the centroids for each class
    3862    centroids_=gslapi::matrix(matrix_.rows(),target_.nof_classes());
     
    5478                    gslapi::vector& prediction) const
    5579  {
     80    // Markus : ranker_ should be taken into account if used!!!
     81
    5682    prediction=gslapi::vector(centroids_.columns());   
    5783    gslapi::vector w(input.size(),0);
     
    6894                    gslapi::matrix& prediction) const
    6995  {
     96    // Markus : ranker_ should be taken into account if used!!!
     97   
    7098    prediction=gslapi::matrix(centroids_.columns(), input.columns());   
    7199    for(size_t j=0; j<input.columns();j++) {     
  • trunk/lib/classifier/NCC.h

    r523 r525  
    77
    88#include <c++_tools/classifier/SupervisedClassifier.h>
    9 //#include <c++_tools/statistics/Distance.h>
    109
    1110#include <map>
     
    1514  namespace statistics {
    1615    class Distance;
     16    class Score;
    1717  }
    1818
     
    3636    ///
    3737    NCC(const DataLookup2D&, const Target&, const statistics::Distance&);
     38
     39    NCC(const DataLookup2D&, const Target&, const statistics::Distance&,
     40        statistics::Score&, const size_t);
     41
     42    virtual ~NCC();
    3843
    3944    const gslapi::matrix& centroids(void) const {return centroids_;}
  • trunk/lib/classifier/SupervisedClassifier.cc

    r523 r525  
    66namespace classifier {
    77
    8   SupervisedClassifier::SupervisedClassifier(const Target& target)
    9     : target_(target), trained_(false)
     8  SupervisedClassifier::SupervisedClassifier(const Target& target,
     9                                             statistics::Score* score,
     10                                             const size_t nof_inputs)
     11    : target_(target), score_(score), ranker_(0), nof_inputs_(nof_inputs),
     12      trained_(false)
    1013  {
    1114  }
  • trunk/lib/classifier/SupervisedClassifier.h

    r523 r525  
    44#define _theplu_classifier_supervisedclassifier_
    55
     6#include <cctype>
    67
    78namespace theplu {
     
    1213  }
    1314
     15  namespace statistics {
     16    class Score;
     17  }
     18
     19
    1420namespace classifier { 
    1521
    1622  class DataLookup2D;
    17   class Target;
     23  class InputRanker;  class Target;
    1824
    1925
     
    2935    /// Constructor. Taking a vector of target values.
    3036    ///
    31     SupervisedClassifier(const Target&);
     37    SupervisedClassifier(const Target&, statistics::Score* =0,
     38                         const size_t=0);
    3239   
    3340    ///
     
    6269   
    6370    const Target& target_;
     71    statistics::Score* score_;
     72    classifier::InputRanker* ranker_;
     73    size_t nof_inputs_;
    6474    bool trained_;
    6575   
Note: See TracChangeset for help on using the changeset viewer.