adam_optimizer.h 808 字节
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 12
  AdamOptimizer(
      double beta_1, double beta_2, double epsilon, double decay, BaseLr *lr)
D
dzhwinter 已提交
13
      : ParameterOptimizer(lr),
14 15 16 17 18 19 20 21
        beta_1(beta_1),
        beta_2(beta_2),
        epsilon(epsilon),
        decay(decay) {}
  ~AdamOptimizer() {
    if (momentums_) delete momentums_;
    if (velocitys_) delete velocitys_;
  }
D
dzhwinter 已提交
22 23 24
  void update(const Tensor &gradient);
  void set_weight(Tensor *p);
  real *get_weight() const;
25 26

private:
D
dzhwinter 已提交
27 28
  Tensor *momentums_;
  Tensor *velocitys_;
29 30 31 32 33 34 35 36 37
  double beta_1;
  double beta_2;
  double epsilon;
  double decay;
};

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