-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
KernelPCA.h
135 lines (103 loc) · 2.92 KB
/
KernelPCA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Sergey Lisitsyn, Soeren Sonnenburg, Michele Mazzoni,
* Evgeniy Andreev, Evan Shelhamer
*/
#ifndef KERNELPCA_H__
#define KERNELPCA_H__
#include <shogun/lib/config.h>
#include <shogun/features/Features.h>
#include <shogun/kernel/Kernel.h>
#include <shogun/lib/common.h>
#include <shogun/preprocessor/DensePreprocessor.h>
namespace shogun
{
class CFeatures;
class CKernel;
/** @brief Preprocessor KernelPCA performs kernel principal component analysis
*
* Schoelkopf, B., Smola, A. J., & Mueller, K. R. (1999).
* Kernel Principal Component Analysis.
* Advances in kernel methods support vector learning, 1327(3), 327-352. MIT Press.
* Retrieved from http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.32.8744
*
*/
class CKernelPCA : public CPreprocessor
{
public:
/** default constructor
*/
CKernelPCA();
/** constructor
* @param k kernel to be used
*/
CKernelPCA(CKernel* k);
virtual ~CKernelPCA();
virtual void fit(CFeatures* features);
virtual CFeatures* apply(CFeatures* features, bool inplace);
/// cleanup
virtual void cleanup();
virtual SGMatrix<float64_t> apply_to_feature_matrix(CFeatures* features);
/// apply preproc on single feature vector
/// result in feature matrix
virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector);
/** apply to string features
* @param features
*/
virtual CDenseFeatures<float64_t>* apply_to_string_features(CFeatures* features);
/** get transformation matrix, i.e. eigenvectors
*
*/
SGMatrix<float64_t> get_transformation_matrix() const
{
return m_transformation_matrix;
}
/** get bias of KPCA
*
*/
SGVector<float64_t> get_bias_vector() const
{
return m_bias_vector;
}
virtual EFeatureClass get_feature_class();
virtual EFeatureType get_feature_type();
/** @return object name */
virtual const char* get_name() const { return "KernelPCA"; }
/** @return the type of preprocessor */
virtual EPreprocessorType get_type() const { return P_KERNELPCA; }
/** setter for target dimension
* @param dim target dimension
*/
void set_target_dim(int32_t dim);
/** getter for target dimension
* @return target dimension
*/
int32_t get_target_dim() const;
/** setter for kernel
* @param kernel kernel to set
*/
void set_kernel(CKernel* kernel);
/** getter for kernel
* @return kernel
*/
CKernel* get_kernel() const;
protected:
/** default init */
void init();
protected:
/** features used by init. needed for apply */
CFeatures* m_init_features;
/** transformation matrix */
SGMatrix<float64_t> m_transformation_matrix;
/** bias vector */
SGVector<float64_t> m_bias_vector;
/** true when already initialized */
bool m_initialized;
/** target dimension */
int32_t m_target_dim;
/** kernel to be used */
CKernel* m_kernel;
};
}
#endif