PLearn 0.1
RBMMixedLayer.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // RBMMixedLayer.h
00004 //
00005 // Copyright (C) 2006 Dan Popovici & 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: Dan Popovici & Pascal Lamblin
00036 
00040 #ifndef RBMMixedLayer_INC
00041 #define RBMMixedLayer_INC
00042 
00043 #include "RBMLayer.h"
00044 
00045 namespace PLearn {
00046 using namespace std;
00047 
00053 class RBMMixedLayer: public RBMLayer
00054 {
00055     typedef RBMLayer inherited;
00056 
00057 public:
00058     //#####  Public Build Options  ############################################
00059 
00061     TVec< PP<RBMLayer> > sub_layers;
00062 
00063 
00064 public:
00065     //#####  Public Member Functions  #########################################
00066 
00068     RBMMixedLayer();
00069 
00071     RBMMixedLayer( TVec< PP<RBMLayer> > the_sub_layers );
00072 
00074     virtual void setLearningRate( real the_learning_rate );
00075 
00077     virtual void setMomentum( real the_momentum );
00078 
00080     virtual void setBatchSize( int the_batch_size );
00081 
00083     virtual void setExpectation(const Vec& the_expectation);
00084 
00087     virtual void setExpectationByRef(const Vec& the_expectation);
00088 
00090     virtual void setExpectations(const Mat& the_expectations);
00091 
00094     virtual void setExpectationsByRef(const Mat& the_expectations);
00095 
00096     // Your other public member functions go here
00099     virtual void getUnitActivation( int i, PP<RBMConnection> rbmc,
00100                                     int offset=0 );
00101 
00104     virtual void getAllActivations( PP<RBMConnection> rbmc, int offset=0,
00105                                     bool minibatch = false );
00106 
00107     //change the flag of expectation_is_up_to_date to false
00108     virtual void expectation_is_not_up_to_date();
00109 
00111     virtual void generateSample();
00112 
00114     virtual void generateSamples();
00115 
00117     virtual void computeExpectation();
00118 
00120     virtual void computeExpectations();
00121 
00123     virtual void fprop( const Vec& input, Vec& output ) const;
00124 
00126     virtual void fprop( const Mat& inputs, Mat& outputs );
00127 
00129     virtual void fprop( const Vec& input, const Vec& rbm_bias,
00130                         Vec& output ) const;
00131 
00133     virtual void bpropUpdate(const Vec& input, const Vec& output,
00134                              Vec& input_gradient, const Vec& output_gradient,
00135                              bool accumulate=false);
00136 
00138     virtual void bpropUpdate(const Mat& inputs, const Mat& outputs,
00139                              Mat& input_gradients,
00140                              const Mat& output_gradients,
00141                              bool accumulate = false);
00142 
00144     virtual void bpropUpdate(const Vec& input, const Vec& rbm_bias,
00145                              const Vec& output,
00146                              Vec& input_gradient, Vec& rbm_bias_gradient,
00147                              const Vec& output_gradient) ;
00148 
00151     virtual real fpropNLL(const Vec& target);
00152 
00154     virtual void fpropNLL(const Mat& targets, const Mat& costs_column);
00155 
00158     virtual void bpropNLL(const Vec& target, real nll, Vec& bias_gradient);
00159     virtual void bpropNLL(const Mat& targets, const Mat& costs_column,
00160                           Mat& bias_gradients);
00161 
00163     virtual void accumulatePosStats( const Vec& pos_values );
00164 
00166     virtual void accumulateNegStats( const Vec& neg_values );
00167 
00169     virtual void update();
00170 
00172     virtual void update( const Vec& pos_values, const Vec& neg_values );
00173 
00175     virtual void update( const Mat& pos_values, const Mat& neg_values );
00176 
00178     virtual void reset();
00179 
00181     virtual void clearStats();
00182 
00184     virtual void forget();
00185 
00187     virtual real energy(const Vec& unit_values) const;
00188 
00192     virtual real freeEnergyContribution(const Vec& unit_activations) const;
00193 
00198     virtual void freeEnergyContributionGradient(const Vec& unit_activations,
00199                                                 Vec& unit_activations_gradient,
00200                                                 real output_gradient = 1,
00201                                                 bool accumulate = false) 
00202         const;
00203 
00204     virtual int getConfigurationCount();
00205 
00206     virtual void getConfiguration(int conf_index, Vec& output);
00207 
00208     //#####  PLearn::Object Protocol  #########################################
00209 
00210     // Declares other standard object methods.
00211     PLEARN_DECLARE_OBJECT(RBMMixedLayer);
00212 
00213     // Simply calls inherited::build() then build_()
00214     virtual void build();
00215 
00217     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00218 
00219 protected:
00220 
00222     TVec<int> init_positions;
00223 
00225     TVec<int> layer_of_unit;
00226 
00228     int n_layers;
00229 
00230     //#####  Not Options  #####################################################
00231 
00232 protected:
00233     //#####  Protected Member Functions  ######################################
00234 
00236     static void declareOptions(OptionList& ol);
00237 
00238 private:
00239     //#####  Private Member Functions  ########################################
00240 
00242     void build_();
00243 
00244 private:
00245     //#####  Private Data Members  ############################################
00246 
00247     // The rest of the private stuff goes here
00248     mutable Vec nlls;
00249     mutable Mat mat_nlls;
00250 };
00251 
00252 // Declares a few other classes and functions related to this class
00253 DECLARE_OBJECT_PTR(RBMMixedLayer);
00254 
00255 } // end of namespace PLearn
00256 
00257 #endif
00258 
00259 
00260 /*
00261   Local Variables:
00262   mode:c++
00263   c-basic-offset:4
00264   c-file-style:"stroustrup"
00265   c-file-offsets:((innamespace . 0)(inline-open . 0))
00266   indent-tabs-mode:nil
00267   fill-column:79
00268   End:
00269 */
00270 // 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