PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // BinarizeModule.h 00004 // 00005 // Copyright (C) 2007 Yoshua Bengio 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: Yoshua Bengio 00036 00040 #ifndef BinarizeModule_INC 00041 #define BinarizeModule_INC 00042 00043 #include <plearn_learners/online/OnlineLearningModule.h> 00044 00045 namespace PLearn { 00046 00053 class BinarizeModule : public OnlineLearningModule 00054 { 00055 typedef OnlineLearningModule inherited; 00056 00057 public: 00058 //##### Public Build Options ############################################ 00059 00062 00064 bool stochastic; 00065 00067 bool copy_gradients; 00068 00070 bool saturate_gradients; 00071 00072 public: 00073 //##### Public Member Functions ######################################### 00074 00076 // ### Make sure the implementation in the .cc 00077 // ### initializes all fields to reasonable default values. 00078 BinarizeModule(); 00079 00080 // Your other public member functions go here 00081 00094 void fprop(const TVec<Mat*>& ports_value); 00095 00117 virtual void bpropAccUpdate(const TVec<Mat*>& ports_value, 00118 const TVec<Mat*>& ports_gradient); 00119 00120 /* Optional 00121 00124 virtual void fprop(const Vec& input, Vec& output) const; 00125 00128 virtual void fprop(const Mat& inputs, Mat& outputs); 00129 */ 00130 00131 /* Optional 00142 virtual void bpropUpdate(const Vec& input, const Vec& output, 00143 Vec& input_gradient, 00144 const Vec& output_gradient, 00145 bool accumulate=false); 00146 00150 virtual void bpropUpdate(const Mat& inputs, const Mat& outputs, 00151 Mat& input_gradients, 00152 const Mat& output_gradients, 00153 bool accumulate=false); 00154 */ 00155 00156 /* Optional 00159 A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH 00160 JUST CALLS 00161 bpropUpdate(input, output, input_gradient, output_gradient) 00162 AND IGNORES INPUT GRADIENT. 00164 virtual void bpropUpdate(const Vec& input, const Vec& output, 00165 const Vec& output_gradient); 00166 00170 virtual void bpropUpdate(const Mat& inputs, const Mat& outputs, 00171 const Mat& output_gradients); 00172 */ 00173 00174 /* Optional 00175 N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH 00176 RAISES A PLERROR. 00181 virtual void bbpropUpdate(const Vec& input, const Vec& output, 00182 Vec& input_gradient, 00183 const Vec& output_gradient, 00184 Vec& input_diag_hessian, 00185 const Vec& output_diag_hessian, 00186 bool accumulate=false); 00187 */ 00188 00189 /* Optional 00190 N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, 00191 WHICH JUST CALLS 00192 bbpropUpdate(input, output, input_gradient, output_gradient, 00193 out_hess, in_hess) 00194 AND IGNORES INPUT HESSIAN AND INPUT GRADIENT. 00196 virtual void bbpropUpdate(const Vec& input, const Vec& output, 00197 const Vec& output_gradient, 00198 const Vec& output_diag_hessian); 00199 */ 00200 00201 00205 virtual void forget(); 00206 00207 00208 /* Optional 00209 THE DEFAULT IMPLEMENTATION PROVIDED IN THE SUPER-CLASS DOES NOT 00210 DO ANYTHING. 00214 virtual void finalize(); 00215 */ 00216 00217 /* Optional 00218 THE DEFAULT IMPLEMENTATION PROVIDED IN THE SUPER-CLASS RETURNS false 00220 virtual bool bpropDoesNothing(); 00221 */ 00222 00223 /* Optional 00224 Default implementation prints a warning and does nothing 00227 virtual void setLearningRate(real dynamic_learning_rate); 00228 */ 00229 00233 virtual const TVec<string>& getPorts(); 00234 00245 virtual const TMat<int>& getPortSizes(); 00246 00247 /* Optional 00251 // ### Default implementation performs a simple linear search in 00252 // ### getPorts(). 00253 virtual int getPortIndex(const string& port); 00254 */ 00255 00256 //##### PLearn::Object Protocol ######################################### 00257 00258 // Declares other standard object methods. 00259 // ### If your class is not instantiatable (it has pure virtual methods) 00260 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT 00261 PLEARN_DECLARE_OBJECT(BinarizeModule); 00262 00263 // Simply calls inherited::build() then build_() 00264 virtual void build(); 00265 00267 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00268 00269 00270 protected: 00271 //##### Protected Member Functions ###################################### 00272 00274 static void declareOptions(OptionList& ol); 00275 00276 private: 00277 //##### Private Member Functions ######################################## 00278 00280 void build_(); 00281 00282 private: 00283 //##### Private Data Members ############################################ 00284 00285 // The rest of the private stuff goes here 00286 }; 00287 00288 // Declares a few other classes and functions related to this class 00289 DECLARE_OBJECT_PTR(BinarizeModule); 00290 00291 } // end of namespace PLearn 00292 00293 #endif 00294 00295 00296 /* 00297 Local Variables: 00298 mode:c++ 00299 c-basic-offset:4 00300 c-file-style:"stroustrup" 00301 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00302 indent-tabs-mode:nil 00303 fill-column:79 00304 End: 00305 */ 00306 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :