adam_optimizer.h 818 字节
Newer Older
1 2 3 4 5 6 7 8
#ifndef PADDLE_ADAM_OPTIMIZER_H_
#define PADDLE_ADAM_OPTIMIZER_H_

#include "parameter_optimizer.h"

namespace paddle {
namespace optimizer {

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

}  // namespace optimizer
}  // namespace paddle
#endif