Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

KernelPCA.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // KernelPCA.cc 00004 // 00005 // Copyright (C) 2004 Olivier Delalleau 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: KernelPCA.cc,v 1.7 2004/07/21 16:30:59 chrish42 Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00043 #include <plearn/ker/AdditiveNormalizationKernel.h> 00044 #include "KernelPCA.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00050 // KernelPCA // 00052 KernelPCA::KernelPCA() 00053 : kernel_is_distance(false), 00054 remove_bias(false), 00055 remove_bias_in_evaluate(false) 00056 { 00057 // Usually, one will want only positive eigenvalues. 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 // declareOptions // 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 // Now call the parent class' declareOptions 00085 inherited::declareOptions(ol); 00086 00087 // Redirect the 'kernel' option toward kpca_kernel. 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 // And declare the normalized kernel so that it can be saved. 00095 declareOption(ol, "normalized_kernel", &KernelProjection::kernel, OptionBase::learntoption, 00096 "The normalized kernel."); 00097 00098 } 00099 00101 // build // 00103 void KernelPCA::build() 00104 { 00105 inherited::build(); 00106 build_(); 00107 } 00108 00110 // build_ // 00112 void KernelPCA::build_() 00113 { 00114 // Obtain the "real" kernel by additive normalization of 'kpca_kernel'. 00115 // We have to do this iff: 00116 // 1. A 'kpca_kernel' is provided, and 00117 // 2. either: 00118 // 2.a. the 'kernel' option is not set, or 00119 // 2.b. the 'kernel' option is not an AdditiveNormalization acting on 'kpca_kernel'. 00120 // This is to ensure that a loaded 'kernel' won't be overwritten. 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 // forget // 00132 void KernelPCA::forget() 00133 { 00134 inherited::forget(); 00135 } 00136 00138 // makeDeepCopyFromShallowCopy // 00140 void KernelPCA::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00141 { 00142 inherited::makeDeepCopyFromShallowCopy(copies); 00143 00144 // ### Call deepCopyField on all "pointer-like" fields 00145 // ### that you wish to be deepCopied rather than 00146 // ### shallow-copied. 00147 // ### ex: 00148 // deepCopyField(trainvec, copies); 00149 00150 // ### Remove this line when you have fully implemented this method. 00151 PLERROR("KernelPCA::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00152 } 00153 00154 } // end of namespace PLearn 00155

Generated on Tue Aug 17 15:56:28 2004 for PLearn by doxygen 1.3.7