PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // GaussianDBNClassification.h 00004 // 00005 // Copyright (C) 2006 Pascal Lamblin 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: Dan Popovici 00036 00040 #ifndef GaussianDBNClassification_INC 00041 #define GaussianDBNClassification_INC 00042 00043 #include <plearn_learners/distributions/PDistribution.h> 00044 #include "RBMMixedLayer.h" 00045 #include "RBMMultinomialLayer.h" 00046 #include "RBMQLParameters.h" 00047 00048 namespace PLearn { 00049 00050 class RBMLayer; 00051 class RBMParameters; 00052 class RBMLLParameters; 00053 class RBMJointLLParameters; 00054 // Note: cannot use forward declaration with PP<>. Thus the following lines are 00055 // commented out. It *can* sometimes work though depending on the includes 00056 // around, this is why there are still some forward declarations above. 00057 // class RBMMixedLayer; 00058 // class RBMMultinomialLayer; 00059 // class RBMQLParameters; 00060 00067 class GaussianDBNClassification : public PDistribution 00068 { 00069 typedef PDistribution inherited; 00070 00071 public: 00072 //##### Public Build Options ############################################ 00073 00076 00078 real learning_rate; 00079 00081 real weight_decay; 00082 00088 string initialization_method; 00089 00092 int n_layers; 00093 00096 TVec< PP<RBMLayer> > layers; 00097 00099 PP<RBMLayer> last_layer; 00100 00102 PP<RBMMultinomialLayer> target_layer; 00103 00105 PP<RBMMixedLayer> joint_layer; 00106 00109 TVec< PP<RBMLLParameters> > params; 00110 00111 PP<RBMQLParameters> input_params; 00112 00114 PP<RBMLLParameters> target_params; 00115 00118 PP<RBMJointLLParameters> joint_params; 00119 00122 TVec<int> training_schedule; 00123 00130 string fine_tuning_method; 00131 00132 bool use_sample_rather_than_expectation_in_positive_phase_statistics; 00133 00134 public: 00135 //##### Public Member Functions ######################################### 00136 00138 // ### Make sure the implementation in the .cc 00139 // ### initializes all fields to reasonable default values. 00140 GaussianDBNClassification(); 00141 00142 00143 //##### PDistribution Member Functions ################################## 00144 00146 virtual real density(const Vec& y) const; 00147 00149 virtual real log_density(const Vec& y) const; 00150 00152 virtual real survival_fn(const Vec& y) const; 00153 00155 virtual real cdf(const Vec& y) const; 00156 00158 virtual void expectation(Vec& mu) const; 00159 00161 virtual void variance(Mat& cov) const; 00162 00165 virtual void generate(Vec& y) const; 00166 00167 //### Override this method if you need it (and if your distribution can 00168 //### handle it. Default version calls PLERROR. 00173 // virtual void generatePredictorGivenPredicted(Vec& x, const Vec& y); 00174 00176 //### See help in PDistribution.h. 00177 virtual bool setPredictorPredictedSizes(int the_predictor_size, 00178 int the_predicted_size, 00179 bool call_parent = true); 00180 00182 //### See help in PDistribution.h. 00183 virtual void setPredictor(const Vec& predictor, bool call_parent = true) 00184 const; 00185 00186 // ### These methods may be overridden for efficiency purpose: 00187 /* 00188 //### Default version calls setPredictorPredictedSises(0,-1) and generate 00193 virtual void generateJoint(Vec& xy); 00194 00195 //### Default version calls generateJoint and discards y 00200 virtual void generatePredictor(Vec& x); 00201 00202 //### Default version calls generateJoint and discards x 00207 virtual void generatePredicted(Vec& y); 00208 */ 00209 00210 00211 //##### PLearner Member Functions ####################################### 00212 00213 // ### Default version of inputsize returns learner->inputsize() 00214 // ### If this is not appropriate, you should uncomment this and define 00215 // ### it properly in the .cc 00216 // virtual int inputsize() const; 00217 00225 virtual void forget(); 00226 00230 virtual void train(); 00231 00235 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00236 const Vec& target, Vec& costs) const; 00237 00238 virtual TVec<string> getTestCostNames() const; 00239 00240 //##### PLearn::Object Protocol ######################################### 00241 00242 // Declares other standard object methods. 00243 // ### If your class is not instantiatable (it has pure virtual methods) 00244 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00245 PLEARN_DECLARE_OBJECT(GaussianDBNClassification); 00246 00247 // Simply calls inherited::build() then build_() 00248 virtual void build(); 00249 00251 // (PLEASE IMPLEMENT IN .cc) 00252 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00253 00254 protected: 00255 //##### Protected Options ############################################### 00256 00257 // ### Declare protected option fields (such as learned parameters) here 00258 // ... 00259 00261 mutable TVec< Vec > activation_gradients; 00262 00264 mutable TVec< Vec > expectation_gradients; 00265 00267 mutable Vec output_gradient; 00268 00269 00270 protected: 00271 //##### Protected Member Functions ###################################### 00272 00273 virtual void greedyStep( const Vec& predictor, int params_index ); 00274 virtual void jointGreedyStep( const Vec& input ); 00275 virtual void fineTuneByGradientDescent( const Vec& input ); 00276 00278 static void declareOptions(OptionList& ol); 00279 00280 private: 00281 //##### Private Member Functions ######################################## 00282 00284 void build_(); 00285 00287 void build_layers(); 00288 00290 void build_params(); 00291 00292 private: 00293 //##### Private Data Members ############################################ 00294 00295 // The rest of the private stuff goes here 00296 }; 00297 00298 // Declares a few other classes and functions related to this class 00299 DECLARE_OBJECT_PTR(GaussianDBNClassification); 00300 00301 } // end of namespace PLearn 00302 00303 #endif 00304 00305 00306 /* 00307 Local Variables: 00308 mode:c++ 00309 c-basic-offset:4 00310 c-file-style:"stroustrup" 00311 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00312 indent-tabs-mode:nil 00313 fill-column:79 00314 End: 00315 */ 00316 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :