ECOCPAK v0.9
fn_decoc.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2011 the authors listed below
00002 // http://ecocpak.sourceforge.net
00003 //
00004 // Authors:
00005 // - Dimitrios Bouzas (bouzas at ieee dot org)
00006 // - Nikolaos Arvanitopoulos (niarvani at ieee dot org)
00007 // - Anastasios Tefas (tefas at aiia dot csd dot auth dot gr)
00008 //
00009 // This file is part of the ECOC PAK C++ library. It is
00010 // provided without any warranty of fitness for any purpose.
00011 //
00012 // You can redistribute this file and/or modify it under
00013 // the terms of the GNU Lesser General Public License (LGPL)
00014 // as published by the Free Software Foundation, either
00015 // version 3 of the License or (at your option) any later
00016 // version.
00017 // (see http://www.opensource.org/licenses for more info)
00018 
00019 
00022 
00023 
00024 
00051 u32
00052 decoc
00053   (
00054   const mat& training_samples,
00055   const icolvec& training_labels,
00056   const mat& testing_samples,
00057   const icolvec& testing_labels,
00058   const int decoding_strategy,
00059   const int classifiers_option,
00060   const int criterion_option,
00061   const bool verbose,
00062   ofstream& verbose_output,
00063   double& execution_time
00064   )
00065   {
00066   // timer object to count execution times
00067   wall_clock timer;
00068 
00069   // start timer
00070   timer.tic();
00071 
00072   // number of training samples
00073   const u32 n_training_samples = training_samples.n_rows;
00074 
00075   // number of samples attributes
00076   const u32 n_attributes = training_samples.n_cols;
00077 
00078   // number of testing samples
00079   const u32 n_testing_samples = testing_samples.n_rows;
00080 
00081   // variable to hold the number of classes
00082   u32 n_classes = 0;
00083 
00084   // adjust the training samples class labels to start from one
00085   // and count number of classes
00086   const icolvec tmp_training_labels =
00087     conv_to<icolvec>::from(process_labels(training_labels, n_classes));
00088 
00089   // adjust the testing samples class labels to start from one
00090   const uvec tmp_testing_labels = process_labels(testing_labels);
00091 
00092   // create classes vector
00093   vector<ClassData> classes_vector = create_class_vector
00094                                        (
00095                                        training_samples,
00096                                        tmp_training_labels
00097                                        );
00098 
00099   // coding matrix
00100   imat coding_matrix;
00101 
00102   // classifiers vector
00103   vector<Classifier*> classifiers_vector;
00104 
00105   // ================================================================ //
00106   // ||                        Training Step                       || //
00107   // ================================================================ //
00108 
00109     decoc_coding
00110       (
00111       classes_vector,
00112       criterion_option,
00113       classifiers_option,
00114       coding_matrix,
00115       classifiers_vector
00116       );
00117 
00118   // ================================================================ //
00119   // ||                        Testing Step                        || //
00120   // ================================================================ //
00121 
00122     // classification error
00123     double error = 0.0;
00124 
00125     // predictions for each sample
00126     uvec predictions;
00127 
00128     // confussion matrix
00129     umat confussion;
00130 
00131     // number of misclassified samples
00132     u32 n_missed = 0;
00133 
00134     // used to hold the number of missclassified testing samples
00135     decode
00136       (
00137       testing_samples,
00138       tmp_testing_labels,
00139       coding_matrix,
00140       classifiers_vector,
00141       classes_vector,
00142       decoding_strategy,
00143       predictions,
00144       n_missed,
00145       error,
00146       confussion
00147       );
00148 
00149   // if verbose output is activated
00150   if(verbose == true)
00151     {
00152     predictions = join_rows(predictions, tmp_testing_labels);
00153     verbose_output << "* Predictions vs Labels: " << endl << predictions << endl << endl;
00154     verbose_output << "* Coding Matrix: " << endl << coding_matrix << endl << endl;
00155     verbose_output << "* Confusion Matrix: " << endl << confussion << endl;
00156     }
00157 
00158   // clean up classifiers vector
00159   for(u32 i = 0; i < classifiers_vector.size(); i++)
00160     {
00161     delete classifiers_vector[i];
00162     }
00163 
00164   // stop timer
00165   execution_time = timer.toc();
00166 
00167   // reset class counter
00168   ClassData::globalIndex = 0;
00169 
00170   // return number of misclassified samples
00171   return n_missed;
00172   }
00173 
00174 
00175 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerator Defines