Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Func.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) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: Func.h,v 1.11 2004/07/21 16:30:54 chrish42 Exp $ 00041 * AUTHORS: Pascal Vincent & Yoshua Bengio 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef FUNCTION_INC 00049 #define FUNCTION_INC 00050 00051 #include <plearn/base/general.h> 00052 #include <plearn/base/PP.h> 00053 #include <plearn/math/TMat.h> 00054 #include <plearn/vmat/VMat.h> 00055 #include "Variable.h" 00056 #include "VarArray.h" 00057 00058 namespace PLearn { 00059 using namespace std; 00060 00061 00062 class Function; 00063 class Func: public PP<Function> 00064 { 00065 public: 00066 Func(); 00067 00068 Func(Function* f); 00069 00070 Func(const VarArray& the_inputs, const VarArray& the_outputs); 00071 00072 Func(const VarArray& the_inputs, const VarArray& parameters_to_optimize,const VarArray& the_outputs); 00073 00074 Vec operator()(const Vec& input) const; 00075 00076 real operator()(const Vec& input1, const Vec& input2) const; 00077 00082 VarArray operator()(const VarArray& new_inputs) const; 00083 }; 00084 00085 class Function: public Object 00086 { 00087 public: 00088 00089 // Build options: 00090 mutable VarArray inputs; 00091 mutable VarArray parameters; 00092 mutable VarArray outputs; 00093 00094 // Other variables 00095 int inputsize; 00096 int outputsize; 00097 mutable VarArray fproppath; 00098 VarArray bproppath; 00099 VarArray parentspath; 00100 00101 Func df; 00102 00103 private: 00105 // (Please implement in .cc) 00106 void build_(); 00107 00108 protected: 00110 // (Please implement in .cc) 00111 static void declareOptions(OptionList& ol); 00112 00113 00114 public: 00115 Function(); 00116 Function(const VarArray& the_inputs, const VarArray& the_outputs); 00117 Function(const VarArray& the_inputs, const VarArray& parameters_to_optimize,const VarArray& the_outputs); 00118 //void bprop(VarArray& parameters_to_optimize); 00119 00120 public: 00121 00122 // ************************ 00123 // **** Object methods **** 00124 // ************************ 00125 00127 virtual void build(); 00128 00130 virtual void makeDeepCopyFromShallowCopy(map<const void*, void*>& copies); 00131 00132 // Declares other standard object methods 00133 // If your class is not instantiatable (it has pure virtual methods) 00134 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00135 typedef Object inherited; 00136 PLEARN_DECLARE_OBJECT(Function); 00137 00138 00139 // ************************** 00140 // **** Function methods **** 00141 // ************************** 00142 00143 void fprop(const Vec& in, const Vec& out) const; 00144 void fprop(const Array<Vec>& in, const Array<Vec>& out) const; 00145 00151 void fbprop(const Vec& in, const Vec& out, const Vec& input_gradient, const Vec& output_gradient); 00152 void fbprop(const Array<Vec>& in, const Array<Vec>& out, 00153 const Array<Vec>& input_gradient, const Array<Vec>& output_gradient); 00154 00156 void fbbprop(const Vec& in, const Vec& out, const Vec& gradient, const Mat& hessian); 00158 void fbbpropAcc(const Vec& in, const Vec& out, const Vec& gradient, const Mat& hessian); 00159 00160 void rfprop(const Vec& in, const Vec& out, const Vec& input_rvalue, const Vec& output_rvalue, bool do_fprop=true); 00161 00162 void recomputeParents(); 00163 00169 Func differentiate(); 00170 00171 Vec operator()(const Vec& input) const; 00172 real operator()(const Vec& input1, const Vec& input2) const; 00173 00182 VarArray operator()(const VarArray& new_inputs) const; 00183 00185 void verifyGradient(const Vec& in, real step=0.01); 00186 00187 void verifyHessian(const Vec& in, real step=0.01); 00188 00190 void verifyGradient(real minval, real maxval, real step=0.01); 00191 00193 void verifyGradient(real step=0.01); 00194 00199 void verifySymbolicGradient(const Vec& in); 00200 00201 // This is developed to make sure that the code of rfprop is correct. 00202 // The value of H * r computed by rfprop or Hessian should be the same. 00203 void verifyrfprop(const Vec& in, real step=0.01); 00204 }; 00205 00206 DECLARE_OBJECT_PTR(Function); 00207 DECLARE_OBJECT_PP(Func, Function); 00208 00209 Func operator/(Func f, real value); 00210 00211 template <> void deepCopyField(Func& field, CopiesMap& copies); 00212 00213 } // end of namespace PLearn 00214 00215 #endif 00216

Generated on Tue Aug 17 15:53:33 2004 for PLearn by doxygen 1.3.7