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 00039 template<typename T1> 00040 typename T1::elem_type 00041 fldr 00042 ( 00043 const Base<typename T1::elem_type, T1>& X, 00044 const Base<typename T1::elem_type, T1>& Y 00045 ) 00046 { 00047 arma_extra_debug_sigprint(); 00048 00049 // alias to element type 00050 typedef typename T1::elem_type eT; 00051 00052 // unwrap first samples matrix 00053 const unwrap<T1> tmp_X(X.get_ref()); 00054 const Mat<eT>& samples_X = tmp_X.M; 00055 00056 // unwrap second samples matrix 00057 const unwrap<T1> tmp_Y(Y.get_ref()); 00058 const Mat<eT>& samples_Y = tmp_Y.M; 00059 00060 // check wether one of the input matrices or both are empty 00061 if(samples_Y.is_empty() == true || samples_X.is_empty() == true) 00062 { 00063 return eT(0); 00064 } 00065 00066 // compute "trace" of within-class scatter matrix 00067 eT trSw = accu(var(samples_X) + var(samples_Y)); 00068 00069 // compute the means of each column of the two data matrices 00070 Row<eT> tmp = mean(samples_X) - mean(samples_Y); 00071 00072 // compute the trace of the between-class scatter matrix 00073 eT trSb = trace(trans(tmp) * tmp); 00074 00075 // return the ratio of the traces 00076 return eT(trSb) / eT(trSw); 00077 } 00078 00079