00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
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;
00073
00074
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;
00093 Vec learning_rates;
00094 Vec gradient;
00095 Vec tmp_storage;
00096
00097
00098 Vec old_evol;
00099 Array<Mat> oldgradientlocations;
00100 Vec store_var_grad;
00101 Vec store_grad;
00102 Vec store_quad_grad;
00103 int count_updates;
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
00160
00161
00162
void adaptLearningRateBasic(
00163
Vec old_params,
00164
Vec new_evol);
00165
00166
00167
00168
00169
void adaptLearningRateALAP1(
00170
Vec old_gradient,
00171
Vec new_gradient);
00172
00173
00174
00175
00176
void adaptLearningRateVariance();
00177
00178
protected:
00179
00180
static void declareOptions(
OptionList& ol);
00181
00182 };
00183
00184 }
00185
00186
#endif