adam_optimizer.h 888 字节
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),
D
dzhwinter 已提交
16 17 18
        beta_1_(beta_1),
        beta_2_(beta_2),
        epsilon_(epsilon),
D
dzhwinter 已提交
19 20 21 22 23
        decay_(decay) {
    size_t size = p->size();
    momentums_ = new Tensor(size);
    velocitys_ = new Tensor(size);
  }
24 25 26 27
  ~AdamOptimizer() {
    if (momentums_) delete momentums_;
    if (velocitys_) delete velocitys_;
  }
D
dzhwinter 已提交
28
  void Update(const Tensor *gradient);
29 30

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

}  // namespace optimizer
}  // namespace paddle