parameter_optimizer.h 928 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef PADDLE_PARAMETER_OPTIMIZER_H_
#define PADDLE_PARAMETER_OPTIMIZER_H_

#include <glog/logging.h>
#include <functional>
#include <string>
#include "OptimizerConfig.pb.h"
#include "Tensor.h"
#include "lr_policy.h"

namespace paddle {
namespace optimizer {

class ParameterOptimizer {
public:
  /**
   * @brief  update hook for algorithm need to traverse parameter more than
   * once.
   */
20 21 22
  ParameterOptimizer(BaseLr *lr) : lr_policy(lr), num_sample_passed(0) {}
  virtual ~ParameterOptimizer() { delete parameter_; };

23
  static ParameterOptimizer *create(const ::std::string &config_proto);
24
  virtual void update(const Tensor *gradient) = 0;
D
dzhwinter 已提交
25 26
  virtual real *get_weight() const;
  virtual void set_weight(Tensor *parameter);
27

28
public:
29
  OptimizerConfig config_;
D
dzhwinter 已提交
30
  Tensor *parameter_;
31 32 33 34 35 36 37 38 39 40

  // learning rate policy
  BaseLr *lr_policy;
  uint64_t num_sample_passed;
};

}  // namespace optimizer
}  // namespace paddle

#endif