PLearn 0.1
FNetLayerVariable.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PLearn (A C++ Machine Learning Library)
00004 // Copyright (C) 1998 Pascal Vincent
00005 // Copyright (C) 2005 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 
00036 /* *******************************************************      
00037  * $Id: FNetLayerVariable.h 3994 2005-08-25 13:35:03Z chapados $
00038  * This file is part of the PLearn library.
00039  ******************************************************* */
00040 
00041 #ifndef FNetLayerVariable_INC
00042 #define FNetLayerVariable_INC
00043 
00044 #include "NaryVariable.h"
00045 
00046 namespace PLearn {
00047 using namespace std;
00048 
00049 
00054 class FNetLayerVariable: public NaryVariable
00055 {
00056     typedef NaryVariable inherited;
00057 
00059     Mat mu; // [hidden unit, input element] centering normalization
00060     Mat invs; // 1/sqrt(mu2 - mu*mu) for normalization
00061     real gradient_threshold; // threshold for |dC/da[k,i]| to 'activate' gradient propagation through unit i at example k
00062 
00064     Mat mu2; // to compute invs, the inverse of the standard deviation
00065     real avg_act_gradient; // mov. avg of |dC/da[i,k]|
00066     bool no_bprop_has_been_done; // have we ever done a bprop before?
00067     TVec<Mat> u; // normalized input [example index in minibatch](hidden unit, input index)
00068     Mat inh; // inhibitory signal on each hidden unit (minibatch_size x n_hidden)
00069     Mat cum_inh; 
00070 
00071 public:
00072 
00074     real c1_;
00075     real c2_;
00076     int n_inputs;
00077     int n_hidden;
00078     int minibatch_size;
00079     bool inhibit_next_units; 
00080     bool inhibit_by_sum;
00081     bool squashed_inhibition;
00082     bool normalize_inputs;
00083     bool backprop_to_inputs;
00084     real exp_moving_average_coefficient;
00085     real average_error_fraction_to_threshold;
00086     real min_stddev;
00087 
00089     FNetLayerVariable();
00090 
00091     FNetLayerVariable(Var inputs, Var weights,
00092                       Var biases, Var inhibition_weights,
00093                       bool _inhibit_next_units=true,
00094                       bool _normalize_inputs=true,
00095                       bool _backprop_to_inputs=false,
00096                       real _exp_moving_average_coefficient=0.001,
00097                       real _average_error_fraction_to_threshold=0.5);
00098 
00099     PLEARN_DECLARE_OBJECT(FNetLayerVariable);
00100 
00101     virtual void build();
00102 
00103     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00104 
00105     virtual void recomputeSize(int& l, int& w) const;
00106     virtual void fprop();
00107     virtual void bprop();
00108 
00109 protected:
00110 
00111     static void declareOptions(OptionList &ol);
00112 
00113 private:
00114 
00115     void build_();
00116 
00117 };
00118 
00119 DECLARE_OBJECT_PTR(FNetLayerVariable);
00120 
00121 } // end of namespace PLearn
00122 
00123 #endif 
00124 
00125 
00126 /*
00127   Local Variables:
00128   mode:c++
00129   c-basic-offset:4
00130   c-file-style:"stroustrup"
00131   c-file-offsets:((innamespace . 0)(inline-open . 0))
00132   indent-tabs-mode:nil
00133   fill-column:79
00134   End:
00135 */
00136 // 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