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

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

}  // namespace optimizer
}  // namespace paddle