PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // GaussianDBNRegression.h 00004 // 00005 // Copyright (C) 2006 Dan Popovici 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 GaussianDBNRegression_INC 00041 #define GaussianDBNRegression_INC 00042 00043 #include <plearn_learners/distributions/PDistribution.h> 00044 00045 namespace PLearn { 00046 00047 class RBMLayer; 00048 class RBMParameters; 00049 class RBMLLParameters; 00050 class RBMQLParameters; 00051 class RBMLQParameters; 00052 00060 class GaussianDBNRegression : public PDistribution 00061 { 00062 typedef PDistribution inherited; 00063 00064 public: 00065 //##### Public Build Options ############################################ 00066 00069 00071 real learning_rate; 00072 00074 real weight_decay; 00075 00081 string initialization_method; 00082 00085 int n_layers; 00086 00089 TVec< PP<RBMLayer> > layers; 00090 00092 PP<RBMLayer> last_layer; 00093 00095 PP<RBMLayer> target_layer; 00096 00099 TVec< PP<RBMLLParameters> > params; 00100 00102 PP<RBMQLParameters> input_params; 00103 00105 PP<RBMLQParameters> target_params; 00106 00109 TVec<int> training_schedule; 00110 00117 string fine_tuning_method; 00118 00119 bool use_sample_rather_than_expectation_in_positive_phase_statistics; 00120 00121 public: 00122 //##### Public Member Functions ######################################### 00123 00125 // ### Make sure the implementation in the .cc 00126 // ### initializes all fields to reasonable default values. 00127 GaussianDBNRegression(); 00128 00129 00130 //##### PDistribution Member Functions ################################## 00131 00133 virtual real density(const Vec& y) const; 00134 00136 virtual real log_density(const Vec& y) const; 00137 00139 virtual real survival_fn(const Vec& y) const; 00140 00142 virtual real cdf(const Vec& y) const; 00143 00145 virtual void expectation(Vec& mu) const; 00146 00148 virtual void variance(Mat& cov) const; 00149 00152 virtual void generate(Vec& y) const; 00153 00154 //### Override this method if you need it (and if your distribution can 00155 //### handle it. Default version calls PLERROR. 00160 // virtual void generatePredictorGivenPredicted(Vec& x, const Vec& y); 00161 00163 //### See help in PDistribution.h. 00164 virtual bool setPredictorPredictedSizes(int the_predictor_size, 00165 int the_predicted_size, 00166 bool call_parent = true); 00167 00169 //### See help in PDistribution.h. 00170 virtual void setPredictor(const Vec& predictor, bool call_parent = true) 00171 const; 00172 00173 // ### These methods may be overridden for efficiency purpose: 00174 /* 00175 //### Default version calls setPredictorPredictedSises(0,-1) and generate 00180 virtual void generateJoint(Vec& xy); 00181 00182 //### Default version calls generateJoint and discards y 00187 virtual void generatePredictor(Vec& x); 00188 00189 //### Default version calls generateJoint and discards x 00194 virtual void generatePredicted(Vec& y); 00195 */ 00196 00197 00198 //##### PLearner Member Functions ####################################### 00199 00200 // ### Default version of inputsize returns learner->inputsize() 00201 // ### If this is not appropriate, you should uncomment this and define 00202 // ### it properly in the .cc 00203 // virtual int inputsize() const; 00204 00212 virtual void forget(); 00213 00217 virtual void train(); 00218 00222 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00223 const Vec& target, Vec& costs) const; 00224 00225 virtual TVec<string> getTestCostNames() const; 00226 00227 //##### PLearn::Object Protocol ######################################### 00228 00229 // Declares other standard object methods. 00230 // ### If your class is not instantiatable (it has pure virtual methods) 00231 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00232 PLEARN_DECLARE_OBJECT(GaussianDBNRegression); 00233 00234 // Simply calls inherited::build() then build_() 00235 virtual void build(); 00236 00238 // (PLEASE IMPLEMENT IN .cc) 00239 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00240 00241 protected: 00242 //##### Protected Options ############################################### 00243 00244 // ### Declare protected option fields (such as learned parameters) here 00245 // ... 00246 00248 mutable TVec< Vec > activation_gradients; 00249 00251 mutable TVec< Vec > expectation_gradients; 00252 00254 mutable Vec output_gradient; 00255 00256 00257 protected: 00258 //##### Protected Member Functions ###################################### 00259 00260 virtual void greedyStep( const Vec& predictor, int params_index ); 00261 virtual void fineTuneByGradientDescent( const Vec& input ); 00262 void fineTuneByGradientDescentLastLayer( const Vec& input ); 00263 00265 static void declareOptions(OptionList& ol); 00266 00267 private: 00268 //##### Private Member Functions ######################################## 00269 00271 void build_(); 00272 00274 void build_layers(); 00275 00277 void build_params(); 00278 00279 private: 00280 //##### Private Data Members ############################################ 00281 00282 // The rest of the private stuff goes here 00283 }; 00284 00285 // Declares a few other classes and functions related to this class 00286 DECLARE_OBJECT_PTR(GaussianDBNRegression); 00287 00288 } // end of namespace PLearn 00289 00290 #endif 00291 00292 00293 /* 00294 Local Variables: 00295 mode:c++ 00296 c-basic-offset:4 00297 c-file-style:"stroustrup" 00298 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00299 indent-tabs-mode:nil 00300 fill-column:79 00301 End: 00302 */ 00303 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :