PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // RBMGaussianLayer.h 00004 // 00005 // Copyright (C) 2006 Dan Popovici & 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 & Pascal Lamblin 00036 00040 #ifndef RBMGaussianLayer_INC 00041 #define RBMGaussianLayer_INC 00042 00043 #include "RBMLayer.h" 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00052 class RBMGaussianLayer: public RBMLayer 00053 { 00054 typedef RBMLayer inherited; 00055 00056 public: 00057 //##### Public Build Options ############################################ 00058 00059 real min_quad_coeff; 00060 00061 bool share_quad_coeff; 00062 00065 int size_quad_coeff; 00066 00067 real fixed_std_deviation; 00068 00072 bool compute_mse_instead_of_nll; 00073 00074 public: 00075 //##### Public Member Functions ######################################### 00076 00078 RBMGaussianLayer( real the_learning_rate=0. ); 00079 00081 RBMGaussianLayer( int the_size, real the_learning_rate=0. ); 00082 00085 RBMGaussianLayer( int the_size, real the_learning_rate=0., 00086 bool do_share_quad_coeff=false ); 00087 00089 virtual void generateSample() ; 00090 00091 virtual void generateSamples() ; 00092 00094 virtual void computeExpectation() ; 00095 00097 virtual void computeExpectations() ; 00098 00100 virtual void computeStdDeviation() ; 00101 00103 virtual void fprop( const Vec& input, Vec& output ) const; 00104 00106 virtual void bpropUpdate(const Vec& input, const Vec& output, 00107 Vec& input_gradient, const Vec& output_gradient, 00108 bool accumulate=false); 00109 00111 virtual void bpropUpdate(const Mat& inputs, const Mat& outputs, 00112 Mat& input_gradients, 00113 const Mat& output_gradients, 00114 bool accumulate = false) 00115 { 00116 PLASSERT_MSG(false, "Not implemented"); 00117 } 00118 00120 virtual void accumulatePosStats( const Vec& pos_values ); 00121 00123 virtual void accumulateNegStats( const Vec& neg_values ); 00124 00126 virtual void update(); 00127 00129 virtual void update( const Vec& pos_values, const Vec& neg_values ); 00130 00132 virtual void update( const Mat& pos_values, const Mat& neg_values ); 00133 00135 virtual void reset(); 00136 00138 virtual void clearStats(); 00139 00141 virtual void forget(); 00142 00144 virtual real energy(const Vec& unit_values) const; 00145 00149 virtual real freeEnergyContribution(const Vec& unit_activations) const; 00150 00151 virtual int getConfigurationCount() 00152 { 00153 return INFINITE_CONFIGURATIONS; 00154 } 00155 00158 virtual real fpropNLL(const Vec& target); 00159 virtual void fpropNLL(const Mat& targets, const Mat& costs_column); 00160 00163 virtual void bpropNLL(const Vec& target, real nll, Vec& bias_gradient); 00164 virtual void bpropNLL(const Mat& targets, const Mat& costs_column, 00165 Mat& bias_gradients); 00166 00167 //##### PLearn::Object Protocol ######################################### 00168 00169 // Declares other standard object methods. 00170 PLEARN_DECLARE_OBJECT(RBMGaussianLayer); 00171 00172 // Simply calls inherited::build() then build_() 00173 virtual void build(); 00174 00176 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00177 00178 protected: 00179 //##### Learned Options ################################################# 00181 Vec quad_coeff; 00182 00183 //##### Not Options ##################################################### 00184 Vec quad_coeff_pos_stats; 00185 Vec quad_coeff_neg_stats; 00186 Vec quad_coeff_inc; 00187 00189 Vec sigma; 00190 bool sigma_is_up_to_date; 00191 00192 protected: 00193 //##### Protected Member Functions ###################################### 00194 00196 static void declareOptions(OptionList& ol); 00197 00198 private: 00199 //##### Private Member Functions ######################################## 00200 00202 void build_(); 00203 00204 private: 00205 //##### Private Data Members ############################################ 00206 00207 // The rest of the private stuff goes here 00208 }; 00209 00210 // Declares a few other classes and functions related to this class 00211 DECLARE_OBJECT_PTR(RBMGaussianLayer); 00212 00213 } // end of namespace PLearn 00214 00215 #endif 00216 00217 00218 /* 00219 Local Variables: 00220 mode:c++ 00221 c-basic-offset:4 00222 c-file-style:"stroustrup" 00223 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00224 indent-tabs-mode:nil 00225 fill-column:79 00226 End: 00227 */ 00228 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :