A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pca.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_MATH_MATRIX_PCA_H_
2 #define GENESIS_UTILS_MATH_MATRIX_PCA_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
35 
36 #include <vector>
37 
38 namespace genesis {
39 namespace utils {
40 
41 // ================================================================================================
42 // Settings for Functions
43 // ================================================================================================
44 
50 {
59 
68 
75  kSSCP
76 };
77 
78 // ================================================================================================
79 // Structs for Storing Results
80 // ================================================================================================
81 
87 {
88  std::vector<double> eigenvalues;
89  std::vector<double> intermediates;
90 };
91 
95 struct PcaData
96 {
97  std::vector<double> eigenvalues;
100 };
101 
102 // ================================================================================================
103 // Helper Functions
104 // ================================================================================================
105 
129  Matrix<double>& data
130 );
131 
154  Matrix<double>& data,
156  size_t max_iterations = 1000
157 );
158 
159 // ================================================================================================
160 // Principal Component Analysis
161 // ================================================================================================
162 
181  Matrix<double> const& data,
182  size_t components = 0,
184 );
185 
186 } // namespace utils
187 } // namespace genesis
188 
189 #endif // include guard
std::vector< double > eigenvalues
Definition: pca.hpp:97
std::vector< double > intermediates
Definition: pca.hpp:89
Standardize the mean, but not the variance of the data before performing the PCA. ...
Helper stucture that collects the output of principal_component_analysis().
Definition: pca.hpp:95
Matrix< double > eigenvectors
Definition: pca.hpp:98
TridiagonalDecompositionData reduce_to_tridiagonal_matrix(Matrix< double > &data)
Triangular decomposition of a symmetric matrix.
Definition: pca.cpp:49
Matrix< double > projection
Definition: pca.hpp:99
PcaStandardization
Setting for principal_component_analysis() to determine which form of standardization of the data to ...
Definition: pca.hpp:49
void tridiagonal_ql_algorithm(Matrix< double > &data, TridiagonalDecompositionData &tri, size_t max_iterations)
Reduce a symmetric matrix to a symmetric tridiagonal matrix.
Definition: pca.cpp:150
std::vector< double > eigenvalues
Definition: pca.hpp:88
Standardize the mean and variance of the data before performing the PCA.
PcaData principal_component_analysis(Matrix< double > const &data, size_t components, PcaStandardization standardization)
Perfom a Principal Component Analysis on a given data Matrix.
Definition: pca.cpp:242
Helper structure used for the eigenvalue decomposition in reduce_to_tridiagonal_matrix() and tridiago...
Definition: pca.hpp:86
Do not perform any standardization prior to performing the PCA.