Changeset 866 for trunk/yat/classifier


Ignore:
Timestamp:
Sep 12, 2007, 2:25:28 PM (14 years ago)
Author:
Markus Ringnér
Message:

refs #236. EnsembleBuilder::predict bug fixed for matrix-based classifiers. However this is not the case for Kernel-based classifiers!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/EnsembleBuilder.cc

    r865 r866  
    2828#include "FeatureSelector.h"
    2929#include "KernelLookup.h"
     30#include "MatrixLookup.h"
     31#include "MatrixLookupWeighted.h"
    3032#include "Sampler.h"
    3133#include "SubsetGenerator.h"
     
    8284
    8385
    84   void  EnsembleBuilder::predict
     86  void EnsembleBuilder::predict
    8587  (const DataLookup2D& data,
    8688   std::vector<std::vector<statistics::Averager> >& result)
     
    9294   
    9395    utility::matrix prediction; 
    94     const KernelLookup* kernel = dynamic_cast<const KernelLookup*>(&data);
    95     if (kernel) {
    96       for(u_long k=0;k<subset_->size();k++) {
     96   
     97    const KernelLookup* kernel = dynamic_cast<const KernelLookup*>(&data);   
     98    const MatrixLookupWeighted* mw =
     99      dynamic_cast<const MatrixLookupWeighted*>(&data);   
     100    const MatrixLookup* m = dynamic_cast<const MatrixLookup*>(&data);
     101
     102    if(kernel) {
     103      for(u_long k=0;k<subset_->size();k++) {       
    97104        KernelLookup sub_kernel(*kernel,subset_->training_index(k),true);
    98105        classifier(k).predict(sub_kernel,prediction);
    99 
    100         for(size_t i=0; i<prediction.rows();i++)
    101           for(size_t j=0; j<prediction.columns();j++)
    102             result[i][j].add(prediction(i,j));
     106      }
     107    }
     108    else if(mw) {
     109      for(u_long k=0;k<subset_->size();k++) {
     110        MatrixLookupWeighted sub_matrix(*mw,subset_->training_features(k),true);
     111        classifier(k).predict(sub_matrix,prediction);
     112      }
     113    }
     114    else if(m) {
     115      for(u_long k=0;k<subset_->size();k++) {       
     116        MatrixLookup sub_matrix(*m,subset_->training_features(k),true);
     117        classifier(k).predict(sub_matrix,prediction);       
    103118      }
    104119    }
    105120    else {
    106       for(u_long k=0;k<subset_->size();k++) {
    107         classifier(k).predict(data,prediction);
    108         for(size_t i=0; i<prediction.rows();i++)
    109           for(size_t j=0; j<prediction.columns();j++)
    110             result[i][j].add(prediction(i,j));
    111        
    112       }
     121      std::string str;
     122      str = "Error in NCC::predict: DataLookup2D of unexpected class.";
     123      throw std::runtime_error(str);
    113124    }
     125
     126    for(size_t i=0; i<prediction.rows();i++)
     127      for(size_t j=0; j<prediction.columns();j++)
     128        result[i][j].add(prediction(i,j));   
    114129  }
    115130
    116 
     131 
    117132  const std::vector<std::vector<statistics::Averager> >&
    118133  EnsembleBuilder::validate(void)
     
    127142    for(u_long k=0;k<subset_->size();k++) {
    128143      classifier(k).predict(subset_->validation_data(k),prediction);
    129 
     144     
     145      // map results to indices of samples in training + validation data set
    130146      for(size_t i=0; i<prediction.rows();i++)
    131147        for(size_t j=0; j<prediction.columns();j++) {
Note: See TracChangeset for help on using the changeset viewer.