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   )
00038   {
00039   arma_extra_debug_sigprint();
00040   
00041   typedef typename T1::elem_type eT;
00042   
00043   const unwrap<T1>   tmp(X.get_ref());
00044   const Mat<eT>& A = tmp.M;
00045 
00046   op_princomp_cov::direct_princomp_cov(coeff_out, latent_out, explained_out, A); 
00047   }
00048 
00049 
00050 
00051 //! \brief
00052 //! principal component analysis of a covariance matrix -- 2 arguments version
00053 //! coeff_out  -> principal component coefficients
00054 //! latent_out -> principal component variances
00055 template<typename T1>
00056 inline
00057 void
00058 princomp_cov
00059   (
00060          Mat<typename T1::elem_type>&    coeff_out,
00061          Col<typename T1::pod_type>&     latent_out,
00062   const Base<typename T1::elem_type,T1>& X
00063   )
00064   {
00065   arma_extra_debug_sigprint();
00066  
00067   typedef typename T1::elem_type eT;
00068   
00069   const unwrap<T1>   tmp(X.get_ref());
00070   const Mat<eT>& A = tmp.M;
00071  
00072   op_princomp_cov::direct_princomp_cov(coeff_out, latent_out, A);
00073   }
00074 
00075 
00076 
00077 //! \brief
00078 //! principal component analysis of a covariance matrix -- 1 argument version
00079 //! coeff_out -> principal component coefficients
00080 template<typename T1>
00081 inline
00082 const Op<T1, op_princomp_cov>
00083 princomp_cov(const Base<typename T1::elem_type,T1>& X)
00084   {
00085   arma_extra_debug_sigprint();
00086 
00087   return Op<T1, op_princomp_cov>(X.get_ref());
00088   }
00089 
00090 
00091 
00092 //! @}