Changeset 1236


Ignore:
Timestamp:
Mar 15, 2008, 5:33:43 PM (13 years ago)
Author:
Peter
Message:

working on #223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/ensemble_test.cc

    r1227 r1236  
    2323*/
    2424
     25#include "Suite.h"
     26
    2527#include "yat/utility/Matrix.h"
    2628#include "yat/classifier/SubsetGenerator.h"
     
    4648
    4749
    48 int main(const int argc,const char* argv[])
     50int main(int argc, char* argv[])
    4951
    5052  using namespace theplu::yat;
     53  test::Suite suite(argc, argv);
     54 
     55  suite.err() << "testing ensemble" << std::endl;
    5156
    52   std::ostream* error;
    53   if (argc>1 && argv[1]==std::string("-v"))
    54     error = &std::cerr;
    55   else {
    56     error = new std::ofstream("/dev/null");
    57     if (argc>1)
    58       std::cout << "ensemble_test -v : for printing extra information\n";
    59   }
    60   *error << "testing ensemble" << std::endl;
    61   bool ok = true;
    62 
    63   *error << "loading data" << std::endl;
     57  suite.err() << "loading data" << std::endl;
    6458  std::ifstream is("data/nm_data_centralized.txt");
    6559  utility::Matrix data_core(is);
    6660  is.close();
    6761
    68   *error << "create MatrixLookup" << std::endl;
     62  suite.err() << "create MatrixLookup" << std::endl;
    6963  classifier::MatrixLookup data(data_core);
    7064  classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction();
    71   *error << "Building kernel" << std::endl;
     65  suite.err() << "Building kernel" << std::endl;
    7266  classifier::Kernel_SEV kernel(data,*kf);
    7367
    7468
    75   *error << "load target" << std::endl;
     69  suite.err() << "load target" << std::endl;
    7670  is.open("data/nm_target_bin.txt");
    7771  classifier::Target target(is);
     
    8074
    8175  {
    82     *error << "create ensemble of ncc" << std::endl;
     76    suite.err() << "create ensemble of ncc" << std::endl;
    8377    classifier::NCC<statistics::EuclideanDistance> ncc;
    8478    classifier::CrossValidationSampler sampler(target,3,3);
     
    8680    classifier::EnsembleBuilder<classifier::SupervisedClassifier,
    8781      classifier::MatrixLookup> ensemble(ncc, data, sampler);
    88     *error << "build ensemble" << std::endl;
     82    suite.err() << "build ensemble" << std::endl;
    8983    ensemble.build();
    9084    std::vector<std::vector<statistics::Averager> > result;
     
    9387
    9488  {
    95     *error << "create ensemble of ncc" << std::endl;
     89    suite.err() << "create ensemble of ncc" << std::endl;
    9690    classifier::MatrixLookupWeighted data_weighted(data);
    9791    classifier::NCC<statistics::EuclideanDistance> ncc;
     
    10195    classifier::EnsembleBuilder<classifier::SupervisedClassifier,
    10296      classifier::MatrixLookupWeighted> ensemble(ncc, data_weighted, sampler);
    103     *error << "build ensemble" << std::endl;
     97    suite.err() << "build ensemble" << std::endl;
    10498    ensemble.build();
    10599    std::vector<std::vector<statistics::Averager> > result;
     
    107101  }
    108102
    109   *error << "create KernelLookup" << std::endl;
     103  suite.err() << "create KernelLookup" << std::endl;
    110104  classifier::KernelLookup kernel_lookup(kernel);
    111   *error << "create svm" << std::endl;
     105  suite.err() << "create svm" << std::endl;
    112106  classifier::SVM svm;
    113   *error << "create Subsets" << std::endl;
     107  suite.err() << "create Subsets" << std::endl;
    114108  classifier::CrossValidationSampler sampler(target,3,3);
    115109  classifier::SubsetGenerator<classifier::KernelLookup> cv(sampler,
    116110                                                           kernel_lookup);
    117111
    118   *error << "create ensemble" << std::endl;
     112  suite.err() << "create ensemble" << std::endl;
    119113  classifier::EnsembleBuilder<classifier::SVM, classifier::KernelLookup>
    120114    ensemble(svm, kernel_lookup, sampler);
    121   *error << "build ensemble" << std::endl;
     115  suite.err() << "build ensemble" << std::endl;
    122116  ensemble.build();
    123117  std::vector<std::vector<statistics::Averager> > result;
     
    128122    out(i)=ensemble.validate()[0][i].mean();
    129123  statistics::AUC roc;
    130   *error << roc.score(target,out) << std::endl;
     124  suite.err() << roc.score(target,out) << std::endl;
    131125
    132126  {
    133     *error << "create ensemble" << std::endl;
     127    suite.err() << "create ensemble" << std::endl;
    134128    classifier::EnsembleBuilder<classifier::SVM, classifier::KernelLookup>
    135129      ensemble(svm, kernel_lookup, sampler);
    136     *error << "test validate() before build()\n";
     130    suite.err() << "test validate() before build()\n";
    137131    ensemble.validate();
    138132    std::vector<std::vector<statistics::Averager> > result;
    139     *error << "test predict() before build()\n";
     133    suite.err() << "test predict() before build()\n";
    140134    ensemble.predict(kernel_lookup, result);
    141135  }
    142136  delete kf;
    143137
    144   if (error!=&std::cerr)
    145     delete error;
    146 
    147   if(ok)
    148     return 0;
    149   return -1;
    150  
     138  return suite.return_value();
    151139}
Note: See TracChangeset for help on using the changeset viewer.