A toolkit for working with phylogenetic data.
v0.24.0
pca.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_MATH_PCA_H_
2 #define GENESIS_UTILS_MATH_PCA_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 Lucas Czech and HITS gGmbH
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 
130  Matrix<double>& data
131 );
132 
155  Matrix<double>& data,
157  size_t max_iterations = 1000
158 );
159 
160 // ================================================================================================
161 // Principal Component Analysis
162 // ================================================================================================
163 
182  Matrix<double> const& data,
183  size_t components = 0,
185 );
186 
187 } // namespace utils
188 } // namespace genesis
189 
190 #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. ...
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Helper stucture that collects the output of principal_component_analysis().
Definition: pca.hpp:95
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:260
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:160
std::vector< double > eigenvalues
Definition: pca.hpp:88
Standardize the mean and variance of the data before performing the PCA.
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.