PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // TopDownAsymetricDeepNetwork.h 00004 // 00005 // Copyright (C) 2008 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 TopDownAsymetricDeepNetwork_INC 00041 #define TopDownAsymetricDeepNetwork_INC 00042 00043 #include <plearn/vmat/ClassSubsetVMatrix.h> 00044 #include <plearn_learners/generic/PLearner.h> 00045 #include <plearn_learners/online/GradNNetLayerModule.h> 00046 #include <plearn_learners/online/OnlineLearningModule.h> 00047 #include <plearn_learners/online/CostModule.h> 00048 #include <plearn_learners/online/ModuleStackModule.h> 00049 #include <plearn_learners/online/NLLCostModule.h> 00050 #include <plearn_learners/online/ClassErrorCostModule.h> 00051 #include <plearn_learners/online/CombiningCostsModule.h> 00052 #include <plearn_learners/online/RBMClassificationModule.h> 00053 #include <plearn_learners/online/RBMLayer.h> 00054 #include <plearn_learners/online/RBMMixedLayer.h> 00055 #include <plearn_learners/online/RBMConnection.h> 00056 #include <plearn_learners/online/SoftmaxModule.h> 00057 #include <plearn/misc/PTimer.h> 00058 00059 namespace PLearn { 00060 00067 class TopDownAsymetricDeepNetwork : public PLearner 00068 { 00069 typedef PLearner inherited; 00070 00071 public: 00072 //##### Public Build Options ############################################ 00073 00075 real cd_learning_rate; 00076 00078 real cd_decrease_ct; 00079 00081 real greedy_learning_rate; 00082 00086 real greedy_decrease_ct; 00087 00089 real fine_tuning_learning_rate; 00090 00093 real fine_tuning_decrease_ct; 00094 00097 TVec<int> training_schedule; 00098 00100 TVec< PP<RBMLayer> > layers; 00101 00103 TVec< PP<RBMLayer> > top_down_layers; 00104 00106 TVec< PP<RBMConnection> > connections; 00107 00109 TVec< PP<RBMConnection> > reconstruction_connections; 00110 00112 int n_classes; 00113 00115 real output_weights_l1_penalty_factor; 00116 00118 real output_weights_l2_penalty_factor; 00119 00122 real fraction_of_masked_inputs; 00123 00124 //##### Public Learnt Options ########################################### 00125 00127 int n_layers; 00128 00129 public: 00130 //##### Public Member Functions ######################################### 00131 00133 TopDownAsymetricDeepNetwork(); 00134 00135 //##### PLearner Member Functions ####################################### 00136 00139 virtual int outputsize() const; 00140 00144 virtual void forget(); 00145 00149 virtual void train(); 00150 00152 virtual void computeOutput(const Vec& input, Vec& output) const; 00153 00155 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00156 const Vec& target, Vec& costs) const; 00157 00160 virtual TVec<std::string> getTestCostNames() const; 00161 00164 virtual TVec<std::string> getTrainCostNames() const; 00165 00166 void greedyStep( const Vec& input, const Vec& target, int index, 00167 Vec train_costs, int stage); 00168 00169 void fineTuningStep( const Vec& input, const Vec& target, 00170 Vec& train_costs); 00171 00172 void computeRepresentation( const Vec& input, 00173 Vec& representation, int layer) const; 00174 00175 //##### PLearn::Object Protocol ######################################### 00176 00177 // Declares other standard object methods. 00178 // ### If your class is not instantiatable (it has pure virtual methods) 00179 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00180 PLEARN_DECLARE_OBJECT(TopDownAsymetricDeepNetwork); 00181 00182 // Simply calls inherited::build() then build_() 00183 virtual void build(); 00184 00186 // (PLEASE IMPLEMENT IN .cc) 00187 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00188 00189 protected: 00190 //##### Not Options ##################################################### 00191 00194 mutable TVec<Vec> activations; 00195 00198 mutable TVec<Vec> expectations; 00199 00203 mutable TVec<Vec> activation_gradients; 00204 00208 mutable TVec<Vec> expectation_gradients; 00209 00211 mutable Vec reconstruction_activations; 00212 00214 mutable Vec reconstruction_activation_gradients; 00215 00217 mutable Vec reconstruction_expectation_gradients; 00218 00220 mutable Vec input_representation; 00221 00223 mutable Vec masked_autoassociator_input; 00224 00226 mutable TVec<int> autoassociator_input_indices; 00227 00229 Vec pos_down_val; 00231 Vec pos_up_val; 00233 Vec neg_down_val; 00235 Vec neg_up_val; 00236 00238 mutable Vec final_cost_input; 00240 mutable Vec final_cost_value; 00242 mutable Vec final_cost_gradient; 00243 00245 TVec<int> greedy_stages; 00246 00249 int currently_trained_layer; 00250 00252 PP<OnlineLearningModule> final_module; 00253 00255 PP<CostModule> final_cost; 00256 00257 protected: 00258 //##### Protected Member Functions ###################################### 00259 00261 static void declareOptions(OptionList& ol); 00262 00263 private: 00264 //##### Private Member Functions ######################################## 00265 00267 void build_(); 00268 00269 void build_layers_and_connections(); 00270 00271 void build_output_layer_and_cost(); 00272 00273 void setLearningRate( real the_learning_rate ); 00274 00275 private: 00276 //##### Private Data Members ############################################ 00277 00278 // The rest of the private stuff goes here 00279 }; 00280 00281 // Declares a few other classes and functions related to this class 00282 DECLARE_OBJECT_PTR(TopDownAsymetricDeepNetwork); 00283 00284 } // end of namespace PLearn 00285 00286 #endif 00287 00288 00289 /* 00290 Local Variables: 00291 mode:c++ 00292 c-basic-offset:4 00293 c-file-style:"stroustrup" 00294 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00295 indent-tabs-mode:nil 00296 fill-column:79 00297 End: 00298 */ 00299 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :