sgd_optimizer.h 623 字节
Newer Older
1 2 3 4 5 6 7 8
#ifndef PADDLE_SGD_OPTIMIZER_H_
#define PADDLE_SGD_OPTIMIZER_H_

#include "parameter_optimizer.h"

namespace paddle {
namespace optimizer {

D
dzhwinter 已提交
9
class SGDOptimizer : public ParameterOptimizer {
10
public:
D
dzhwinter 已提交
11 12
  SGDOptimizer(double m, double d, bool n, LrPolicy* lr)
      : ParameterOptimizer(lr), momentum_(m), decay_(d), nesterov_(n) {}
D
dzhwinter 已提交
13
  virtual ~SGDOptimizer() { delete momentums_; }
D
dzhwinter 已提交
14
  void Update(const Tensor* gradient);
D
dzhwinter 已提交
15 16 17

  void set_weight(Tensor* p);
  real* get_weight() const;
18 19

private:
D
dzhwinter 已提交
20
  Tensor* momentums_;
D
dzhwinter 已提交
21 22 23
  double momentum_;
  double decay_;
  bool nesterov_;
24 25 26 27 28 29
};

}  // namespace optimizer
}  // namespace paddle

#endif