ECOCPAK v0.9
|
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 00041 template<typename eT1, typename eT2> 00042 Col<u32> 00043 process_labels 00044 ( 00045 const Mat<eT1>& labels, 00046 Col<eT2>& n_samples_each_class, 00047 u32& n_classes 00048 ) 00049 { 00050 arma_extra_debug_sigprint(); 00051 00052 // sort the labels in ascending order 00053 Mat<eT1> tmp = sort(labels); 00054 Mat<u32> tmp_pos = sort_index(labels); 00055 00056 // number of element 00057 const u32 n_elem = labels.n_elem; 00058 00059 // new vector of transformed labels 00060 Col<u32> labels_out(n_elem); 00061 00062 // set size for n_samples_each_class vector 00063 n_samples_each_class.set_size(n_elem); 00064 00065 // initialize elements of n_samples_each_class to zero 00066 n_samples_each_class.zeros(); 00067 00068 // first step 00069 eT1 cur_value = tmp[0]; 00070 n_classes++; 00071 u32 j = 0; 00072 n_samples_each_class[j]++; 00073 labels_out[tmp_pos[0]] = n_classes; 00074 00075 // rest of steps 00076 for(u32 i = 1; i < n_elem; i++) 00077 { 00078 if(cur_value != tmp[i]) 00079 { 00080 cur_value = tmp[i]; 00081 n_classes++; 00082 j++; 00083 } 00084 00085 n_samples_each_class[j]++; 00086 labels_out[tmp_pos[i]] = n_classes; 00087 } 00088 00089 // dump junk 00090 n_samples_each_class = n_samples_each_class.rows(0, n_classes - 1); 00091 00092 return labels_out; 00093 } 00094 00095 00096 00111 template<typename eT1> 00112 Col<u32> 00113 process_labels 00114 ( 00115 const Mat<eT1>& labels, 00116 u32& n_classes 00117 ) 00118 { 00119 arma_extra_debug_sigprint(); 00120 00121 // sort the labels in ascending order 00122 Mat<eT1> tmp = sort(labels); 00123 Mat<u32> tmp_pos = sort_index(labels); 00124 00125 // number of element 00126 const u32 n_elem = labels.n_elem; 00127 00128 // new vector of transformed labels 00129 Col<u32> labels_out(n_elem); 00130 00131 // first step 00132 eT1 cur_value = tmp[0]; 00133 n_classes++; 00134 u32 j = 0; 00135 labels_out[tmp_pos[0]] = n_classes; 00136 00137 // rest of steps 00138 for(u32 i = 1; i < n_elem; i++) 00139 { 00140 if(cur_value != tmp[i]) 00141 { 00142 cur_value = tmp[i]; 00143 n_classes++; 00144 j++; 00145 } 00146 00147 labels_out[tmp_pos[i]] = n_classes; 00148 } 00149 00150 return labels_out; 00151 } 00152 00153 00154 00168 template<typename eT1> 00169 Col<u32> 00170 process_labels 00171 ( 00172 const Mat<eT1>& labels 00173 ) 00174 { 00175 arma_extra_debug_sigprint(); 00176 00177 u32 n_classes = 0; 00178 00179 // sort the labels in ascending order 00180 Mat<eT1> tmp = sort(labels); 00181 Mat<u32> tmp_pos = sort_index(labels); 00182 00183 // number of element 00184 const u32 n_elem = labels.n_elem; 00185 00186 // new vector of transformed labels 00187 Col<u32> labels_out(n_elem); 00188 00189 // first step 00190 eT1 cur_value = tmp[0]; 00191 n_classes++; 00192 u32 j = 0; 00193 labels_out[tmp_pos[0]] = n_classes; 00194 00195 // for all the elements 00196 for(u32 i = 1; i < n_elem; i++) 00197 { 00198 // if current value is different than the i-th label 00199 if(cur_value != tmp[i]) 00200 { 00201 cur_value = tmp[i]; 00202 n_classes++; // increase number of classes 00203 j++; 00204 } 00205 00206 // update the new labels vector 00207 labels_out[tmp_pos[i]] = n_classes; 00208 } 00209 00210 return labels_out; 00211 } 00212 00213 00214