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