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

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

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

}  // namespace optimizer
}  // namespace paddle