adam_optimizer.h 758 字节
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),
D
dzhwinter 已提交
13 14 15 16
        beta_1_(beta_1),
        beta_2_(beta_2),
        epsilon_(epsilon),
        decay_(decay) {}
17 18 19 20
  ~AdamOptimizer() {
    if (momentums_) delete momentums_;
    if (velocitys_) delete velocitys_;
  }
D
dzhwinter 已提交
21
  void Update(const Tensor *gradient);
D
dzhwinter 已提交
22 23
  void set_weight(Tensor *p);
  real *get_weight() const;
24 25

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

}  // namespace optimizer
}  // namespace paddle