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

AdaptGradientOptimizer.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-2003 Pascal Vincent, Yoshua Bengio, 00006 // Olivier Delalleau and University of Montreal 00007 // 00008 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are met: 00011 // 00012 // 1. Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // 00015 // 2. Redistributions in binary form must reproduce the above copyright 00016 // notice, this list of conditions and the following disclaimer in the 00017 // documentation and/or other materials provided with the distribution. 00018 // 00019 // 3. The name of the authors may not be used to endorse or promote 00020 // products derived from this software without specific prior written 00021 // permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00024 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00025 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00026 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00028 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00029 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00030 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00031 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00032 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 // 00034 // This file is part of the PLearn library. For more information on the PLearn 00035 // library, go to the PLearn Web site at www.plearn.org 00036 00037 00038 00039 00040 /* ******************************************************* 00041 * $Id: AdaptGradientOptimizer.h,v 1.10 2004/02/20 21:11:48 chrish42 Exp $ 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef AdaptGradientOptimizer_INC 00049 #define AdaptGradientOptimizer_INC 00050 00051 #include "Optimizer.h" 00052 00053 namespace PLearn { 00054 using namespace std; 00055 00056 00064 class AdaptGradientOptimizer : public Optimizer 00065 { 00066 typedef Optimizer inherited; 00067 00068 public: 00069 00072 real learning_rate; // current learning rate 00073 00074 // Options (also available through setOption) 00075 real start_learning_rate; 00076 real min_learning_rate; 00077 real max_learning_rate; 00078 00079 00080 00081 00082 00083 int learning_rate_adaptation; 00084 real adapt_coeff1; 00085 real adapt_coeff2; 00086 real decrease_constant; 00087 int mini_batch; 00088 int adapt_every; 00089 00090 private: 00091 00092 bool stochastic_hack; // true when we're computing a stochastic gradient 00093 Vec learning_rates; // used to store the individual learning rates 00094 Vec gradient; // used to store the gradient 00095 Vec tmp_storage; // used to store various stuff 00096 // used to store the previous weights evolution, it can be used to 00097 // see how many times a weight has increased / decreased consecutively 00098 Vec old_evol; 00099 Array<Mat> oldgradientlocations; // used for the stochastic hack 00100 Vec store_var_grad; // used to store the gradient variance 00101 Vec store_grad; // used to store the gradient 00102 Vec store_quad_grad; // used to store the gradient^2 00103 int count_updates; // used to count how many examples we went through 00104 00105 public: 00106 00107 AdaptGradientOptimizer(real the_start_learning_rate=0.01, 00108 real the_decrease_constant=0, 00109 real the_min_learning_rate=0.001, 00110 real the_max_learning_rate=0.02, 00111 int the_learning_rate_adaptation=0, 00112 real the_adapt_coeff1=0, 00113 real the_adapt_coeff2=0, 00114 int n_updates=1, const string& filename="", 00115 int every_iterations=1); 00116 AdaptGradientOptimizer(VarArray the_params, Var the_cost, 00117 real the_start_learning_rate=0.01, 00118 real the_decrease_constant=0, 00119 real the_min_learning_rate=0.001, 00120 real the_max_learning_rate=0.02, 00121 int the_learning_rate_adaptation=0, 00122 real the_adapt_coeff1=0, 00123 real the_adapt_coeff2=0, 00124 int n_updates=1, const string& filename="", 00125 int every_iterations=1); 00126 AdaptGradientOptimizer(VarArray the_params, Var the_cost, 00127 VarArray update_for_measure, 00128 real the_start_learning_rate=0.01, 00129 real the_decrease_constant=0, 00130 real the_min_learning_rate=0.001, 00131 real the_max_learning_rate=0.02, 00132 int the_learning_rate_adaptation=0, 00133 real the_adapt_coeff1=0, 00134 real the_adapt_coeff2=0, 00135 int n_updates=1, const string& filename="", 00136 int every_iterations=1); 00137 00138 00139 PLEARN_DECLARE_OBJECT(AdaptGradientOptimizer); 00140 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); } 00141 00142 virtual void build() 00143 { 00144 inherited::build(); 00145 build_(); 00146 } 00147 00148 private: 00149 00150 void build_(); 00151 00152 public: 00153 00154 virtual real optimize(); 00155 virtual bool optimizeN(VecStatsCollector& stats_coll); 00156 00157 private: 00158 00159 // Basic learning rate adaptation 00160 // If grad(i) > 0 : lr(i) = lr(i) + lr(i) * adapt_coeff1 00161 // else : lr(i) = lr(i) - lr(i) * adapt_coeff2 00162 void adaptLearningRateBasic( 00163 Vec old_params, 00164 Vec new_evol); 00165 00166 // ALAP1 formula learning rate adaptation 00167 // lr = lr + adapt_coeff1 * dot(grad(k-1), grad(k)) 00168 // NB: has not been tested 00169 void adaptLearningRateALAP1( 00170 Vec old_gradient, 00171 Vec new_gradient); 00172 00173 // Learning rate adaptation depending on the variance : 00174 // If var(i) is low, lr(i) = max_learning_rate 00175 // else lr(i) = min_learning_rate 00176 void adaptLearningRateVariance(); 00177 00178 protected: 00179 00180 static void declareOptions(OptionList& ol); 00181 00182 }; 00183 00184 } // end of namespace PLearn 00185 00186 #endif

Generated on Tue Aug 17 15:48:11 2004 for PLearn by doxygen 1.3.7