comparison armadillo-2.4.4/include/armadillo_bits/fn_princomp.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-2011 Conrad Sanderson
3 // Copyright (C) 2010 Dimitrios Bouzas
4 //
5 // This file is part of the Armadillo C++ library.
6 // It is provided without any warranty of fitness
7 // for any purpose. You can redistribute this file
8 // and/or modify it under the terms of the GNU
9 // Lesser General Public License (LGPL) as published
10 // by the Free Software Foundation, either version 3
11 // of the License or (at your option) any later version.
12 // (see http://www.opensource.org/licenses for more info)
13
14
15 //! \addtogroup fn_princomp
16 //! @{
17
18
19
20 //! \brief
21 //! principal component analysis -- 4 arguments version
22 //! coeff_out -> principal component coefficients
23 //! score_out -> projected samples
24 //! latent_out -> eigenvalues of principal vectors
25 //! tsquared_out -> Hotelling's T^2 statistic
26 template<typename T1>
27 inline
28 bool
29 princomp
30 (
31 Mat<typename T1::elem_type>& coeff_out,
32 Mat<typename T1::elem_type>& score_out,
33 Col<typename T1::pod_type>& latent_out,
34 Col<typename T1::elem_type>& tsquared_out,
35 const Base<typename T1::elem_type,T1>& X,
36 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
37 )
38 {
39 arma_extra_debug_sigprint();
40
41 typedef typename T1::elem_type eT;
42
43 const unwrap<T1> tmp(X.get_ref());
44 const Mat<eT>& A = tmp.M;
45
46 const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, tsquared_out, A);
47
48 if(status == false)
49 {
50 coeff_out.reset();
51 score_out.reset();
52 latent_out.reset();
53 tsquared_out.reset();
54
55 arma_bad("princomp(): failed to converge", false);
56 }
57
58 return status;
59 }
60
61
62
63 //! \brief
64 //! principal component analysis -- 3 arguments version
65 //! coeff_out -> principal component coefficients
66 //! score_out -> projected samples
67 //! latent_out -> eigenvalues of principal vectors
68 template<typename T1>
69 inline
70 bool
71 princomp
72 (
73 Mat<typename T1::elem_type>& coeff_out,
74 Mat<typename T1::elem_type>& score_out,
75 Col<typename T1::pod_type>& latent_out,
76 const Base<typename T1::elem_type,T1>& X,
77 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
78 )
79 {
80 arma_extra_debug_sigprint();
81
82 typedef typename T1::elem_type eT;
83
84 const unwrap<T1> tmp(X.get_ref());
85 const Mat<eT>& A = tmp.M;
86
87 const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, A);
88
89 if(status == false)
90 {
91 coeff_out.reset();
92 score_out.reset();
93 latent_out.reset();
94
95 arma_bad("princomp(): failed to converge", false);
96 }
97
98 return status;
99 }
100
101
102
103 //! \brief
104 //! principal component analysis -- 2 arguments version
105 //! coeff_out -> principal component coefficients
106 //! score_out -> projected samples
107 template<typename T1>
108 inline
109 bool
110 princomp
111 (
112 Mat<typename T1::elem_type>& coeff_out,
113 Mat<typename T1::elem_type>& score_out,
114 const Base<typename T1::elem_type,T1>& X,
115 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
116 )
117 {
118 arma_extra_debug_sigprint();
119
120 typedef typename T1::elem_type eT;
121
122 const unwrap<T1> tmp(X.get_ref());
123 const Mat<eT>& A = tmp.M;
124
125 const bool status = op_princomp::direct_princomp(coeff_out, score_out, A);
126
127 if(status == false)
128 {
129 coeff_out.reset();
130 score_out.reset();
131
132 arma_bad("princomp(): failed to converge", false);
133 }
134
135 return status;
136 }
137
138
139
140 //! \brief
141 //! principal component analysis -- 1 argument version
142 //! coeff_out -> principal component coefficients
143 template<typename T1>
144 inline
145 bool
146 princomp
147 (
148 Mat<typename T1::elem_type>& coeff_out,
149 const Base<typename T1::elem_type,T1>& X,
150 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
151 )
152 {
153 arma_extra_debug_sigprint();
154
155 typedef typename T1::elem_type eT;
156
157 const unwrap<T1> tmp(X.get_ref());
158 const Mat<eT>& A = tmp.M;
159
160 const bool status = op_princomp::direct_princomp(coeff_out, A);
161
162 if(status == false)
163 {
164 coeff_out.reset();
165
166 arma_bad("princomp(): failed to converge", false);
167 }
168
169 return status;
170 }
171
172
173
174 template<typename T1>
175 inline
176 const Op<T1, op_princomp>
177 princomp
178 (
179 const Base<typename T1::elem_type,T1>& X,
180 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
181 )
182 {
183 arma_extra_debug_sigprint();
184
185 return Op<T1, op_princomp>(X.get_ref());
186 }
187
188
189
190 //! @}