3643 |
10 May 17 |
peter |
1 |
#ifndef _theplu_yat_utility_kernel_pca_ |
3643 |
10 May 17 |
peter |
2 |
#define _theplu_yat_utility_kernel_pca_ |
2324 |
21 Sep 10 |
peter |
3 |
|
2324 |
21 Sep 10 |
peter |
// $Id$ |
2324 |
21 Sep 10 |
peter |
5 |
|
2324 |
21 Sep 10 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2010, 2022 Peter Johansson |
2324 |
21 Sep 10 |
peter |
8 |
|
2324 |
21 Sep 10 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2324 |
21 Sep 10 |
peter |
10 |
|
2324 |
21 Sep 10 |
peter |
The yat library is free software; you can redistribute it and/or |
2324 |
21 Sep 10 |
peter |
modify it under the terms of the GNU General Public License as |
2324 |
21 Sep 10 |
peter |
published by the Free Software Foundation; either version 3 of the |
2324 |
21 Sep 10 |
peter |
License, or (at your option) any later version. |
2324 |
21 Sep 10 |
peter |
15 |
|
2324 |
21 Sep 10 |
peter |
The yat library is distributed in the hope that it will be useful, |
2324 |
21 Sep 10 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2324 |
21 Sep 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2324 |
21 Sep 10 |
peter |
General Public License for more details. |
2324 |
21 Sep 10 |
peter |
20 |
|
2324 |
21 Sep 10 |
peter |
You should have received a copy of the GNU General Public License |
2324 |
21 Sep 10 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2324 |
21 Sep 10 |
peter |
23 |
*/ |
2324 |
21 Sep 10 |
peter |
24 |
|
2324 |
21 Sep 10 |
peter |
25 |
namespace theplu { |
2324 |
21 Sep 10 |
peter |
26 |
namespace yat { |
2324 |
21 Sep 10 |
peter |
27 |
namespace utility { |
2324 |
21 Sep 10 |
peter |
28 |
|
2324 |
21 Sep 10 |
peter |
29 |
class Matrix; |
4125 |
14 Jan 22 |
peter |
30 |
class MatrixBase; |
2324 |
21 Sep 10 |
peter |
31 |
class Vector; |
2324 |
21 Sep 10 |
peter |
32 |
|
2324 |
21 Sep 10 |
peter |
33 |
/** |
2324 |
21 Sep 10 |
peter |
\brief Principal Component Analysis on a Kernel Matrix |
2324 |
21 Sep 10 |
peter |
35 |
|
2324 |
21 Sep 10 |
peter |
This class performs PCA on a kernel matrix. Note that this class |
2324 |
21 Sep 10 |
peter |
does not diagonalize the kernel matrix to find eigen-samples that |
2324 |
21 Sep 10 |
peter |
maximizes the variance (use class SVD). Instead, this class finds |
2324 |
21 Sep 10 |
peter |
eigen-features that maximizes the variance in feature space and |
2324 |
21 Sep 10 |
peter |
projects the data onto these eigen-features. |
2324 |
21 Sep 10 |
peter |
41 |
|
2324 |
21 Sep 10 |
peter |
As the covariance of features is not available nor is the data, |
2324 |
21 Sep 10 |
peter |
we create a data matrix Z that fulfills Kernel = Z' * Z. As this |
2324 |
21 Sep 10 |
peter |
data matrix Z has the same kernel matrix as the original data and |
2324 |
21 Sep 10 |
peter |
thus also same distances between each pair of sample, the |
2324 |
21 Sep 10 |
peter |
difference between Z and original data matrix is at most a |
2324 |
21 Sep 10 |
peter |
rotation and translation. Hence, the projection of Z onto the |
2324 |
21 Sep 10 |
peter |
first principial components will be equivalent to the projection |
2324 |
21 Sep 10 |
peter |
of original data onto its principal components. |
2324 |
21 Sep 10 |
peter |
50 |
|
2324 |
21 Sep 10 |
peter |
\see PCA |
2324 |
21 Sep 10 |
peter |
52 |
|
2324 |
21 Sep 10 |
peter |
\since New in yat 0.7 |
2324 |
21 Sep 10 |
peter |
54 |
*/ |
2324 |
21 Sep 10 |
peter |
55 |
class KernelPCA |
2324 |
21 Sep 10 |
peter |
56 |
{ |
2324 |
21 Sep 10 |
peter |
57 |
public: |
2324 |
21 Sep 10 |
peter |
58 |
/** |
2324 |
21 Sep 10 |
peter |
Constructor taking the kernel matrix as input. \a kernel is |
2324 |
21 Sep 10 |
peter |
expected to be symmetric and positive semi-definite. |
2324 |
21 Sep 10 |
peter |
61 |
|
2324 |
21 Sep 10 |
peter |
The \a kernel matrix contains the scalar product between all |
2324 |
21 Sep 10 |
peter |
samples, i.e., element kernel(i,j) is the scalar product |
2324 |
21 Sep 10 |
peter |
between sample i and sample j. |
2324 |
21 Sep 10 |
peter |
65 |
*/ |
4125 |
14 Jan 22 |
peter |
66 |
explicit KernelPCA(const MatrixBase& kernel); |
3643 |
10 May 17 |
peter |
67 |
|
2324 |
21 Sep 10 |
peter |
68 |
/** |
2324 |
21 Sep 10 |
peter |
\brief destructor |
2324 |
21 Sep 10 |
peter |
70 |
*/ |
2324 |
21 Sep 10 |
peter |
71 |
virtual ~KernelPCA(void); |
2324 |
21 Sep 10 |
peter |
72 |
|
2324 |
21 Sep 10 |
peter |
73 |
/** |
2324 |
21 Sep 10 |
peter |
\brief sorted eigenvalues. |
2324 |
21 Sep 10 |
peter |
75 |
|
2324 |
21 Sep 10 |
peter |
\return eigenvalues sorted such eignenvalues(0) is the largest value |
2324 |
21 Sep 10 |
peter |
77 |
*/ |
2324 |
21 Sep 10 |
peter |
78 |
const Vector& eigenvalues(void) const; |
2324 |
21 Sep 10 |
peter |
79 |
|
2324 |
21 Sep 10 |
peter |
80 |
/** |
2324 |
21 Sep 10 |
peter |
This function will project data onto the new coordinate-system. |
2324 |
21 Sep 10 |
peter |
82 |
|
2324 |
21 Sep 10 |
peter |
Each column corresponds to a sample. |
2324 |
21 Sep 10 |
peter |
84 |
*/ |
2324 |
21 Sep 10 |
peter |
85 |
const Matrix& projection(void) const; |
2324 |
21 Sep 10 |
peter |
86 |
|
2324 |
21 Sep 10 |
peter |
87 |
private: |
2324 |
21 Sep 10 |
peter |
88 |
class Impl; |
2324 |
21 Sep 10 |
peter |
89 |
Impl* impl_; |
2324 |
21 Sep 10 |
peter |
90 |
}; |
2324 |
21 Sep 10 |
peter |
91 |
|
2324 |
21 Sep 10 |
peter |
92 |
}}} // of namespace utility, yat, and theplu |
2324 |
21 Sep 10 |
peter |
93 |
|
2324 |
21 Sep 10 |
peter |
94 |
#endif |