#include <principalcomponentanalysis.h>
template<Numeric NumericType>
class Cosan::PrincipalComponentAnalysis< NumericType >
https://en.wikipedia.org/wiki/Principal_component_analysis
Definition at line 16 of file principalcomponentanalysis.h.
◆ PrincipalComponentAnalysis() [1/4]
template<Numeric NumericType>
◆ PrincipalComponentAnalysis() [2/4]
template<Numeric NumericType>
Definition at line 19 of file principalcomponentanalysis.h.
19 :Preprocessor<NumericType>(){
20 ncom = std::min(ncom,RD.GetcolsX());
21 this->
fit(RD.GetInput(),ncom);
◆ PrincipalComponentAnalysis() [3/4]
template<Numeric NumericType>
Definition at line 23 of file principalcomponentanalysis.h.
23 :Preprocessor<NumericType>(){
24 ncom = std::min(ncom,RD.GetcolsX());
25 this->
fit(RD.GetInput(),ncom);
◆ PrincipalComponentAnalysis() [4/4]
template<Numeric NumericType>
◆ fit()
template<Numeric NumericType>
Definition at line 37 of file principalcomponentanalysis.h.
38 fmt::print(
"*********************************\n");
39 fmt::print(
"Begin PCA on Input Data X. Select the first {:} principal components\n",ncom);
40 CosanMatrix<NumericType> centered = X.rowwise() - X.colwise().mean();
41 CosanMatrix<NumericType> cov = centered.adjoint() * centered;
43 Eigen::SelfAdjointEigenSolver<CosanMatrix<NumericType>> eigensolver(cov);
44 if (eigensolver.info() != Eigen::Success) {
45 throw std::invalid_argument(
"Cannot solve eigenvalue decomposition.");}
47 std::vector<NumericType>
vec(eigensolver.eigenvalues().data(), eigensolver.eigenvalues().data() + eigensolver.eigenvalues().size());
48 std::reverse(
vec.begin(),
vec.end());
49 std::vector<NumericType> runningSum(
vec.size());
50 std::partial_sum(
vec.begin(),
vec.end(), runningSum.begin());
51 for (gsl::index i =0;i<runningSum.size();i++){
52 fmt::print(
"The first {:} principal components explains {:f}% of the total variance.\n",i,runningSum[i]/runningSum.back()*100);
53 if (runningSum[i]/runningSum.back()>0.98 and i>=8){
60 fmt::print(
"Finsh PCA on Input Data X. The first {:} principal components explains {:f}% of the total variance.\n",ncom,runningSum[ncom]/runningSum.back()*100);
61 fmt::print(
"Uer .GetPC() function to get the principal components.\n" );
62 fmt::print(
"*********************************\n");
◆ GetPC()
template<Numeric NumericType>
◆ FullComponent
template<Numeric NumericType>
◆ PrincipalComponent
template<Numeric NumericType>
The documentation for this class was generated from the following file: