PLearn 0.1
ManifoldKNNDistribution.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ManifoldKNNDistribution.h
00004 //
00005 // Copyright (C) 2007 Hugo Larochelle
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 // Authors: Hugo Larochelle
00036 
00040 #ifndef ManifoldKNNDistribution_INC
00041 #define ManifoldKNNDistribution_INC
00042 
00043 #include <plearn_learners/distributions/UnconditionalDistribution.h>
00044 #include <plearn_learners/nearest_neighbors/GenericNearestNeighbors.h>
00045 
00046 namespace PLearn {
00047 
00048 // -*- C++ -*-
00049 
00050 
00055 class ManifoldKNNDistribution : public UnconditionalDistribution
00056 {
00057     typedef UnconditionalDistribution inherited;
00058 
00059 public:
00060     //#####  Public Build Options  ############################################
00061 
00063     PP<GenericNearestNeighbors> knn_manifold;
00064 
00067     PP<GenericNearestNeighbors> knn_density;
00068 
00070     int manifold_dimensionality;
00071     
00074     real min_sigma_square;
00075 
00079     bool center_around_manifold_neighbors;
00080 
00084     bool use_gaussian_distribution;
00085 
00087     PP<PDistribution> density_learner;
00088 
00089 public:
00090     //#####  Public Member Functions  #########################################
00091 
00093     // ### Make sure the implementation in the .cc
00094     // ### initializes all fields to reasonable default values.
00095     ManifoldKNNDistribution();
00096 
00097 
00098     //#####  UnconditionalDistribution Member Functions  ######################
00099 
00101     virtual real log_density(const Vec& x) const;
00102 
00104     virtual real survival_fn(const Vec& y) const;
00105 
00107     virtual real cdf(const Vec& y) const;
00108 
00110     virtual void expectation(Vec& mu) const;
00111 
00113     virtual void variance(Mat& cov) const;
00114 
00116     virtual void generate(Vec& y) const;
00117 
00120     virtual void resetGenerator(long g_seed) const;
00121 
00122     //#####  PLearner Member Functions  #######################################
00123 
00127     virtual void forget();
00128 
00132     virtual void train();
00133 
00134 
00135     //#####  PLearn::Object Protocol  #########################################
00136 
00137     // Declares other standard object methods.
00138     PLEARN_DECLARE_OBJECT(ManifoldKNNDistribution);
00139 
00140     // Simply calls inherited::build() then build_()
00141     virtual void build();
00142 
00144     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00145 
00146 protected:
00147     //#####  Protected Options  ###############################################
00148 
00150     mutable Mat nearest_neighbors_manifold;
00152     mutable Vec nearest_neighbors_manifold_vec;
00154     mutable Mat nearest_neighbors_density;
00156     mutable Vec nearest_neighbors_density_vec;
00158     mutable Mat eig_vectors;
00160     mutable Vec eig_values;
00162     mutable Mat Ut, V;
00164     mutable Vec S;
00166     mutable Vec eig_vectors_projection;
00168     mutable Vec neighbors_mean;
00170     mutable Vec test_minus_mean;
00171 
00173     mutable VMat density_learner_train_set;
00174 
00175 protected:
00176     //#####  Protected Member Functions  ######################################
00177 
00179     static void declareOptions(OptionList& ol);
00180 
00181     void computeLocalPrincipalComponents(const Vec& x, 
00182                                          Vec& eig_values, 
00183                                          Mat& eig_vectors) const;
00184 
00185 private:
00186     //#####  Private Member Functions  ########################################
00187 
00189     void build_();
00190 
00191 private:
00192     //#####  Private Data Members  ############################################
00193 
00194     // The rest of the private stuff goes here
00195 };
00196 
00197 // Declares a few other classes and functions related to this class
00198 DECLARE_OBJECT_PTR(ManifoldKNNDistribution);
00199 
00200 } // end of namespace PLearn
00201 
00202 #endif
00203 
00204 
00205 /*
00206   Local Variables:
00207   mode:c++
00208   c-basic-offset:4
00209   c-file-style:"stroustrup"
00210   c-file-offsets:((innamespace . 0)(inline-open . 0))
00211   indent-tabs-mode:nil
00212   fill-column:79
00213   End:
00214 */
00215 // 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