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

SourceKernel.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // SourceKernel.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: SourceKernel.cc,v 1.3 2004/06/25 12:58:22 tihocan Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00043 #include "SourceKernel.h" 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00049 // SourceKernel // 00051 SourceKernel::SourceKernel() 00052 /* ### Initialize all fields to their default value here */ 00053 {} 00054 00055 PLEARN_IMPLEMENT_OBJECT(SourceKernel, 00056 "A kernel built upon an underlying source kernel", 00057 "The default behavior of a SourceKernel is to forward all calls to the underlying\n" 00058 "kernel. However, subclasses will probably want to override the methods to perform\n" 00059 "more complex operations." 00060 ); 00061 00063 // declareOptions // 00065 void SourceKernel::declareOptions(OptionList& ol) 00066 { 00067 declareOption(ol, "source_kernel", &SourceKernel::source_kernel, OptionBase::buildoption, 00068 "The underlying kernel."); 00069 00070 // Now call the parent class' declareOptions 00071 inherited::declareOptions(ol); 00072 } 00073 00075 // build // 00077 void SourceKernel::build() 00078 { 00079 inherited::build(); 00080 build_(); 00081 } 00082 00084 // build_ // 00086 void SourceKernel::build_() 00087 { 00088 this->is_symmetric = source_kernel->is_symmetric; 00089 this->data_inputsize = source_kernel->dataInputsize(); 00090 this->n_examples = source_kernel->nExamples(); 00091 if (specify_dataset) { 00092 // Forward the specified dataset to the underlying kernel, if it is not done already. 00093 if (static_cast<VMatrix*>(specify_dataset) != static_cast<VMatrix*>(source_kernel->specify_dataset)) { 00094 source_kernel->specify_dataset = specify_dataset; 00095 source_kernel->build(); 00096 } 00097 } 00098 } 00099 00101 // addDataForKernelMatrix // 00103 void SourceKernel::addDataForKernelMatrix(const Vec& newRow) { 00104 // By default, this kernel and its source_kernel share the same data. 00105 // Therefore, we must be careful not to append 'newRow' twice. This is 00106 // why we do not call inherited::addDataForKernelMatrix(). 00107 source_kernel->addDataForKernelMatrix(newRow); 00108 } 00109 00111 // computeGramMatrix // 00113 void SourceKernel::computeGramMatrix(Mat K) const { 00114 source_kernel->computeGramMatrix(K); 00115 } 00116 00118 // evaluate // 00120 real SourceKernel::evaluate(const Vec& x1, const Vec& x2) const { 00121 return source_kernel->evaluate(x1, x2); 00122 } 00123 00125 // evaluate_i_j // 00127 real SourceKernel::evaluate_i_j(int i, int j) const { 00128 return source_kernel->evaluate_i_j(i,j); 00129 } 00130 00132 // evaluate_i_x // 00134 real SourceKernel::evaluate_i_x(int i, const Vec& x, real squared_norm_of_x) const { 00135 return source_kernel->evaluate_i_x(i, x, squared_norm_of_x); 00136 } 00137 00139 // evaluate_x_i // 00141 real SourceKernel::evaluate_x_i(const Vec& x, int i, real squared_norm_of_x) const { 00142 return source_kernel->evaluate_x_i(x, i, squared_norm_of_x); 00143 } 00144 00146 // getParameters // 00148 Vec SourceKernel::getParameters() const { 00149 return source_kernel->getParameters(); 00150 } 00151 00153 // makeDeepCopyFromShallowCopy // 00155 void SourceKernel::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00156 { 00157 inherited::makeDeepCopyFromShallowCopy(copies); 00158 deepCopyField(source_kernel, copies); 00159 } 00160 00162 // setDataForKernelMatrix // 00164 void SourceKernel::setDataForKernelMatrix(VMat the_data) { 00165 inherited::setDataForKernelMatrix(the_data); 00166 source_kernel->setDataForKernelMatrix(the_data); 00167 } 00168 00170 // setParameters // 00172 void SourceKernel::setParameters(Vec paramvec) { 00173 source_kernel->setParameters(paramvec); 00174 } 00175 00176 } // end of namespace PLearn 00177

Generated on Tue Aug 17 16:06:12 2004 for PLearn by doxygen 1.3.7