ECOCPAK v0.9
fn_custom_criterion.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 
00042 double
00043 criterion_custom
00044   (
00045   const vector<ClassData>& classes_vector,
00046   const ucolvec& indexPtr,
00047   const u32 curSubsetSize
00048   )
00049   {
00050   // print header
00051   #ifdef NCURSES_OUTPUT
00052   mvaddstr(3, 0, "Computing Custom Criterion:      ");
00053   refresh();
00054   #endif
00055 
00056   // don't engage criterion computation if the best
00057   // set yield by SFFS is the whole set of classes
00058   if((classes_vector.size() - curSubsetSize) == 0)
00059     {
00060     return 0.0;
00061     }
00062 
00063 // ================================================================== //
00064 // || INFO: Here we declare a 2D Armadillo matrix (i.e., "samples")|| //
00065 // ||       to hold the data matrix.                               || //
00066 // ||                                                              || //
00067 // ||       If you want to use instead of "samples" a raw C++ array|| //
00068 // ||       of doubles you can use the following statement to get a|| //
00069 // ||       pointer to a raw array of doubles.                     || //
00070 // ||                                                              || //
00071 // ||         double* raw_samples = samples.memptr();              || //
00072 // ||                                                              || //
00073 // ||       You can also use the following statement to get this   || //
00074 // ||       array's (i.e., "raw_samples") dimensions.              || //
00075 // ||                                                              || //
00076 // ||         const unsigned int n_rows = samples.n_rows;          || //
00077 // ||         const unsigned int n_cols = samples.n_cols;          || //
00078 // ||                                                              || //
00079 // ||       Where n_rows is the number of matrix rows and n_cols is|| //
00080 // ||       the number of matrix columns.                          || //
00081 // ||                                                              || //
00082 // ||       Of course you have to put these statements after the   || //
00083 // ||       "create_samples_matrix()" function below, since here we|| //
00084 // ||       only declare the "samples" matrix and consequently i   || //
00085 // ||       empty.                                                 || //
00086 // ||                                                              || //
00087 // ||       Note however, that Armadillo 2D matrices are stored in || //
00088 // ||       memory in a columnwise manner. e.g., if we have the    || //
00089 // ||       following (2 x 3) sized 2D matrix:                     || //
00090 // ||                                                              || //
00091 // ||                    2      1      3                           || //
00092 // ||                    3      4      5                           || //
00093 // ||                                                              || //
00094 // ||       is stored in memory as:                                || //
00095 // ||                                                              || //
00096 // ||                   {2, 3, 1, 4, 3, 5}                         || //
00097 // ||==============================================================|| //
00098 
00099     // ========== UNCOMMENT PIECES OF CODE IF NECESSARY ========== //
00100 
00101       // %% UNCOMMENT BEGINNING %%
00102         // mat samples;
00103       // %% UNCOMMENT END %%
00104 
00105 // ================================================================== //
00106 // || INFO: Here we declare a 1D Armadillo column vector of        || //
00107 // ||       unsigned integers to hold the samples labels i.e., each|| //
00108 // ||       element of the labels vector corresponds to a row i.e.,|| //
00109 // ||       a feature vector in the "samples" 2D matrix declared   || //
00110 // ||       previously. If you want to use "labels" as a raw C++   || //
00111 // ||       array of unsigned integers you can use the following   || //
00112 // ||       statement to get a pointer to a raw array of unsigned  || //
00113 // ||       integers.                                              || //
00114 // ||                                                              || //
00115 // ||         unsigned int* raw_labels = labels.memptr();          || //
00116 // ||                                                              || //
00117 // ||       You can also use the following statement to get this   || //
00118 // ||       array's (i.e., "raw_labels") size.                     || //
00119 // ||                                                              || //
00120 // ||         const unsigned int n_labels = labels.n_elem;         || //
00121 // ||                                                              || //
00122 // ||       Of course you have to put these statements after the   || //
00123 // ||       "create_samples_matrix()" function, since here we only || //
00124 // ||       declare the "labels" vector and consequently is empty. || //
00125 // ================================================================== //
00126 
00127     // ========== UNCOMMENT PIECES OF CODE IF NECESSARY ========== //
00128 
00129       // %% UNCOMMENT BEGINNING %%
00130         // ucolvec labels;
00131       // %% UNCOMMENT END %%
00132 
00133 // ================================================================== //
00134 // || INFO: The "create_samples_matrix()" function is used in order|| //
00135 // ||       to fill in the "samples" 2D matrix and the "labels" 1D || //
00136 // ||       column vector.                                         || //
00137 // ================================================================== //
00138 
00139     // ========== UNCOMMENT PIECES OF CODE IF NECESSARY ========== //
00140 
00141       // %% UNCOMMENT BEGINNING %%
00142         // create_samples_matrix
00143         //  (
00144         //  classes_vector,
00145         //  samples,
00146         //  labels
00147         //  );
00148       // %% UNCOMMENT END %%
00149 
00150 // ================================================================== //
00151 // || INFO: "bSet" is a column vector of unsigned integers that    || //
00152 // ||       holds the indices of the ClassData objects in the input|| //
00153 // ||       ClassData vector that represent the current set of     || //
00154 // ||       classes examined by SFFS.                              || //
00155 // ||                                                              || //
00156 // ||       If you want to use bSet as a raw C++ array of unsigned || //
00157 // ||       integers you can use the following statement to get a  || //
00158 // ||       pointer to a raw unsigned integers array.              || //
00159 // ||                                                              || //
00160 // ||         unsigned int* curinds = bSet.memptr();               || //
00161 // ||                                                              || //
00162 // ||       You can also use the following statement to get this   || //
00163 // ||       array's (i.e., "curinds") size.                        || //
00164 // ||                                                              || //
00165 // ||         const unsigned int n_curinds = bSet.n_elem;          || //
00166 // ||                                                              || //
00167 // ================================================================== //
00168 
00169     // ========== UNCOMMENT PIECES OF CODE IF NECESSARY ========== //
00170 
00171       // %% UNCOMMENT BEGINNING %%
00172         // ucolvec bSet = indexPtr.row(0, curSubsetSize - 1);
00173       // %% UNCOMMENT END %%
00174 
00175 // ================================================================== //
00176 // || INFO: cSet is a column vector of unsigned integers that holds|| //
00177 // ||       the indices of the ClassData objects that are          || //
00178 // ||       complement to the bSet indices i.e., the rest of the   || //
00179 // ||       class indices. If you want to use bSet as a raw C++    || //
00180 // ||       array of unsigned integers you can use the following   || //
00181 // ||       statement to get a pointer to a raw unsigned integers  || //
00182 // ||       array.                                                 || //
00183 // ||                                                              || //
00184 // ||         unsigned int* inds = bSet.memptr();                  || //
00185 // ||                                                              || //
00186 // ||       and you can also use the following statement to get    || //
00187 // ||       this array i.e., inds size.                            || //
00188 // ||                                                              || //
00189 // ||         const unsigned int s = bSet.n_elem;                  || //
00190 // ================================================================== //
00191 
00192     // ========== UNCOMMENT PIECES OF CODE IF NECESSARY ========== //
00193 
00194       // %% UNCOMMENT BEGINNING %%
00195         // ucolvec cSet = complement_sffs(indexPtr, curSubsetSize);
00196       // %% UNCOMMENT END %%
00197 
00198 // ================================================================== //
00199 // || INFO: If you want to use the raw C++ pointer to 1D arrays of || //
00200 // ||       type "double*" or "unsigned int*" you have to uncomment|| //
00201 // ||       the pieces of code below. Note however, that Armadillo || //
00202 // ||       2D matrices are stored in memory in a columnwise       || //
00203 // ||       manner.                                                || //
00204 // ||                                                              || //
00205 // ||       - The memptr() member function is used to obtain a     || //
00206 // ||         raw pointer to the memory used for storing           || //
00207 // ||         elements.                                            || //
00208 // ||                                                              || //
00209 // ||       - As soon as the size of the matrix/vector is          || //
00210 // ||         changed, the pointer is no longer valid.             || //
00211 // ||                                                              || //
00212 // ||       - Data for matrices is stored in a column-by-column    || //
00213 // ||         order.                                               || //
00214 // ================================================================== //
00215 
00216     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00217     //   - Raw pointer of feature vectors as a 1D array of type   //
00218     //     "double*"                                              //
00219     // ========================================================== //
00220 
00221       // %% UNCOMMENT BEGINNING %%
00222         // double* samples_mem = samples.memptr();
00223       // %% UNCOMMENT END %%
00224 
00225     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00226     //   - Number of features.                                    //
00227     // ========================================================== //
00228 
00229       // %% UNCOMMENT BEGINNING %%
00230         // const unsigned int n_cols = samples.n_cols;
00231       // %% UNCOMMENT END %%
00232 
00233     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00234     //   - Number of feature vectors.                             //
00235     // ========================================================== //
00236 
00237       // %% UNCOMMENT BEGINNING %%
00238         // const unsigned int n_rows = samples.n_rows;
00239       // %% UNCOMMENT END %%
00240 
00241     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00242     //   - Raw pointer of feature vectors labels as an 1D array   //
00243     //     of type "double*".                                     //
00244     // ========================================================== //
00245 
00246       // %% UNCOMMENT BEGINNING %%
00247         // double* labels_mem = labels.memptr();
00248       // %% UNCOMMENT END %%
00249 
00250     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00251     //   - Raw pointer of current class labels yield by SFFS as   //
00252     //     an 1D array of unsigned integers.                      //
00253     // ========================================================== //
00254 
00255       // %% UNCOMMENT BEGINNING %%
00256         // unsigned int* curinds = bSet.memptr();
00257       // %% UNCOMMENT END %%
00258 
00259     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00260     //   - size of "curinds" array.                               //
00261     // ========================================================== //
00262 
00263       // %% UNCOMMENT BEGINNING %%
00264         // const unsigned int n_curinds = bSet.n_elem;
00265       // %% UNCOMMENT END %%
00266 
00267     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00268     //   - Raw pointer of complement class labels yield by SFFS   //
00269     //     as an 1D array of unsigned integers.                   //
00270     // ========================================================== //
00271 
00272       // %% UNCOMMENT BEGINNING %%
00273         // unsigned int* cominds = cSet.memptr();
00274       // %% UNCOMMENT END %%
00275 
00276     // ========== UNCOMMENT PIECE OF CODE IF NECESSARY ========== //
00277     //   - size of "cominds" array.                               //
00278     // ========================================================== //
00279 
00280       // %% UNCOMMENT BEGINNING %%
00281         // const unsigned int n_cominds = bSet.n_elem;
00282       // %% UNCOMMENT END %%
00283 
00284   // ================================================================ //
00285   // ||                   START YOUR CODE HERE                     || //
00286   // ================================================================ //
00287 
00288     // - Replace the return value with the value returned by your
00289     //   criterion
00290     return 0.0;
00291 
00292   // ================================================================ //
00293   // ||                    END YOUR CODE HERE                      || //
00294   // ================================================================ //
00295   }
00296 
00297 
00298 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerator Defines