fn_princomp.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
00006 // - Conrad Sanderson (conradsand at ieee dot org)
00007 // 
00008 // This file is part of the Armadillo C++ library.
00009 // It is provided without any warranty of fitness
00010 // for any purpose. You can redistribute this file
00011 // and/or modify it under the terms of the GNU
00012 // Lesser General Public License (LGPL) as published
00013 // by the Free Software Foundation, either version 3
00014 // of the License or (at your option) any later version.
00015 // (see http://www.opensource.org/licenses for more info)
00016 
00017 
00018 //! \addtogroup fn_princomp
00019 //! @{
00020 
00021 
00022 
00023 //! \brief
00024 //! principal component analysis -- 4 arguments version
00025 //! coeff_out    -> principal component coefficients
00026 //! score_out    -> projected samples
00027 //! latent_out   -> eigenvalues of principal vectors
00028 //! tsquared_out -> Hotelling's T^2 statistic
00029 template<typename T1>
00030 inline
00031 void
00032 princomp
00033   (
00034          Mat<typename T1::elem_type>&    coeff_out,
00035          Mat<typename T1::elem_type>&    score_out,
00036          Col<typename T1::pod_type>&     latent_out,
00037          Col<typename T1::elem_type>&    tsquared_out,
00038   const Base<typename T1::elem_type,T1>& X,
00039   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00040   )
00041   {
00042   arma_extra_debug_sigprint();
00043   
00044   typedef typename T1::elem_type eT;
00045   
00046   const unwrap<T1>   tmp(X.get_ref());
00047   const Mat<eT>& A = tmp.M;
00048   
00049   op_princomp::direct_princomp(coeff_out, score_out, latent_out, tsquared_out, A);
00050   }
00051 
00052 
00053 
00054 //! \brief
00055 //! principal component analysis -- 3 arguments version
00056 //! coeff_out    -> principal component coefficients
00057 //! score_out    -> projected samples
00058 //! latent_out   -> eigenvalues of principal vectors
00059 template<typename T1>
00060 inline
00061 void
00062 princomp
00063   (
00064          Mat<typename T1::elem_type>&    coeff_out,
00065          Mat<typename T1::elem_type>&    score_out,
00066          Col<typename T1::pod_type>&     latent_out,
00067   const Base<typename T1::elem_type,T1>& X,
00068   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00069   )
00070   {
00071   arma_extra_debug_sigprint();
00072   
00073   typedef typename T1::elem_type eT;
00074   
00075   const unwrap<T1>   tmp(X.get_ref());
00076   const Mat<eT>& A = tmp.M;
00077   
00078   op_princomp::direct_princomp(coeff_out, score_out, latent_out, A); 
00079   }
00080 
00081 
00082 
00083 //! \brief
00084 //! principal component analysis -- 2 arguments version
00085 //! coeff_out    -> principal component coefficients
00086 //! score_out    -> projected samples
00087 template<typename T1>
00088 inline
00089 void
00090 princomp
00091   (
00092          Mat<typename T1::elem_type>&    coeff_out,
00093          Mat<typename T1::elem_type>&    score_out,
00094   const Base<typename T1::elem_type,T1>& X,
00095   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00096   )
00097   {
00098   arma_extra_debug_sigprint();
00099   
00100   typedef typename T1::elem_type eT;
00101   
00102   const unwrap<T1>   tmp(X.get_ref());
00103   const Mat<eT>& A = tmp.M;
00104   
00105   op_princomp::direct_princomp(coeff_out, score_out, A); 
00106   }
00107 
00108 
00109 
00110 //! \brief
00111 //! principal component analysis -- 1 argument version
00112 //! coeff_out    -> principal component coefficients
00113 template<typename T1>
00114 inline
00115 const Op<T1, op_princomp>
00116 princomp
00117   (
00118   const Base<typename T1::elem_type,T1>& X,
00119   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00120   )
00121   {
00122   arma_extra_debug_sigprint();
00123 
00124   return Op<T1, op_princomp>(X.get_ref());
00125   }
00126 
00127 
00128 
00129 //! @}