ECOCPAK v0.9
fn_subdecoc.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 subdecoc
00053   (
00054   const mat& training_samples,
00055   const icolvec& training_labels,
00056   const mat& testing_samples,
00057   const icolvec& testing_labels,
00058   const Threshold& thres,
00059   const int decoding_strategy,
00060   const int classifiers_type,
00061   const int criterion_option,
00062   const bool verbose,
00063   imat& coding_matrix,
00064   ofstream& verbose_output,
00065   double& execution_time
00066   )
00067   {
00068   // timer object to count execution times
00069   wall_clock timer;
00070 
00071   // start timer
00072   timer.tic();
00073 
00074   // number of training samples
00075   const u32 n_training_samples = training_samples.n_rows;
00076 
00077   // number of samples attributes
00078   const u32 n_attributes = training_samples.n_cols;
00079 
00080   // number of testing samples
00081   const u32 n_testing_samples = testing_samples.n_rows;
00082 
00083   // variable to hold the number of classes
00084   u32 n_classes = 0;
00085 
00086   // adjust the training samples class labels to start from one
00087   // and count number of classes
00088   const icolvec tmp_training_labels =
00089     conv_to<icolvec>::from(process_labels(training_labels, n_classes));
00090 
00091   // adjust the testing samples class labels to start from one
00092   const uvec tmp_testing_labels = process_labels(testing_labels);
00093 
00094   // resulting classes after subclass techique
00095   vector<ClassData> classes_created_vector;
00096 
00097   // classifiers vector
00098   vector<Classifier*> classifiers_vector;
00099 
00100   // ================================================================ //
00101   // ||                        Training Step                       || //
00102   // ================================================================ //
00103 
00104     subclass_encoding
00105       (
00106       training_samples,
00107       tmp_training_labels,
00108       thres,
00109       criterion_option,
00110       classifiers_type,
00111       coding_matrix,
00112       classifiers_vector,
00113       classes_created_vector
00114       );
00115 
00116   // ================================================================ //
00117   // ||                        Testing Step                        || //
00118   // ================================================================ //
00119 
00120      // classification error
00121     double error = 0.0;
00122 
00123     // predictions for each sample
00124     uvec predictions;
00125 
00126     // confussion matrix
00127     umat confussion;
00128 
00129     // number of misclassified samples
00130     u32 n_missed = 0;
00131 
00132     // used to hold the number of missclassified testing samples
00133     decode
00134       (
00135       testing_samples,
00136       tmp_testing_labels,
00137       coding_matrix,
00138       classifiers_vector,
00139       classes_created_vector,
00140       decoding_strategy,
00141       predictions,
00142       n_missed,
00143       error,
00144       confussion
00145       );
00146 
00147   // if verbose output is activated
00148   if(verbose == true)
00149     {
00150     verbose_output << "* Predictions vs Labels: "
00151                    << endl << join_rows(predictions, tmp_testing_labels)
00152                    << endl << endl;
00153     verbose_output << "* Coding Matrix: " << endl << coding_matrix << endl << endl;
00154 
00155     verbose_output << "* Row    -   Class:" << endl;
00156     for(u32 i = 0; i < classes_created_vector.size(); i++)
00157       {
00158       verbose_output << "   " << i + 1 << "     -     "
00159                      << classes_created_vector[i].ClassLabel() << endl;
00160       }
00161 
00162     verbose_output << endl;
00163 
00164 
00165     verbose_output << "* Confusion Matrix: " << endl << confussion << endl;
00166     }
00167 
00168   // clean up classifiers vector
00169   for(u32 i = 0; i < classifiers_vector.size(); i++)
00170     {
00171     delete classifiers_vector[i];
00172     }
00173 
00174   // stop timer
00175   execution_time = timer.toc();
00176 
00177   // reset class counter
00178   ClassData::globalIndex = 0;
00179 
00180   // return number of misclassified samples
00181   return n_missed;
00182   }
00183 
00184 
00185 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerator Defines