philsupertramp/game-math
Loading...
Searching...
No Matches
include
math
ds
decomposition
PCA.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "../../numerics/lin_alg/svd.h"
4
#include "../Predictor.h"
5
6
class
PCA
:
public
Transformer
7
{
8
public
:
9
Matrix<double>
PCs
;
10
Matrix<double>
right
;
11
int
keep_components
;
12
13
public
:
14
PCA
(
int
k_components = 0)
15
:
Transformer
()
16
,
keep_components
(k_components) { }
17
18
void
fit
(
const
Matrix<double>
& X,
const
Matrix<double>
& y)
override
{
19
auto
res =
svd
(X,
keep_components
);
20
PCs
= res[0] * res[1];
21
right
= res[2];
22
}
23
Matrix<double>
transform
(
const
Matrix<double>
& in)
override
{
return
in *
PCs
; }
24
};
Matrix
Definition:
Matrix.h:42
PCA
Definition:
PCA.h:7
PCA::PCs
Matrix< double > PCs
Definition:
PCA.h:9
PCA::keep_components
int keep_components
Definition:
PCA.h:11
PCA::fit
void fit(const Matrix< double > &X, const Matrix< double > &y) override
Definition:
PCA.h:18
PCA::PCA
PCA(int k_components=0)
Definition:
PCA.h:14
PCA::right
Matrix< double > right
Definition:
PCA.h:10
PCA::transform
Matrix< double > transform(const Matrix< double > &in) override
Definition:
PCA.h:23
Transformer
Definition:
Predictor.h:30
svd
std::vector< Matrix< double > > svd(const Matrix< double > &A, const size_t &k, const double epsilon=0.1e-4)
Definition:
svd.h:14
Generated by
1.9.5