Ignore:
Timestamp:
Feb 24, 2006, 5:29:22 PM (17 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.

File:
1 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++) {     
Note: See TracChangeset for help on using the changeset viewer.