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   )
00040   {
00041   arma_extra_debug_sigprint();
00042   
00043   typedef typename T1::elem_type eT;
00044   
00045   const unwrap<T1>   tmp(X.get_ref());
00046   const Mat<eT>& A = tmp.M;
00047   
00048   op_princomp::direct_princomp(coeff_out, score_out, latent_out, tsquared_out, A);
00049   }
00050 
00051 
00052 
00053 //! \brief
00054 //! principal component analysis -- 3 arguments version
00055 //! coeff_out    -> principal component coefficients
00056 //! score_out    -> projected samples
00057 //! latent_out   -> eigenvalues of principal vectors
00058 template<typename T1>
00059 inline
00060 void
00061 princomp
00062   (
00063          Mat<typename T1::elem_type>&    coeff_out,
00064          Mat<typename T1::elem_type>&    score_out,
00065          Col<typename T1::pod_type>&     latent_out,
00066   const Base<typename T1::elem_type,T1>& X
00067   )
00068   {
00069   arma_extra_debug_sigprint();
00070   
00071   typedef typename T1::elem_type eT;
00072   
00073   const unwrap<T1>   tmp(X.get_ref());
00074   const Mat<eT>& A = tmp.M;
00075   
00076   op_princomp::direct_princomp(coeff_out, score_out, latent_out, A); 
00077   }
00078 
00079 
00080 
00081 //! \brief
00082 //! principal component analysis -- 2 arguments version
00083 //! coeff_out    -> principal component coefficients
00084 //! score_out    -> projected samples
00085 template<typename T1>
00086 inline
00087 void
00088 princomp
00089   (
00090          Mat<typename T1::elem_type>&    coeff_out,
00091          Mat<typename T1::elem_type>&    score_out,
00092   const Base<typename T1::elem_type,T1>& X
00093   )
00094   {
00095   arma_extra_debug_sigprint();
00096   
00097   typedef typename T1::elem_type eT;
00098   
00099   const unwrap<T1>   tmp(X.get_ref());
00100   const Mat<eT>& A = tmp.M;
00101   
00102   op_princomp::direct_princomp(coeff_out, score_out, A); 
00103   }
00104 
00105 
00106 
00107 //! \brief
00108 //! principal component analysis -- 1 argument version
00109 //! coeff_out    -> principal component coefficients
00110 template<typename T1>
00111 inline
00112 const Op<T1, op_princomp>
00113 princomp(const Base<typename T1::elem_type,T1>& X)
00114   {
00115   arma_extra_debug_sigprint();
00116 
00117   return Op<T1, op_princomp>(X.get_ref());
00118   }
00119 
00120 
00121 
00122 //! @}