00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00043
#include <plearn/ker/AdditiveNormalizationKernel.h>
00044
#include "KernelPCA.h"
00045
00046
namespace PLearn {
00047
using namespace std;
00048
00050
00052 KernelPCA::KernelPCA()
00053 : kernel_is_distance(false),
00054 remove_bias(false),
00055 remove_bias_in_evaluate(false)
00056 {
00057
00058 min_eigenvalue = 0;
00059 }
00060
00061
PLEARN_IMPLEMENT_OBJECT(
KernelPCA,
00062
"Kernel Principal Component Analysis",
00063
"Perform PCA in a feature space phi(x), defined by a kernel K such that\n"
00064
" K(x,y) = < phi(x), phi(y) >\n"
00065 );
00066
00068
00070 void KernelPCA::declareOptions(
OptionList& ol)
00071 {
00072
declareOption(ol,
"kernel_is_distance", &KernelPCA::kernel_is_distance, OptionBase::buildoption,
00073
"If set to 1, then the kernel will be considered as a squared distance instead of\n"
00074
"a dot product (i.e. the double-centering formula will be applied).");
00075
00076
declareOption(ol,
"remove_bias", &KernelPCA::remove_bias, OptionBase::buildoption,
00077
"If set to 1, the (additively) normalized kernel will not take into account terms\n"
00078
"of the form K(x_i,x_i), in order to remove bias induced by those terms.");
00079
00080
declareOption(ol,
"remove_bias_in_evaluate", &KernelPCA::remove_bias_in_evaluate, OptionBase::buildoption,
00081
"If set to 1, the (additively) normalized kernel will not take into account terms\n"
00082
"of the form K(x_i,x_i), but only when evaluated on test points.");
00083
00084
00085 inherited::declareOptions(ol);
00086
00087
00088
redeclareOption(ol,
"kernel", &KernelPCA::kpca_kernel, OptionBase::buildoption,
00089
"The kernel used to (implicitly) project the data in feature space.");
00090
00091
redeclareOption(ol,
"ignore_n_first", &KernelPCA::ignore_n_first, OptionBase::nosave,
00092
"In KernelPCA, no eigenvector is ignored.");
00093
00094
00095
declareOption(ol,
"normalized_kernel", &KernelProjection::kernel, OptionBase::learntoption,
00096
"The normalized kernel.");
00097
00098 }
00099
00101
00103 void KernelPCA::build()
00104 {
00105 inherited::build();
00106
build_();
00107 }
00108
00110
00112 void KernelPCA::build_()
00113 {
00114
00115
00116
00117
00118
00119
00120
00121
if (
kpca_kernel &&
00122 (!kernel ||
00123 (dynamic_cast<AdditiveNormalizationKernel*>((
Kernel*) kernel))->source_kernel !=
kpca_kernel)) {
00124 this->kernel =
new AdditiveNormalizationKernel
00125 (
kpca_kernel,
remove_bias,
remove_bias_in_evaluate,
kernel_is_distance);
00126 }
00127 }
00128
00130
00132 void KernelPCA::forget()
00133 {
00134 inherited::forget();
00135 }
00136
00138
00140 void KernelPCA::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00141 {
00142 inherited::makeDeepCopyFromShallowCopy(copies);
00143
00144
00145
00146
00147
00148
00149
00150
00151
PLERROR(
"KernelPCA::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00152 }
00153
00154 }
00155