PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // RBMLocalMultinomialLayer.h 00004 // 00005 // Copyright (C) 2007 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 // Author: Pascal Lamblin 00036 00040 #ifndef RBMLocalMultinomialLayer_INC 00041 #define RBMLocalMultinomialLayer_INC 00042 00043 #include "RBMLayer.h" 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00052 class RBMLocalMultinomialLayer: public RBMLayer 00053 { 00054 typedef RBMLayer inherited; 00055 00056 public: 00057 //##### Public Build Options ############################################ 00058 00060 int n_images; 00061 00063 int images_length; 00064 00066 int images_width; 00067 00069 int area_length; 00070 00072 int area_width; 00073 00074 //##### Learnt Options ################################################## 00075 int images_size; 00076 int area_size; 00077 int n_areas; 00078 00079 public: 00080 //##### Public Member Functions ######################################### 00081 00083 RBMLocalMultinomialLayer( real the_learning_rate=0. ); 00084 00086 RBMLocalMultinomialLayer( int the_size, real the_learning_rate=0. ); 00087 00088 00090 virtual void generateSample(); 00091 00093 virtual void generateSamples(); 00094 00096 virtual void computeExpectation(); 00097 00099 virtual void computeExpectations(); 00100 00102 virtual void fprop( const Vec& input, Vec& output ) const; 00103 00105 virtual void fprop( const Vec& input, const Vec& rbm_bias, 00106 Vec& output ) const; 00107 00109 virtual void bpropUpdate(const Vec& input, const Vec& output, 00110 Vec& input_gradient, const Vec& output_gradient, 00111 bool accumulate=false); 00112 00114 virtual void bpropUpdate(const Mat& inputs, const Mat& outputs, 00115 Mat& input_gradients, 00116 const Mat& output_gradients, 00117 bool accumulate = false); 00118 00120 virtual void bpropUpdate(const Vec& input, const Vec& rbm_bias, 00121 const Vec& output, 00122 Vec& input_gradient, Vec& rbm_bias_gradient, 00123 const Vec& output_gradient) ; 00124 00127 virtual real fpropNLL(const Vec& target); 00128 virtual void fpropNLL(const Mat& targets, const Mat& costs_column); 00129 00132 virtual void bpropNLL(const Vec& target, real nll, Vec& bias_gradient); 00133 virtual void bpropNLL(const Mat& targets, const Mat& costs_column, 00134 Mat& bias_gradients); 00135 00136 // Compute -bias' unit_values 00137 virtual real energy(const Vec& unit_values) const; 00138 00142 virtual real freeEnergyContribution(const Vec& unit_activations) const; 00143 00144 virtual int getConfigurationCount(); 00145 00146 virtual void getConfiguration(int conf_index, Vec& output); 00147 00148 //##### PLearn::Object Protocol ######################################### 00149 00150 // Declares other standard object methods. 00151 PLEARN_DECLARE_OBJECT(RBMLocalMultinomialLayer); 00152 00153 // Simply calls inherited::build() then build_() 00154 virtual void build(); 00155 00157 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00158 00159 protected: 00160 //##### Not Options ##################################################### 00161 00162 protected: 00163 //##### Protected Member Functions ###################################### 00164 00166 static void declareOptions(OptionList& ol); 00167 00168 private: 00169 //##### Private Member Functions ######################################## 00170 00172 void build_(); 00173 00174 private: 00175 //##### Private Data Members ############################################ 00176 00177 // The rest of the private stuff goes here 00178 }; 00179 00180 // Declares a few other classes and functions related to this class 00181 DECLARE_OBJECT_PTR(RBMLocalMultinomialLayer); 00182 00183 } // end of namespace PLearn 00184 00185 #endif 00186 00187 00188 /* 00189 Local Variables: 00190 mode:c++ 00191 c-basic-offset:4 00192 c-file-style:"stroustrup" 00193 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00194 indent-tabs-mode:nil 00195 fill-column:79 00196 End: 00197 */ 00198 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :