sgd_optimizer.h 775 字节
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
  SGDOptimizer(double m, double d, bool n, LrPolicy* lr)
12 13 14 15 16
      : ParameterOptimizer(lr),
        momentums_(nullptr),
        momentum_(m),
        decay_(d),
        nesterov_(n) {}
D
dzhwinter 已提交
17
  virtual ~SGDOptimizer() { delete momentums_; }
D
dzhwinter 已提交
18
  void Update(const Tensor* gradient);
19 20
  const char* SerializeState();
  void DeSerializeState(const std::string& state);
D
dzhwinter 已提交
21 22

  void set_weight(Tensor* p);
23
  float* get_weight(int* param_size) const;
24 25

private:
D
dzhwinter 已提交
26
  Tensor* momentums_;
D
dzhwinter 已提交
27 28 29
  double momentum_;
  double decay_;
  bool nesterov_;
30 31 32 33 34 35
};

}  // namespace optimizer
}  // namespace paddle

#endif