PLearn 0.1
|
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 // 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: ObjectOptionVariable.h 4493 2005-11-13 03:48:04Z morinf $ 00038 * This file is part of the PLearn library. 00039 ******************************************************* */ 00040 00041 #ifndef ObjectOptionVariable_INC 00042 #define ObjectOptionVariable_INC 00043 00044 #include "VarArray.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00058 class ObjectOptionVariable : public Variable 00059 { 00060 typedef Variable inherited; 00061 00062 public: 00063 //##### Public Build Options ############################################ 00064 00067 PP<Object> m_root; 00068 00070 string m_option_name; 00071 00078 string m_initial_value; 00079 00080 public: 00082 ObjectOptionVariable(); 00083 ObjectOptionVariable(PP<Object> root, const string& option_name, 00084 const string& initial_value=""); 00085 00086 00087 //##### PLearn::Object Protocol ######################################### 00088 00089 // Declares other standard object methods. 00090 PLEARN_DECLARE_OBJECT(ObjectOptionVariable); 00091 00092 // Simply calls inherited::build() then build_() 00093 virtual void build(); 00094 00096 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00097 00098 00099 //##### 'Variable' Interface ############################################ 00100 00101 virtual void setParents(const VarArray& parents); 00102 // { PLERROR("In Variable::setParents trying to set parents of a ObjectOptionVariable..."); } 00103 00104 virtual bool markPath(); 00105 virtual void buildPath(VarArray& proppath); 00106 00107 virtual void fprop(); 00108 virtual void bprop(); 00109 virtual void bbprop(); 00110 virtual void symbolicBprop(); 00111 virtual void rfprop(); 00112 virtual VarArray sources(); 00113 virtual VarArray random_sources(); 00114 virtual VarArray ancestors(); 00115 virtual void unmarkAncestors(); 00116 virtual VarArray parents(); 00117 bool isConstant() { return true; } 00118 00119 void printInfo(bool print_gradient) { 00120 pout << getName() << "[" << (void*)this << "] " << *this << " = " << value; 00121 if (print_gradient) pout << " gradient=" << gradient; 00122 pout << endl; 00123 } 00124 00125 // All the 'update' methods are overridden to be followed by an fprop(), 00126 // whose purpose is to reflect the contents of the updated Variable value 00127 // within the mirrorred object-option. 00128 virtual bool update(real step_size, Vec direction_vec, real coeff = 1.0, real b = 0.0); 00129 virtual bool update(Vec step_sizes, Vec direction_vec, real coeff = 1.0, real b = 0.0); 00130 virtual bool update(real step_size, bool clear=false); 00131 virtual bool update(Vec new_value); 00132 virtual void updateAndClear(); 00133 virtual void updateWithWeightDecay(real step_size, real weight_decay, 00134 bool L1, bool clear=true); 00135 00136 00137 protected: 00139 static void declareOptions(OptionList& ol); 00140 00141 private: 00143 void build_(); 00144 00146 Object* m_final_object; 00147 00150 enum OptionType { 00151 OptionTypeUnknown, 00152 OptionTypeInt, 00153 OptionTypeReal, 00154 OptionTypeVec, 00155 OptionTypeMat 00156 } m_option_type; 00157 00159 union { 00160 int* m_option_int; 00161 real* m_option_real; 00162 Vec* m_option_vec; 00163 Mat* m_option_mat; 00164 }; 00165 00167 int m_index; 00168 }; 00169 00170 00171 DECLARE_OBJECT_PTR(ObjectOptionVariable); 00172 00173 } // end of namespace PLearn 00174 00175 #endif 00176 00177 00178 /* 00179 Local Variables: 00180 mode:c++ 00181 c-basic-offset:4 00182 c-file-style:"stroustrup" 00183 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00184 indent-tabs-mode:nil 00185 fill-column:79 00186 End: 00187 */ 00188 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :