PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // StackedSVDNet.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 StackedSVDNet_INC 00041 #define StackedSVDNet_INC 00042 00043 #include <plearn_learners/generic/PLearner.h> 00044 #include <plearn_learners/online/OnlineLearningModule.h> 00045 #include <plearn_learners/online/CostModule.h> 00046 #include <plearn_learners/online/RBMLayer.h> 00047 #include <plearn_learners/online/RBMConnection.h> 00048 #include <plearn_learners/online/RBMMatrixConnection.h> 00049 #include <plearn/misc/PTimer.h> 00050 00051 namespace PLearn { 00052 00056 class StackedSVDNet : public PLearner 00057 { 00058 typedef PLearner inherited; 00059 00060 public: 00061 //##### Public Build Options ############################################ 00062 00065 real greedy_learning_rate; 00066 00069 real greedy_decrease_ct; 00070 00072 real fine_tuning_learning_rate; 00073 00076 real fine_tuning_decrease_ct; 00077 00079 int minibatch_size; 00080 00083 bool global_output_layer; 00084 00088 bool fill_in_null_diagonal; 00089 00097 TVec<int> training_schedule; 00098 00100 TVec< PP<RBMLayer> > layers; 00101 00105 PP<OnlineLearningModule> final_module; 00106 00111 PP<CostModule> final_cost; 00112 00113 //##### Public Learnt Options ########################################### 00114 00116 TVec< PP<RBMMatrixConnection> > connections; 00117 00120 TVec< PP<RBMConnection> > rbm_connections; 00121 00123 int n_layers; 00124 00125 public: 00126 //##### Public Member Functions ######################################### 00127 00129 StackedSVDNet(); 00130 00131 00132 //##### PLearner Member Functions ####################################### 00133 00136 virtual int outputsize() const; 00137 00141 virtual void forget(); 00142 00146 virtual void train(); 00147 00149 virtual void computeOutput(const Vec& input, Vec& output) const; 00150 00152 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00153 const Vec& target, Vec& costs) const; 00154 00157 virtual TVec<std::string> getTestCostNames() const; 00158 00161 virtual TVec<std::string> getTrainCostNames() const; 00162 00163 00164 void greedyStep( const Mat& inputs, const Mat& targets, int index, 00165 Vec train_costs ); 00166 00167 void fineTuningStep( const Mat& inputs, const Mat& targets, 00168 Vec& train_costs ); 00169 00170 //##### PLearn::Object Protocol ######################################### 00171 00172 // Declares other standard object methods. 00173 // ### If your class is not instantiatable (it has pure virtual methods) 00174 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00175 PLEARN_DECLARE_OBJECT(StackedSVDNet); 00176 00177 // Simply calls inherited::build() then build_() 00178 virtual void build(); 00179 00181 // (PLEASE IMPLEMENT IN .cc) 00182 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00183 00184 protected: 00185 //##### Not Options ##################################################### 00186 00190 mutable TVec<Mat> activation_gradients; 00191 00195 mutable TVec<Mat> expectation_gradients; 00196 00198 mutable PP<RBMLayer> reconstruction_layer; 00199 00201 mutable Mat reconstruction_targets; 00202 00204 mutable Mat reconstruction_costs; 00205 00207 mutable Vec reconstruction_test_costs; 00208 00210 mutable Vec reconstruction_activation_gradient; 00211 00213 mutable Mat reconstruction_activation_gradients; 00214 00216 mutable Mat reconstruction_input_gradients; 00217 00219 mutable Vec global_output_layer_input; 00220 00222 mutable Mat global_output_layer_inputs; 00223 00225 mutable Mat global_output_layer_input_gradients; 00226 00228 mutable Mat final_cost_inputs; 00229 00231 mutable Vec final_cost_value; 00232 00234 mutable Mat final_cost_values; 00235 00237 mutable Mat final_cost_gradients; 00238 00240 TVec<int> cumulative_schedule; 00241 00242 00243 protected: 00244 //##### Protected Member Functions ###################################### 00245 00247 static void declareOptions(OptionList& ol); 00248 00249 private: 00250 //##### Private Member Functions ######################################## 00251 00253 void build_(); 00254 00255 void build_layers_and_connections(); 00256 00257 void build_classification_cost(); 00258 00259 void build_costs(); 00260 00261 void setLearningRate( real the_learning_rate ); 00262 00263 private: 00264 //##### Private Data Members ############################################ 00265 00266 // The rest of the private stuff goes here 00267 }; 00268 00269 // Declares a few other classes and functions related to this class 00270 DECLARE_OBJECT_PTR(StackedSVDNet); 00271 00272 } // end of namespace PLearn 00273 00274 #endif 00275 00276 00277 /* 00278 Local Variables: 00279 mode:c++ 00280 c-basic-offset:4 00281 c-file-style:"stroustrup" 00282 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00283 indent-tabs-mode:nil 00284 fill-column:79 00285 End: 00286 */ 00287 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :