PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // NonLocalManifoldParzen.h 00004 // 00005 // Copyright (C) 2004 Yoshua Bengio & 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 /* ******************************************************* 00036 * $Id: NonLocalManifoldParzen.h 8172 2007-10-10 22:41:33Z larocheh $ 00037 ******************************************************* */ 00038 00039 // Authors: Yoshua Bengio & Hugo Larochelle 00040 00044 #ifndef NonLocalManifoldParzen_INC 00045 #define NonLocalManifoldParzen_INC 00046 00047 #include "UnconditionalDistribution.h" 00048 #include <plearn/io/PStream.h> 00049 #include <plearn_learners/generic/PLearner.h> 00050 #include <plearn/var/Func.h> 00051 #include <plearn/opt/Optimizer.h> 00052 #include <plearn_learners/distributions/PDistribution.h> 00053 #include <plearn/ker/DistanceKernel.h> 00054 00055 namespace PLearn { 00056 using namespace std; 00057 00058 class NonLocalManifoldParzen: public UnconditionalDistribution 00059 { 00060 00061 private: 00062 00063 typedef UnconditionalDistribution inherited; 00064 00065 protected: 00066 00067 // ********************* 00068 // * protected options * 00069 // ********************* 00070 00072 int L; 00074 real log_L; 00076 Func cost_of_one_example; 00078 Var x; 00080 Var W, V, muV, snV; 00082 Var tangent_targets; 00085 Var components; 00087 Var mu; 00089 Var sn; 00091 Var sum_nll; 00093 Var min_sig; 00095 Var init_sig; 00097 Func predictor; // predicts everything about the gaussian 00098 00100 mutable Mat U_temp, F, distances; 00102 mutable Vec mu_temp,sm_temp,sn_temp,diff,z, x_minus_neighbor, 00103 t_row, neighbor_row, log_gauss,t_dist; 00105 mutable TVec<int> t_nn; 00107 mutable DistanceKernel dk; 00108 00110 mutable Mat Ut_svd, V_svd; 00112 mutable Vec S_svd; 00113 00115 Mat mus; 00117 Vec sns; 00119 Mat sms; 00121 TVec<Mat> Fs; 00122 00124 VMat train_set_with_targets; 00126 VMat targets_vmat; 00128 Var totalcost; 00130 int nsamples; 00131 00133 Vec paramsvalues; 00134 00135 public: 00136 00137 // ************************ 00138 // * public build options * 00139 // ************************ 00140 00141 // ** General parameters ** 00142 00144 VarArray parameters; 00146 VMat reference_set; 00148 int ncomponents; 00150 int nneighbors; 00152 int nneighbors_density; 00154 bool store_prediction; 00155 00156 // ** Gaussian kernel options ** 00157 00159 bool learn_mu; 00161 real sigma_init; 00163 real sigma_min; 00165 int mu_nneighbors; 00167 real sigma_threshold_factor; 00169 real svd_threshold; 00170 00171 // ** Neural network predictor option ** 00172 00174 int nhidden; 00176 real weight_decay; 00178 string penalty_type; 00180 PP<Optimizer> optimizer; 00182 int batch_size; 00183 00184 // **************** 00185 // * Constructors * 00186 // **************** 00187 00189 NonLocalManifoldParzen(); 00190 00191 // ******************** 00192 // * PLearner methods * 00193 // ******************** 00194 00195 private: 00196 00198 void build_(); 00199 00200 //void update_reference_set_parameters(); 00201 00205 void knn(const VMat& vm, const Vec& x, const int& k, TVec<int>& neighbors, bool sortk) const; 00206 00207 protected: 00208 00210 static void declareOptions(OptionList& ol); 00211 00212 virtual void initializeParams(); 00213 00214 public: 00215 00216 // ************************ 00217 // **** Object methods **** 00218 // ************************ 00219 00221 virtual void build(); 00222 00225 virtual void forget(); 00226 00228 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00229 00230 // Declares other standard object methods. 00231 // If your class is not instantiatable (it has pure virtual methods) 00232 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS. 00233 PLEARN_DECLARE_OBJECT(NonLocalManifoldParzen); 00234 00235 // ******************************* 00236 // **** PDistribution methods **** 00237 // ******************************* 00238 00240 virtual real log_density(const Vec& x) const; 00241 00244 virtual void train(); 00245 00246 /* Not implemented for now 00248 virtual void expectation(Vec& mu) const; 00249 00251 virtual void variance(Mat& cov) const; 00252 00254 virtual void generate(Vec& y) const; 00255 00257 virtual void resetGenerator(long g_seed); 00258 */ 00259 00261 virtual void computeOutput(const Vec& input, Vec& output) const; 00262 00264 virtual int outputsize() const; 00265 00266 /* Not needed anymore 00269 virtual int outputsize() const; 00270 */ 00271 00272 00273 // *** SUBCLASS WRITING: *** 00274 // While in general not necessary, in case of particular needs 00275 // (efficiency concerns for ex) you may also want to overload 00276 // some of the following methods: 00277 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00278 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00279 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00280 // virtual int nTestCosts() const; 00281 // virtual int nTrainCosts() const; 00282 00283 //Mat getEigenvectors(int j) const; 00284 //Vec getTrainPoint(int j) const; 00285 }; 00286 00287 // Declares a few other classes and functions related to this class. 00288 DECLARE_OBJECT_PTR(NonLocalManifoldParzen); 00289 00290 } // end of namespace PLearn 00291 00292 #endif 00293 00294 00295 /* 00296 Local Variables: 00297 mode:c++ 00298 c-basic-offset:4 00299 c-file-style:"stroustrup" 00300 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00301 indent-tabs-mode:nil 00302 fill-column:79 00303 End: 00304 */ 00305 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :