PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // ThresholdedKernel.h 00004 // 00005 // Copyright (C) 2005 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: ThresholdedKernel.h 4090 2005-09-14 17:48:30Z tihocan $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #ifndef ThresholdedKernel_INC 00045 #define ThresholdedKernel_INC 00046 00047 #include <plearn/ker/SourceKernel.h> 00048 00049 namespace PLearn { 00050 00051 class ThresholdedKernel: public SourceKernel 00052 { 00053 00054 private: 00055 00056 typedef SourceKernel inherited; 00057 00058 protected: 00059 00062 bool knn_approx; 00063 00066 int knn_sub; 00067 00070 int n_approx; 00071 00072 // ********************* 00073 // * Protected options * 00074 // ********************* 00075 00077 Vec knn_kernel_values; 00078 00080 Vec k_x_xi; 00081 00083 Mat k_x_xi_mat; 00084 00086 mutable real k_x_threshold; 00087 00088 public: 00089 00090 // ************************ 00091 // * Public build options * 00092 // ************************ 00093 00094 int knn; 00095 real knn_approximation; 00096 int max_size_for_full_gram; 00097 string method; 00098 real threshold; 00099 00100 // **************** 00101 // * Constructors * 00102 // **************** 00103 00105 ThresholdedKernel(); 00106 00107 // ************************ 00108 // * SourceKernel methods * 00109 // ************************ 00110 00111 private: 00112 00114 void build_(); 00115 00116 protected: 00117 00119 static void declareOptions(OptionList& ol); 00120 00123 virtual void thresholdGramMatrix(const Mat& K) const; 00124 00127 void evaluate_random_k_x_i(const Vec& x, const Vec& k_x_xi) const; 00128 00129 public: 00130 00131 // ************************ 00132 // **** Object methods **** 00133 // ************************ 00134 00136 virtual void build(); 00137 00139 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00140 00141 // Declares other standard object methods. 00142 // If your class is not instantiatable (it has pure virtual methods) 00143 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS. 00144 PLEARN_DECLARE_OBJECT(ThresholdedKernel); 00145 00146 // ****************************** 00147 // **** SourceKernel methods **** 00148 // ****************************** 00149 00151 // The default behavior of a SourceKernel is to forward all calls to the 00152 // underlying kernel. When writing a subclass, you will probably want to 00153 // override the following methods. The only method you really need to implement 00154 // is evaluate(). 00155 virtual real evaluate(const Vec& x1, const Vec& x2) const; 00156 virtual real evaluate_i_j(int i, int j) const; 00157 virtual real evaluate_i_x(int i, const Vec& x, real squared_norm_of_x=-1) const; 00158 virtual real evaluate_x_i(const Vec& x, int i, real squared_norm_of_x=-1) const; 00159 virtual real evaluate_i_x_again(int i, const Vec& x, real squared_norm_of_x=-1, bool first_time = false) const; 00160 virtual real evaluate_x_i_again(const Vec& x, int i, real squared_norm_of_x=-1, bool first_time = false) const; 00161 00164 virtual void computeGramMatrix(Mat K) const; 00165 00167 virtual void setDataForKernelMatrix(VMat the_data); 00168 00169 // You may also want to override these methods if you don't want them 00170 // to be directly forwarded to the underlying kernel. 00171 // virtual void addDataForKernelMatrix(const Vec& newRow); 00172 // virtual void setParameters(Vec paramvec); 00173 // virtual Vec getParameters() const; 00174 00175 }; 00176 00177 // Declares a few other classes and functions related to this class. 00178 DECLARE_OBJECT_PTR(ThresholdedKernel); 00179 00180 } // end of namespace PLearn 00181 00182 #endif 00183 00184 00185 /* 00186 Local Variables: 00187 mode:c++ 00188 c-basic-offset:4 00189 c-file-style:"stroustrup" 00190 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00191 indent-tabs-mode:nil 00192 fill-column:79 00193 End: 00194 */ 00195 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :