Changeset 864


Ignore:
Timestamp:
Sep 10, 2007, 4:38:14 PM (14 years ago)
Author:
Markus Ringnér
Message:

Added a lot of tests to feature_selection_test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/feature_selection_test.cc

    r862 r864  
    2323*/
    2424
     25#include "yat/classifier/DataLookupWeighted1D.h"
    2526#include "yat/classifier/FeatureSelectorIR.h"
    2627#include "yat/classifier/FeatureSelectorRandom.h"
    2728#include "yat/classifier/MatrixLookupWeighted.h"
    2829#include "yat/classifier/Target.h"
    29 #include "yat/statistics/AUC.h"
     30#include "yat/statistics/SNRScore.h"
    3031
    3132#include "yat/utility/matrix.h"
     
    5354  bool ok = true;
    5455
    55   statistics::AUC roc;
    56   classifier::FeatureSelectorIR f(roc, 12);
     56  statistics::SNRScore snr;
     57  classifier::FeatureSelectorIR f(snr, 12);
    5758  classifier::FeatureSelectorRandom f2(12);
    5859
     
    8586
    8687  f.update(dataviewweighted,targets);
    87   *error << "\nAUC ordered ordered features (top 12):\n";
     88  *error << "\nSNR ordered ordered features (top 12):\n";
    8889  features=f.features();
    8990  std::copy(features.begin(),features.end(),
     
    9192  *error << std::endl;
    9293
     94  size_t best_feature=features[0];
     95  if(best_feature!=69) {
     96    *error << "\nERROR: Incorrect best feature found!\n" << std::endl;
     97    ok=0;
     98  }
     99
     100  classifier::DataLookupWeighted1D row(dataviewweighted,best_feature,true);
     101  double score_diff=fabs(snr.score(targets,row)-1.47804);
     102  if(score_diff>0.00001) {
     103    *error << "\nERROR: Best score not what expected!\n" << std::endl;
     104    ok=0;
     105  }
     106 
     107  // Re-rank the best features
     108  classifier::MatrixLookupWeighted ranked=f.get(dataviewweighted);
     109  f.update(ranked,targets);
     110  features=f.features();
     111  for(size_t i=0;i<features.size();i++) {
     112    if(features[i]!=i) {
     113      ok=0;
     114      *error << "ERROR: Problem with top-ranked feature" << std::endl;
     115    }
     116  }
    93117
    94118  if (ok)
Note: See TracChangeset for help on using the changeset viewer.