adagrad_optimizer.h 780 字节
Newer Older
D
dzhwinter 已提交
1
#pragma once
2 3 4 5 6 7

#include "parameter_optimizer.h"

namespace paddle {
namespace optimizer {

D
dzhwinter 已提交
8
class AdagradOptimizer : public ParameterOptimizer {
9
public:
D
dzhwinter 已提交
10 11 12 13
  AdagradOptimizer(Tensor *parameter,
                   LrPolicy *lr,
                   double epsilon,
                   double decay)
D
dzhwinter 已提交
14 15 16 17
      : ParameterOptimizer(parameter, lr),
        accum_gradient_(new Tensor(parameter->size())),
        epsilon_(epsilon),
        decay_(decay) {}
18
  ~AdagradOptimizer() {
D
dzhwinter 已提交
19
    if (accum_gradient_) delete accum_gradient_;
20
  }
D
dzhwinter 已提交
21
  void Update(const Tensor *gradient);
D
dzhwinter 已提交
22
  const char *SerializeState(int *state_len);
D
dzhwinter 已提交
23
  void DeserializeState(const std::string &state);
24 25

private:
D
dzhwinter 已提交
26 27 28
  Tensor *accum_gradient_;
  double epsilon_;
  double decay_;
29 30 31 32
};

}  // namespace optimizer
}  // namespace paddle