PLearn 0.1
ReconstructionWeightsKernel.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ReconstructionWeightsKernel.h
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: ReconstructionWeightsKernel.h 9436 2008-09-04 18:48:55Z nouiz $ 
00037  ******************************************************* */
00038 
00039 // Authors: Olivier Delalleau
00040 
00044 #ifndef ReconstructionWeightsKernel_INC
00045 #define ReconstructionWeightsKernel_INC
00046 
00047 #include "Kernel.h"
00048 #include <plearn/vmat/SelectRowsVMatrix.h>
00049 #include <plearn/vmat/ShiftAndRescaleVMatrix.h>
00050 
00051 namespace PLearn {
00052 using namespace std;
00053 
00054 class ReconstructionWeightsKernel: public Kernel
00055 {
00056 
00057 private:
00058 
00059     typedef Kernel inherited;
00060 
00062     bool build_in_progress;
00063 
00067     mutable bool new_data;
00068 
00071     mutable Mat k_xi_x_sorted;
00072 
00074     mutable TVec<int> neighbors_of_x;
00075 
00077     mutable Vec weights_x;
00078 
00080     mutable Mat local_gram;
00081   
00083     mutable PP<ShiftAndRescaleVMatrix> centered_neighborhood;
00084 
00086     mutable Vec ones;
00087 
00088 protected:
00089 
00090     // *********************
00091     // * Protected options *
00092     // *********************
00093 
00094     // Fields below are not options.
00095 
00098     Ker dist_ker;
00099 
00102     Ker dp_ker;
00103     
00105     TMat<int> neighbors;
00106 
00111     TVec< TMat<int> > is_neighbor_of;
00112 
00114     PP<SelectRowsVMatrix> sub_data;
00115 
00117     Mat weights;
00118 
00119 public:
00120 
00121     // ************************
00122     // * Public build options *
00123     // ************************
00124 
00125     Ker distance_kernel;
00126     Ker dot_product_kernel;
00127     int ignore_nearest;
00128     int knn;
00129     real regularizer;
00130 
00131     // ****************
00132     // * Constructors *
00133     // ****************
00134 
00136     ReconstructionWeightsKernel();
00137 
00138     // ******************
00139     // * Kernel methods *
00140     // ******************
00141 
00142 private: 
00143 
00145     void build_();
00146 
00147 protected: 
00148   
00150     static void declareOptions(OptionList& ol);
00151 
00152 public:
00153 
00154     // ************************
00155     // **** Object methods ****
00156     // ************************
00157 
00159     virtual void build();
00160 
00162     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00163 
00164     // Declares other standard object methods.
00165     PLEARN_DECLARE_OBJECT(ReconstructionWeightsKernel);
00166 
00167     // **************************
00168     // **** Kernel methods ****
00169     // **************************
00170 
00172     virtual real evaluate(const Vec& x1, const Vec& x2) const;
00173 
00174     virtual real evaluate_i_j(int i, int j) const;
00175 
00176     virtual real evaluate_i_x(int i, const Vec& x, real squared_norm_of_x=-1) const;
00177 
00178     virtual real evaluate_x_i(const Vec& x, int i, real squared_norm_of_x=-1) const;
00179 
00180     virtual real evaluate_x_i_again(const Vec& x, int i, real squared_norm_of_x=-1, bool first_time = false) const;
00181 
00182     virtual void setDataForKernelMatrix(VMat the_data);
00183 
00185     virtual real evaluate_sum_k_i_k_j(int i, int j) const;
00186 
00190     virtual void computeLLEMatrix(const Mat& lle_mat) const;
00191 
00192     // *** SUBCLASS WRITING: ***
00193     // While in general not necessary, in case of particular needs 
00194     // (efficiency concerns for ex) you may also want to overload
00195     // some of the following methods:
00196     // virtual real evaluate_i_x_again(int i, const Vec& x, real squared_norm_of_x=-1, bool first_time = false) const;
00197     // virtual void computeGramMatrix(Mat K) const;
00198     // virtual void addDataForKernelMatrix(const Vec& newRow);
00199     // virtual void setParameters(Vec paramvec);
00200     // virtual Vec getParameters() const;
00201 
00202 protected:
00203 
00205     void computeWeights();
00206   
00208     void reconstruct(const Vec& x, const TVec<int>& neighbors, Vec& w) const;
00209 
00210 };
00211 
00212 // Declares a few other classes and functions related to this class.
00213 DECLARE_OBJECT_PTR(ReconstructionWeightsKernel);
00214   
00215 } // end of namespace PLearn
00216 
00217 #endif
00218 
00219 
00220 /*
00221   Local Variables:
00222   mode:c++
00223   c-basic-offset:4
00224   c-file-style:"stroustrup"
00225   c-file-offsets:((innamespace . 0)(inline-open . 0))
00226   indent-tabs-mode:nil
00227   fill-column:79
00228   End:
00229 */
00230 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines