PLearn 0.1
RBMConv2DConnection.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // RBMConv2DConnection.h
00004 //
00005 // Copyright (C) 2006 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: Pascal Lamblin
00036 
00040 #ifndef RBMConv2DConnection_INC
00041 #define RBMConv2DConnection_INC
00042 
00043 #include "RBMConnection.h"
00044 
00045 namespace PLearn {
00046 using namespace std;
00047 
00048 
00054 class RBMConv2DConnection: public RBMConnection
00055 {
00056     typedef RBMConnection inherited;
00057 
00058 public:
00059     //#####  Public Build Options  ############################################
00060 
00062     int down_image_length;
00063 
00065     int down_image_width;
00066 
00068     int up_image_length;
00069 
00071     int up_image_width;
00072 
00074     int kernel_step1;
00075 
00077     int kernel_step2;
00078 
00079     //#####  Learned Options  #################################################
00080 
00082     Mat kernel;
00083 
00084     //#####  Not Options  #####################################################
00085 
00087     int kernel_length;
00088 
00090     int kernel_width;
00091 
00093     Mat kernel_pos_stats;
00094 
00096     Mat kernel_neg_stats;
00097 
00099     Mat kernel_inc;
00100 
00101 public:
00102     //#####  Public Member Functions  #########################################
00103 
00105     RBMConv2DConnection( real the_learning_rate=0 );
00106 
00107     // Your other public member functions go here
00108 
00110     virtual void accumulatePosStats( const Vec& down_values,
00111                                      const Vec& up_values );
00112 
00113     virtual void accumulatePosStats( const Mat& down_values,
00114                                      const Mat& up_values )
00115     {
00116         PLASSERT_MSG( false, "Not implemented" );
00117     }
00118 
00120     virtual void accumulateNegStats( const Vec& down_values,
00121                                      const Vec& up_values );
00122 
00123     virtual void accumulateNegStats( const Mat& down_values,
00124                                      const Mat& up_values )
00125     {
00126         PLASSERT_MSG( false, "Not implemented" );
00127     }
00128 
00130     virtual void update();
00131 
00134     virtual void update( const Vec& pos_down_values,
00135                          const Vec& pos_up_values,
00136                          const Vec& neg_down_values,
00137                          const Vec& neg_up_values );
00138 
00139     virtual void update( const Mat& pos_down_values,
00140                          const Mat& pos_up_values,
00141                          const Mat& neg_down_values,
00142                          const Mat& neg_up_values );
00143 
00145     virtual void clearStats();
00146 
00150     virtual void computeProduct( int start, int length,
00151                                  const Vec& activations,
00152                                  bool accumulate=false ) const;
00153 
00154     virtual void computeProducts(int start, int length,
00155                                  Mat& activations,
00156                                  bool accumulate=false ) const;
00157 
00168     // virtual void bpropUpdate(const Vec& input, const Vec& output,
00169     //                          const Vec& output_gradient);
00170 
00173     virtual void bpropUpdate(const Vec& input, const Vec& output,
00174                              Vec& input_gradient,
00175                              const Vec& output_gradient,
00176                              bool accumulate=false);
00177 
00178     virtual void bpropUpdate(const Mat& inputs, const Mat& outputs,
00179                              Mat& input_gradients,
00180                              const Mat& output_gradients,
00181                              bool accumulate=false);
00182 
00183     virtual void bpropAccUpdate(const TVec<Mat*>& ports_value,
00184                                 const TVec<Mat*>& ports_gradient);
00185 
00189     virtual void forget();
00190 
00195     // virtual void finalize();
00196 
00198     virtual int nParameters() const;
00199 
00205     virtual Vec makeParametersPointHere(const Vec& global_parameters);
00206 
00207     //#####  PLearn::Object Protocol  #########################################
00208 
00209     // Declares other standard object methods.
00210     PLEARN_DECLARE_OBJECT(RBMConv2DConnection);
00211 
00212     // Simply calls inherited::build() then build_()
00213     virtual void build();
00214 
00216     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00217 
00218 
00219 protected:
00220     //#####  Protected Member Functions  ######################################
00222     static void declareOptions(OptionList& ol);
00223 
00224 private:
00225     //#####  Private Member Functions  ########################################
00226 
00228     void build_();
00229 
00230 private:
00231     //#####  Private Data Members  ############################################
00232 
00233     // The rest of the private stuff goes here
00234     mutable Mat down_image;
00235     mutable Mat up_image;
00236     mutable Mat down_image_gradient;
00237     mutable Mat up_image_gradient;
00238     Mat kernel_gradient;
00239 };
00240 
00241 // Declares a few other classes and functions related to this class
00242 DECLARE_OBJECT_PTR(RBMConv2DConnection);
00243 
00244 } // end of namespace PLearn
00245 
00246 #endif
00247 
00248 
00249 /*
00250   Local Variables:
00251   mode:c++
00252   c-basic-offset:4
00253   c-file-style:"stroustrup"
00254   c-file-offsets:((innamespace . 0)(inline-open . 0))
00255   indent-tabs-mode:nil
00256   fill-column:79
00257   End:
00258 */
00259 // 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