PLearn 0.1
ProcessInputCostModule.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ProcessInputCostModule.h
00004 //
00005 // Copyright (C) 2007 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 ProcessInputCostModule_INC
00041 #define ProcessInputCostModule_INC
00042 
00043 #include <plearn_learners/online/CostModule.h>
00044 
00045 namespace PLearn {
00046 
00057 class ProcessInputCostModule : public CostModule
00058 {
00059     typedef CostModule inherited;
00060 
00061 public:
00062     //#####  Public Build Options  ############################################
00063 
00065     PP<OnlineLearningModule> processing_module;
00066 
00068     PP<CostModule> cost_module;
00069 
00071     int processed_size;
00072 
00073 public:
00074     //#####  Public Member Functions  #########################################
00075 
00077     ProcessInputCostModule();
00078 
00081     virtual void fprop(const Vec& input, const Vec& target, real& cost) const;
00082 
00084     virtual void fprop(const Mat& inputs, const Mat& targets, Vec& costs );
00085 
00088     virtual void fprop(const Vec& input, const Vec& target, Vec& cost) const;
00089 
00091     virtual void fprop(const Mat& inputs, const Mat& targets, Mat& costs )
00092         const;
00093 
00095     virtual void bpropUpdate(const Vec& input, const Vec& target, real cost,
00096                              Vec& input_gradient, bool accumulate=false);
00097 
00099     virtual void bpropUpdate(const Mat& inputs, const Mat& targets,
00100                              const Vec& costs, Mat& input_gradients,
00101                              bool accumulate=false);
00102 
00103     /* Optional
00104        N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH
00105        JUST CALLS
00106             bpropUpdate(input, target, cost, input_gradient)
00107        AND IGNORES INPUT GRADIENT.
00109     virtual void bpropUpdate(const Vec& input, const Vec& target,
00110                              real cost);
00111     */
00112 
00117     virtual void bbpropUpdate(const Vec& input, const Vec& target, real cost,
00118                               Vec& input_gradient, Vec& input_diag_hessian,
00119                               bool accumulate=false);
00120 
00121     /* Optional
00122        N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS,
00123        WHICH JUST CALLS
00124             bbpropUpdate(input, target, cost, input_gradient, in_hess)
00125        AND IGNORES INPUT HESSIAN AND INPUT GRADIENT.
00127     virtual void bbpropUpdate(const Vec& input, const Vec& target,
00128                               real cost);
00129     */
00130 
00134     virtual void forget();
00135 
00136 
00140     virtual void finalize();
00141 
00143     virtual bool bpropDoesNothing();
00144 
00146     virtual void setLearningRate(real dynamic_learning_rate);
00147 
00149     virtual TVec<string> costNames();
00150 
00151 
00152     //#####  PLearn::Object Protocol  #########################################
00153 
00154     // Declares other standard object methods.
00155     PLEARN_DECLARE_OBJECT(ProcessInputCostModule);
00156 
00157     // Simply calls inherited::build() then build_()
00158     virtual void build();
00159 
00161     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00162 
00163 
00164 protected:
00165     //#####  Protected Member Functions  ######################################
00166 
00168     static void declareOptions(OptionList& ol);
00169 
00170 private:
00171     //#####  Private Member Functions  ########################################
00172 
00174     void build_();
00175 
00176 private:
00177     //#####  Private Data Members  ############################################
00178 
00179     // The rest of the private stuff goes here
00180     //#####  Not Options  #####################################################
00181     mutable Vec processed_value;
00182     mutable Mat processed_values;
00183     mutable Vec processed_gradient;
00184     mutable Mat processed_gradients;
00185     mutable Vec processed_diag_hessian;
00186     mutable Mat processed_diag_hessians;
00187 };
00188 
00189 // Declares a few other classes and functions related to this class
00190 DECLARE_OBJECT_PTR(ProcessInputCostModule);
00191 
00192 } // end of namespace PLearn
00193 
00194 #endif
00195 
00196 
00197 /*
00198   Local Variables:
00199   mode:c++
00200   c-basic-offset:4
00201   c-file-style:"stroustrup"
00202   c-file-offsets:((innamespace . 0)(inline-open . 0))
00203   indent-tabs-mode:nil
00204   fill-column:79
00205   End:
00206 */
00207 // 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