comparison armadillo-3.900.4/include/armadillo_bits/fn_princomp.hpp @ 49:1ec0e2823891

Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author Chris Cannam
date Thu, 13 Jun 2013 10:25:24 +0100
parents
children
comparison
equal deleted inserted replaced
48:69251e11a913 49:1ec0e2823891
1 // Copyright (C) 2010-2012 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-2012 Conrad Sanderson
3 // Copyright (C) 2010 Dimitrios Bouzas
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9
10 //! \addtogroup fn_princomp
11 //! @{
12
13
14
15 //! \brief
16 //! principal component analysis -- 4 arguments version
17 //! coeff_out -> principal component coefficients
18 //! score_out -> projected samples
19 //! latent_out -> eigenvalues of principal vectors
20 //! tsquared_out -> Hotelling's T^2 statistic
21 template<typename T1>
22 inline
23 bool
24 princomp
25 (
26 Mat<typename T1::elem_type>& coeff_out,
27 Mat<typename T1::elem_type>& score_out,
28 Col<typename T1::pod_type>& latent_out,
29 Col<typename T1::elem_type>& tsquared_out,
30 const Base<typename T1::elem_type,T1>& X,
31 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
32 )
33 {
34 arma_extra_debug_sigprint();
35 arma_ignore(junk);
36
37 const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, tsquared_out, X);
38
39 if(status == false)
40 {
41 coeff_out.reset();
42 score_out.reset();
43 latent_out.reset();
44 tsquared_out.reset();
45
46 arma_bad("princomp(): failed to converge", false);
47 }
48
49 return status;
50 }
51
52
53
54 //! \brief
55 //! principal component analysis -- 3 arguments version
56 //! coeff_out -> principal component coefficients
57 //! score_out -> projected samples
58 //! latent_out -> eigenvalues of principal vectors
59 template<typename T1>
60 inline
61 bool
62 princomp
63 (
64 Mat<typename T1::elem_type>& coeff_out,
65 Mat<typename T1::elem_type>& score_out,
66 Col<typename T1::pod_type>& latent_out,
67 const Base<typename T1::elem_type,T1>& X,
68 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
69 )
70 {
71 arma_extra_debug_sigprint();
72 arma_ignore(junk);
73
74 const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, X);
75
76 if(status == false)
77 {
78 coeff_out.reset();
79 score_out.reset();
80 latent_out.reset();
81
82 arma_bad("princomp(): failed to converge", false);
83 }
84
85 return status;
86 }
87
88
89
90 //! \brief
91 //! principal component analysis -- 2 arguments version
92 //! coeff_out -> principal component coefficients
93 //! score_out -> projected samples
94 template<typename T1>
95 inline
96 bool
97 princomp
98 (
99 Mat<typename T1::elem_type>& coeff_out,
100 Mat<typename T1::elem_type>& score_out,
101 const Base<typename T1::elem_type,T1>& X,
102 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
103 )
104 {
105 arma_extra_debug_sigprint();
106 arma_ignore(junk);
107
108 const bool status = op_princomp::direct_princomp(coeff_out, score_out, X);
109
110 if(status == false)
111 {
112 coeff_out.reset();
113 score_out.reset();
114
115 arma_bad("princomp(): failed to converge", false);
116 }
117
118 return status;
119 }
120
121
122
123 //! \brief
124 //! principal component analysis -- 1 argument version
125 //! coeff_out -> principal component coefficients
126 template<typename T1>
127 inline
128 bool
129 princomp
130 (
131 Mat<typename T1::elem_type>& coeff_out,
132 const Base<typename T1::elem_type,T1>& X,
133 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
134 )
135 {
136 arma_extra_debug_sigprint();
137 arma_ignore(junk);
138
139 const bool status = op_princomp::direct_princomp(coeff_out, X);
140
141 if(status == false)
142 {
143 coeff_out.reset();
144
145 arma_bad("princomp(): failed to converge", false);
146 }
147
148 return status;
149 }
150
151
152
153 template<typename T1>
154 inline
155 const Op<T1, op_princomp>
156 princomp
157 (
158 const Base<typename T1::elem_type,T1>& X,
159 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
160 )
161 {
162 arma_extra_debug_sigprint();
163 arma_ignore(junk);
164
165 return Op<T1, op_princomp>(X.get_ref());
166 }
167
168
169
170 //! @}