sgd_optimizer.h 645 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#ifndef PADDLE_SGD_OPTIMIZER_H_
#define PADDLE_SGD_OPTIMIZER_H_

#include "parameter_optimizer.h"

namespace paddle {
namespace optimizer {

template <class T>
class SGDOptimizer : public ParameterOptimizer<T> {
public:
  SGDOptimizer(const ::paddle::OptimizerConfig& config);
  ~SGDOptimizer() {
    // clear memory by Tensor library
    delete momentums_;
  }
  void update(const Tensor<T>& gradient);

  void set_weight(const Tensor<T>* p);
  T* get_weight() const;
  char* get_config_proto();

private:
  Tensor<T>* momentums_;
  double momentum;
  double decay;
  bool nesterov;
};

}  // namespace optimizer
}  // namespace paddle

#endif