sgd_optimizer.h 742 字节
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 13 14 15 16 17
  using ParameterOptimizer::parameter_;
  using ParameterOptimizer::num_sample_passed;
  using ParameterOptimizer::lr_policy;

  SGDOptimizer(double m, double d, bool n, BaseLr* lr)
      : ParameterOptimizer(lr), momentum(m), decay(d), nesterov(n) {}
  virtual ~SGDOptimizer() { delete momentums_; }
18
  void update(const Tensor* gradient);
D
dzhwinter 已提交
19 20 21

  void set_weight(Tensor* p);
  real* get_weight() const;
22 23

private:
D
dzhwinter 已提交
24
  Tensor* momentums_;
25 26 27 28 29 30 31 32 33
  double momentum;
  double decay;
  bool nesterov;
};

}  // namespace optimizer
}  // namespace paddle

#endif