PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // RBMLayer.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 00039 #ifndef RBMLayer_INC 00040 #define RBMLayer_INC 00041 00042 #include <plearn/base/Object.h> 00043 00044 namespace PLearn { 00045 using namespace std; 00046 00047 // forward declarations 00048 class RBMParameters; 00049 class PRandom; 00050 00057 class RBMLayer: public Object 00058 { 00059 typedef Object inherited; 00060 00061 public: 00062 //##### Public Build Options ############################################ 00063 00065 int size; 00066 00071 string units_types; 00072 00074 PP<PRandom> random_gen; 00075 00076 //##### Not Options ##################################################### 00077 00081 Vec activations; 00082 00084 Vec sample; 00085 00087 Vec expectation; 00088 00090 bool expectation_is_up_to_date; 00091 00092 00093 public: 00094 //##### Public Member Functions ######################################### 00095 00097 RBMLayer(); 00098 00099 // Your other public member functions go here 00100 00103 virtual void getUnitActivations( int i, PP<RBMParameters> rbmp, 00104 int offset=0 ) = 0; 00105 00108 virtual void getAllActivations( PP<RBMParameters> rbmp, 00109 int offset=0 ) = 0; 00110 00112 virtual void generateSample() = 0 ; 00113 00115 virtual void computeExpectation() = 0 ; 00116 00118 virtual void bpropUpdate(const Vec& input, const Vec& output, 00119 Vec& input_gradient, 00120 const Vec& output_gradient) = 0 ; 00121 00123 virtual void reset(); 00124 00126 inline string getUnitsTypes() 00127 { 00128 return units_types; 00129 } 00130 00131 00132 //##### PLearn::Object Protocol ######################################### 00133 00134 // Declares other standard object methods. 00135 PLEARN_DECLARE_ABSTRACT_OBJECT(RBMLayer); 00136 00137 // Simply calls inherited::build() then build_() 00138 virtual void build(); 00139 00141 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00142 00143 protected: 00144 //##### Not Options ##################################################### 00145 00146 00147 protected: 00148 //##### Protected Member Functions ###################################### 00149 00151 static void declareOptions(OptionList& ol); 00152 00153 private: 00154 //##### Private Member Functions ######################################## 00155 00157 void build_(); 00158 00159 private: 00160 //##### Private Data Members ############################################ 00161 00162 // The rest of the private stuff goes here 00163 }; 00164 00165 // Declares a few other classes and functions related to this class 00166 DECLARE_OBJECT_PTR(RBMLayer); 00167 00168 } // end of namespace PLearn 00169 00170 #endif 00171 00172 00173 /* 00174 Local Variables: 00175 mode:c++ 00176 c-basic-offset:4 00177 c-file-style:"stroustrup" 00178 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00179 indent-tabs-mode:nil 00180 fill-column:79 00181 End: 00182 */ 00183 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :