PLearn 0.1
VBoundDBN2.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // VBoundDBN2.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 VBoundDBN2_INC
00041 #define VBoundDBN2_INC
00042 
00043 #include <plearn_learners/online/OnlineLearningModule.h>
00044 #include <plearn_learners/online/RBMModule.h>
00045 
00046 namespace PLearn {
00047 
00056 class VBoundDBN2 : public OnlineLearningModule
00057 {
00058     typedef OnlineLearningModule inherited;
00059 
00060 public:
00061     //#####  Public Build Options  ############################################
00062 
00065 
00066     PP<RBMModule> rbm1;
00067     PP<RBMModule> rbm2;
00068 
00069 public:
00070     //#####  Public Member Functions  #########################################
00071 
00073     // ### Make sure the implementation in the .cc
00074     // ### initializes all fields to reasonable default values.
00075     VBoundDBN2();
00076 
00077     // Your other public member functions go here
00078 
00091     void fprop(const TVec<Mat*>& ports_value);
00092 
00114     virtual void bpropAccUpdate(const TVec<Mat*>& ports_value,
00115                                 const TVec<Mat*>& ports_gradient);
00116 
00117     /* Optional
00118 
00121     virtual void fprop(const Vec& input, Vec& output) const;
00122 
00125     virtual void fprop(const Mat& inputs, Mat& outputs);
00126     */
00127 
00128     /* Optional
00139     virtual void bpropUpdate(const Vec& input, const Vec& output,
00140                              Vec& input_gradient,
00141                              const Vec& output_gradient,
00142                              bool accumulate=false);
00143 
00147     virtual void bpropUpdate(const Mat& inputs, const Mat& outputs,
00148                              Mat& input_gradients,
00149                              const Mat& output_gradients,
00150                              bool accumulate=false);
00151     */
00152 
00153     /* Optional
00156        A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH
00157        JUST CALLS
00158             bpropUpdate(input, output, input_gradient, output_gradient)
00159        AND IGNORES INPUT GRADIENT.
00161     virtual void bpropUpdate(const Vec& input, const Vec& output,
00162                              const Vec& output_gradient);
00163 
00167     virtual void bpropUpdate(const Mat& inputs, const Mat& outputs,
00168                              const Mat& output_gradients);
00169     */
00170 
00171     /* Optional
00172        N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH
00173        RAISES A PLERROR.
00178     virtual void bbpropUpdate(const Vec& input, const Vec& output,
00179                               Vec& input_gradient,
00180                               const Vec& output_gradient,
00181                               Vec& input_diag_hessian,
00182                               const Vec& output_diag_hessian,
00183                               bool accumulate=false);
00184     */
00185 
00186     /* Optional
00187        N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS,
00188        WHICH JUST CALLS
00189             bbpropUpdate(input, output, input_gradient, output_gradient,
00190                          out_hess, in_hess)
00191        AND IGNORES INPUT HESSIAN AND INPUT GRADIENT.
00193     virtual void bbpropUpdate(const Vec& input, const Vec& output,
00194                               const Vec& output_gradient,
00195                               const Vec& output_diag_hessian);
00196     */
00197 
00198 
00202     virtual void forget();
00203 
00204 
00205     /* Optional
00206        THE DEFAULT IMPLEMENTATION PROVIDED IN THE SUPER-CLASS DOES NOT
00207        DO ANYTHING.
00211     virtual void finalize();
00212     */
00213 
00214     /* Optional
00215        THE DEFAULT IMPLEMENTATION PROVIDED IN THE SUPER-CLASS RETURNS false
00217     virtual bool bpropDoesNothing();
00218     */
00219 
00220     /* Optional
00221        Default implementation prints a warning and does nothing
00224     virtual void setLearningRate(real dynamic_learning_rate);
00225     */
00226 
00230     virtual const TVec<string>& getPorts();
00231 
00242     virtual const TMat<int>& getPortSizes();
00243 
00244     /* Optional
00248     //  ### Default implementation performs a simple linear search in
00249     //  ### getPorts().
00250     virtual int getPortIndex(const string& port);
00251     */
00252 
00253     //#####  PLearn::Object Protocol  #########################################
00254 
00255     // Declares other standard object methods.
00256     // ### If your class is not instantiatable (it has pure virtual methods)
00257     // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT
00258     PLEARN_DECLARE_OBJECT(VBoundDBN2);
00259 
00260     // Simply calls inherited::build() then build_()
00261     virtual void build();
00262 
00264     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00265 
00266 
00267 protected:
00268     //#####  Protected Member Functions  ######################################
00269 
00271     static void declareOptions(OptionList& ol);
00272 
00273 private:
00274     //#####  Private Member Functions  ########################################
00275 
00277     void build_();
00278 
00279 private:
00280     //#####  Private Data Members  ############################################
00281 
00282     // The rest of the private stuff goes here
00283 
00284     Mat FE1v, FE1h, FE2h;
00285     Mat sampled_h_state;
00286     Mat global_improvement_state;
00287     Mat ph_given_v_state;
00288     Mat p2ph_state;
00289     Mat neglogphsample_given_v;
00290     Mat all_h; // for computing exact likelihood
00291     Mat neglogP2h;
00292     TVec<string> ports;
00293     TMat<int> sizes;
00294 };
00295 
00296 // Declares a few other classes and functions related to this class
00297 DECLARE_OBJECT_PTR(VBoundDBN2);
00298 
00299 } // end of namespace PLearn
00300 
00301 #endif
00302 
00303 
00304 /*
00305   Local Variables:
00306   mode:c++
00307   c-basic-offset:4
00308   c-file-style:"stroustrup"
00309   c-file-offsets:((innamespace . 0)(inline-open . 0))
00310   indent-tabs-mode:nil
00311   fill-column:79
00312   End:
00313 */
00314 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines