123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include <vector>
- #include <core/basics/vectorio.h>
- #include <core/basics/Timer.h>
- #include <core/basics/Config.h>
- #include <vislearning/baselib/Globals.h>
- #include <vislearning/cbaselib/MultiDataset.h>
- #include <gp-hik-core/FastMinKernel.h>
- #include <gp-hik-core/FMKGPHyperparameterOptimization.h>
- #include <gp-hik-core/tools.h>
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- #include "datatools.h"
- int main (int argc, char **argv)
- {
- std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
- Config conf ( argc, argv );
-
- string ext = conf.gS("main", "ext", ".txt");
- cerr << "Using cache extension: " << ext << endl;
- MultiDataset md ( &conf );
- const ClassNames & classNamesTrain = md.getClassNames("train");
-
-
- vector< vector<double> > trainData;
- NICE::Vector y;
- const LabeledSet *train = md["train"];
- readData< vector< vector<double> >, vector<double> > ( conf, *train, trainData, y, ext );
- transposeVectorOfVectors ( trainData );
-
- #if 0
- Quantization q ( conf.gI("GPHIKClassifier", "num_bins") );
- for ( uint i = 0 ; i < trainData.size() ; i++ )
- for ( uint j = 0 ; j < trainData[i].size(); j++ )
- trainData[i][j] = q.getPrototype ( q.quantize( trainData[i][j] ) );
- #endif
-
- cerr << "Size of the training set: " << trainData.size() << endl;
- double noise = 0.1;
-
- Timer t;
- std::cerr << " create FastMinKernel object with data" << std::endl;
- t.start();
- FastMinKernel *fmk = new FastMinKernel ( trainData, noise );
- t.stop();
- std::cerr << " time for setting up FMK object: " << t.getLast() << std::endl;
- std::cerr << " Initialize FMKGPHyperparameterOptimization object " << std::endl;
- t.start();
- FMKGPHyperparameterOptimization hyper ( &conf, fmk, "FMKGPHyperparameterOptimization" );
- t.stop();
- std::cerr << " time for setting up FMKGP object: " << t.getLast() << std::endl;
- std::cerr << " start optimization" << std::endl;
- t.start();
- hyper.optimize ( y );
- t.stop();
- std::cerr << " time for optimization: " << t.getLast() << std::endl;
-
-
-
-
- const LabeledSet *test = md["test"];
- VVector testData;
- Vector yTest;
- readData< VVector, Vector > ( conf, *test, testData, yTest, ext );
-
- #if 0
- for ( uint i = 0 ; i < testData.size() ; i++ )
- for ( uint j = 0 ; j < testData[i].size(); j++ )
- testData[i][j] = q.getPrototype ( q.quantize( testData[i][j] ) );
- #endif
-
- Matrix confusion ( y.Max()+1, yTest.Max() + 1, 0.0 );
- for ( uint i = 0 ; i < testData.size(); i++ )
- {
- const Vector & xstar = testData[i];
-
-
- SparseVector xstar_sparse ( xstar );
- uint classno_groundtruth = yTest[i];
- SparseVector scores;
- t.start();
- uint classno_estimated = hyper.classify ( xstar_sparse, scores );
- t.stop();
-
- scores.store(cerr);
- cerr << "[" << i << " / " << testData.size() << "] " << classno_estimated << " " << classno_groundtruth << " time: " << t.getLast() << endl;
-
- confusion( classno_estimated, classno_groundtruth ) += 1;
- }
- confusion.normalizeColumnsL1();
- cerr << confusion << endl;
- cerr << "average recognition rate: " << confusion.trace()/confusion.rows() << endl;
- return 0;
- }
|