adam_optimizer.h 788 字节
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 AdamOptimizer : public ParameterOptimizer {
9
public:
10
  AdamOptimizer(
D
dzhwinter 已提交
11
      double beta_1, double beta_2, double epsilon, double decay, LrPolicy *lr)
D
dzhwinter 已提交
12
      : ParameterOptimizer(lr),
13 14
        momentums_(nullptr),
        velocitys_(nullptr),
D
dzhwinter 已提交
15 16 17 18
        beta_1_(beta_1),
        beta_2_(beta_2),
        epsilon_(epsilon),
        decay_(decay) {}
19 20 21 22
  ~AdamOptimizer() {
    if (momentums_) delete momentums_;
    if (velocitys_) delete velocitys_;
  }
D
dzhwinter 已提交
23
  void Update(const Tensor *gradient);
D
dzhwinter 已提交
24
  void set_weight(Tensor *p);
25 26

private:
D
dzhwinter 已提交
27 28
  Tensor *momentums_;
  Tensor *velocitys_;
D
dzhwinter 已提交
29 30 31 32
  double beta_1_;
  double beta_2_;
  double epsilon_;
  double decay_;
33 34 35 36
};

}  // namespace optimizer
}  // namespace paddle