sgd_optimizer.h 706 字节
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);
15 16
  const char* SerializeState();
  void DeSerializeState(const std::string& state);
D
dzhwinter 已提交
17 18 19

  void set_weight(Tensor* p);
  real* get_weight() const;
20 21

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

}  // namespace optimizer
}  // namespace paddle

#endif