Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 template<typename eT>
00030 inline
00031 void
00032 op_princomp_cov::direct_princomp_cov
00033 (
00034 Mat<eT>& coeff_out,
00035 Col<eT>& latent_out,
00036 Col<eT>& explained_out,
00037 const Mat<eT>& in
00038 )
00039 {
00040 arma_extra_debug_sigprint();
00041
00042
00043 const Mat<eT> in_cov = cov(in);
00044
00045
00046 Mat<eT> U;
00047
00048 const bool svd_ok = svd(U, latent_out, coeff_out, in_cov);
00049
00050 if(svd_ok == false)
00051 {
00052 arma_print("princomp_cov(): singular value decomposition failed");
00053
00054 coeff_out.reset();
00055 latent_out.reset();
00056 explained_out.reset();
00057
00058 return;
00059 }
00060
00061 explained_out = (eT(100) * latent_out) / sum(latent_out);
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071 template<typename eT>
00072 inline
00073 void
00074 op_princomp_cov::direct_princomp_cov
00075 (
00076 Mat<eT>& coeff_out,
00077 Col<eT>& latent_out,
00078 const Mat<eT>& in
00079 )
00080 {
00081 arma_extra_debug_sigprint();
00082
00083
00084 const Mat<eT> in_cov = cov(in);
00085
00086
00087 Mat<eT> U;
00088
00089 const bool svd_ok = svd(U, latent_out, coeff_out, in_cov);
00090
00091 if(svd_ok == false)
00092 {
00093 arma_print("princomp_cov(): singular value decomposition failed");
00094
00095 coeff_out.reset();
00096 latent_out.reset();
00097
00098 return;
00099 }
00100
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 template<typename eT>
00110 inline
00111 void
00112 op_princomp_cov::direct_princomp_cov
00113 (
00114 Mat<eT>& coeff_out,
00115 const Mat<eT>& in
00116 )
00117 {
00118 arma_extra_debug_sigprint();
00119
00120
00121 const Mat<eT> in_cov = cov(in);
00122
00123
00124 Mat<eT> U;
00125 Col<eT> s;
00126
00127 const bool svd_ok = svd(U, s, coeff_out, in_cov);
00128
00129 if(svd_ok == false)
00130 {
00131 arma_print("princomp_cov(): singular value decomposition failed");
00132
00133 coeff_out.reset();
00134
00135 return;
00136 }
00137
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 template<typename T>
00149 inline
00150 void
00151 op_princomp_cov::direct_princomp_cov
00152 (
00153 Mat< std::complex<T> >& coeff_out,
00154 Col<T>& latent_out,
00155 Col<T>& explained_out,
00156 const Mat< std::complex<T> >& in
00157 )
00158 {
00159 arma_extra_debug_sigprint();
00160
00161 typedef std::complex<T> eT;
00162
00163
00164 const Mat<eT> in_cov = cov(in);
00165
00166
00167 Mat<eT> U;
00168
00169 const bool svd_ok = svd(U, latent_out, coeff_out, in_cov);
00170
00171 if(svd_ok == false)
00172 {
00173 arma_print("princomp_cov(): singular value decomposition failed");
00174
00175 coeff_out.reset();
00176 latent_out.reset();
00177 explained_out.reset();
00178
00179 return;
00180 }
00181
00182 explained_out = (T(100) * latent_out) / sum(latent_out);
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192 template<typename T>
00193 inline
00194 void
00195 op_princomp_cov::direct_princomp_cov
00196 (
00197 Mat< std::complex<T> >& coeff_out,
00198 Col<T>& latent_out,
00199 const Mat< std::complex<T> >& in
00200 )
00201 {
00202 arma_extra_debug_sigprint();
00203
00204 typedef std::complex<T> eT;
00205
00206
00207 const Mat<eT> in_cov = cov(in);
00208
00209
00210 Mat<eT> U;
00211
00212 const bool svd_ok = svd(U, latent_out, coeff_out, in_cov);
00213
00214 if(svd_ok == false)
00215 {
00216 arma_print("princomp_cov(): singular value decomposition failed");
00217
00218 coeff_out.reset();
00219 latent_out.reset();
00220
00221 return;
00222 }
00223
00224 }
00225
00226
00227
00228
00229
00230
00231
00232 template<typename T>
00233 inline
00234 void
00235 op_princomp_cov::direct_princomp_cov
00236 (
00237 Mat< std::complex<T> >& coeff_out,
00238 const Mat< std::complex<T> >& in
00239 )
00240 {
00241 arma_extra_debug_sigprint();
00242
00243 typedef std::complex<T> eT;
00244
00245
00246 const Mat<eT> in_cov = cov(in);
00247
00248
00249 Mat<eT> U;
00250 Col<T> s;
00251
00252 const bool svd_ok = svd(U, s, coeff_out, in_cov);
00253
00254 if(svd_ok == false)
00255 {
00256 arma_print("princomp_cov(): singular value decomposition failed");
00257
00258 coeff_out.reset();
00259
00260 return;
00261 }
00262
00263 }
00264
00265
00266
00267 template<typename T1>
00268 inline
00269 void
00270 op_princomp_cov::apply
00271 (
00272 Mat<typename T1::elem_type>& out,
00273 const Op<T1,op_princomp_cov>& in
00274 )
00275 {
00276 arma_extra_debug_sigprint();
00277
00278 typedef typename T1::elem_type eT;
00279
00280 const unwrap_check<T1> tmp(in.m, out);
00281 const Mat<eT>& A = tmp.M;
00282
00283 op_princomp_cov::direct_princomp_cov(out, A);
00284 }
00285
00286
00287
00288