PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // DeepNonLocalManifoldParzen.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 DeepNonLocalManifoldParzen_INC 00041 #define DeepNonLocalManifoldParzen_INC 00042 00043 #include <plearn/vmat/ClassSubsetVMatrix.h> 00044 #include <plearn_learners/generic/PLearner.h> 00045 #include <plearn_learners/online/OnlineLearningModule.h> 00046 #include <plearn_learners/online/CostModule.h> 00047 #include <plearn_learners/online/NLLCostModule.h> 00048 #include <plearn_learners/online/RBMClassificationModule.h> 00049 #include <plearn_learners/online/RBMLayer.h> 00050 #include <plearn_learners/online/RBMMixedLayer.h> 00051 #include <plearn_learners/online/RBMConnection.h> 00052 #include <plearn/misc/PTimer.h> 00053 00054 namespace PLearn { 00055 00060 class DeepNonLocalManifoldParzen : public PLearner 00061 { 00062 typedef PLearner inherited; 00063 00064 public: 00065 //##### Public Build Options ############################################ 00066 00068 real cd_learning_rate; 00069 00071 real cd_decrease_ct; 00072 00074 real greedy_learning_rate; 00075 00079 real greedy_decrease_ct; 00080 00082 real fine_tuning_learning_rate; 00083 00086 real fine_tuning_decrease_ct; 00087 00090 TVec<int> training_schedule; 00091 00093 mutable TVec< PP<RBMLayer> > layers; 00094 00096 mutable TVec< PP<RBMConnection> > connections; 00097 00099 mutable TVec< PP<RBMConnection> > reconstruction_connections; 00100 00103 int k_neighbors; 00104 00106 int n_components; 00107 00109 real min_sigma_noise; 00110 00112 int n_classes; 00113 00115 bool train_one_network_per_class; 00116 00118 real output_connections_l1_penalty_factor; 00119 00121 real output_connections_l2_penalty_factor; 00122 00125 bool save_manifold_parzen_parameters; 00126 00128 bool do_not_learn_sigma_noise; 00129 00132 bool use_test_centric_nlmp; 00133 00134 //##### Public Learnt Options ########################################### 00135 00137 int n_layers; 00138 00139 public: 00140 //##### Public Member Functions ######################################### 00141 00143 DeepNonLocalManifoldParzen(); 00144 00145 //##### PLearner Member Functions ####################################### 00146 00149 virtual int outputsize() const; 00150 00154 virtual void forget(); 00155 00159 virtual void train(); 00160 00162 virtual void computeOutput(const Vec& input, Vec& output) const; 00163 00165 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00166 const Vec& target, Vec& costs) const; 00167 00172 virtual void updateManifoldParzenParameters() const; 00173 00176 virtual TVec<std::string> getTestCostNames() const; 00177 00180 virtual TVec<std::string> getTrainCostNames() const; 00181 00189 virtual void setTrainingSet(VMat training_set, bool call_forget=true); 00190 00191 void greedyStep( const Vec& input, const Vec& target, int index, 00192 Vec train_costs, int stage); 00193 00194 void fineTuningStep( const Vec& input, const Vec& target, 00195 Vec& train_costs, Mat nearest_neighbors); 00196 00197 void computeRepresentation( const Vec& input, 00198 Vec& representation, int layer) const; 00199 00200 void computeManifoldParzenParameters( const Vec& input, 00201 Mat& F, Vec& mu, Vec& pre_sigma_noise, 00202 Mat& U, Vec& sm_svd, 00203 int target_class = -1) const; 00204 00205 00206 //##### PLearn::Object Protocol ######################################### 00207 00208 // Declares other standard object methods. 00209 // ### If your class is not instantiatable (it has pure virtual methods) 00210 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00211 PLEARN_DECLARE_OBJECT(DeepNonLocalManifoldParzen); 00212 00213 // Simply calls inherited::build() then build_() 00214 virtual void build(); 00215 00217 // (PLEASE IMPLEMENT IN .cc) 00218 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00219 00220 protected: 00221 //##### Not Options ##################################################### 00222 00225 mutable TVec<Vec> activations; 00226 00229 mutable TVec<Vec> expectations; 00230 00234 mutable TVec<Vec> activation_gradients; 00235 00239 mutable TVec<Vec> expectation_gradients; 00240 00242 mutable Vec reconstruction_activations; 00243 00245 mutable Vec reconstruction_activation_gradients; 00246 00248 mutable Vec reconstruction_expectation_gradients; 00249 00251 mutable PP<OnlineLearningModule> output_connections; 00252 00254 mutable TVec< TVec< PP<RBMLayer> > > all_layers; 00255 mutable TVec< TVec<PP<RBMConnection> > > all_connections; 00256 mutable TVec< TVec<PP<RBMConnection> > > all_reconstruction_connections; 00257 mutable TVec< PP<OnlineLearningModule> > all_output_connections; 00258 00260 mutable Vec input_representation; 00261 00263 Vec previous_input_representation; 00264 00266 mutable Vec all_outputs; 00267 00269 Vec all_outputs_gradient; 00270 00272 mutable Mat F, F_copy; 00273 mutable Vec mu; 00274 mutable Vec pre_sigma_noise; 00275 00277 mutable Mat Ut, U, V, z, inv_Sigma_F, inv_Sigma_z; 00278 mutable Vec temp_ncomp, diff_neighbor_input, sm_svd, S; 00279 mutable Vec uk, fk, uk2, inv_sigma_zj, zj, inv_sigma_fk, diff; 00280 00282 Vec pos_down_val; 00284 Vec pos_up_val; 00286 Vec neg_down_val; 00288 Vec neg_up_val; 00289 00290 // Saved components of manifold parzen windows 00291 00293 mutable TVec<Mat> eigenvectors; 00295 mutable Mat eigenvalues; 00297 mutable Vec sigma_noises; 00299 mutable Mat mus; 00300 00302 TVec< PP<ClassSubsetVMatrix> > class_datasets; 00303 00306 //Vec class_proportions; 00307 00309 TMat<int> nearest_neighbors_indices; 00310 00312 mutable Vec test_votes; 00313 00315 TVec<int> greedy_stages; 00316 00319 int currently_trained_layer; 00320 00322 mutable bool manifold_parzen_parameters_are_up_to_date; 00323 00324 protected: 00325 //##### Protected Member Functions ###################################### 00326 00328 static void declareOptions(OptionList& ol); 00329 00330 private: 00331 //##### Private Member Functions ######################################## 00332 00334 void build_(); 00335 00336 void build_layers_and_connections(); 00337 00338 void build_classification_cost(); 00339 00340 void bprop_to_bases(const Mat& R, const Mat& M, 00341 const Vec& v1, 00342 const Vec& v2, real alpha); 00343 00344 void setLearningRate( real the_learning_rate ); 00345 00346 private: 00347 //##### Private Data Members ############################################ 00348 00349 // The rest of the private stuff goes here 00350 }; 00351 00352 // Declares a few other classes and functions related to this class 00353 DECLARE_OBJECT_PTR(DeepNonLocalManifoldParzen); 00354 00355 } // end of namespace PLearn 00356 00357 #endif 00358 00359 00360 /* 00361 Local Variables: 00362 mode:c++ 00363 c-basic-offset:4 00364 c-file-style:"stroustrup" 00365 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00366 indent-tabs-mode:nil 00367 fill-column:79 00368 End: 00369 */ 00370 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :