fn_princomp_cov.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_cov
00019 //! @{
00020 
00021 
00022 
00023 //! \brief
00024 //! principal component analysis of a covariance matrix -- 3 arguments version
00025 //! coeff_out     -> principal component coefficients
00026 //! latent_out    -> principal component variances
00027 //! explained_out -> percentage of the total variance explained by each principal component.
00028 template<typename T1>
00029 inline
00030 void
00031 princomp_cov
00032   (
00033          Mat<typename T1::elem_type>&    coeff_out,
00034          Col<typename T1::pod_type>&     latent_out,
00035          Col<typename T1::pod_type>&     explained_out,
00036   const Base<typename T1::elem_type,T1>& X,
00037   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00038   )
00039   {
00040   arma_extra_debug_sigprint();
00041   
00042   typedef typename T1::elem_type eT;
00043   
00044   const unwrap<T1>   tmp(X.get_ref());
00045   const Mat<eT>& A = tmp.M;
00046 
00047   op_princomp_cov::direct_princomp_cov(coeff_out, latent_out, explained_out, A); 
00048   }
00049 
00050 
00051 
00052 //! \brief
00053 //! principal component analysis of a covariance matrix -- 2 arguments version
00054 //! coeff_out  -> principal component coefficients
00055 //! latent_out -> principal component variances
00056 template<typename T1>
00057 inline
00058 void
00059 princomp_cov
00060   (
00061          Mat<typename T1::elem_type>&    coeff_out,
00062          Col<typename T1::pod_type>&     latent_out,
00063   const Base<typename T1::elem_type,T1>& X,
00064   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00065   )
00066   {
00067   arma_extra_debug_sigprint();
00068  
00069   typedef typename T1::elem_type eT;
00070   
00071   const unwrap<T1>   tmp(X.get_ref());
00072   const Mat<eT>& A = tmp.M;
00073  
00074   op_princomp_cov::direct_princomp_cov(coeff_out, latent_out, A);
00075   }
00076 
00077 
00078 
00079 //! \brief
00080 //! principal component analysis of a covariance matrix -- 1 argument version
00081 //! coeff_out -> principal component coefficients
00082 template<typename T1>
00083 inline
00084 const Op<T1, op_princomp_cov>
00085 princomp_cov
00086   (
00087   const Base<typename T1::elem_type,T1>& X,
00088   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00089   )
00090   {
00091   arma_extra_debug_sigprint();
00092 
00093   return Op<T1, op_princomp_cov>(X.get_ref());
00094   }
00095 
00096 
00097 
00098 //! @}