adagrad_optimizer.h 732 字节
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 AdagradOptimizer : public ParameterOptimizer {
9
public:
D
dzhwinter 已提交
10 11 12 13 14 15 16 17 18
  AdagradOptimizer(Tensor *parameter,
                   LrPolicy *lr,
                   double epsilon,
                   double decay)
      : ParameterOptimizer(parameter, lr), epsilon_(epsilon), decay_(decay) {
    size_t size = p->size();
    if (accum_gradient_) delete accum_gradient_;
    accum_gradient_ = new Tensor(size);
  }
19
  ~AdagradOptimizer() {
D
dzhwinter 已提交
20
    if (accum_gradient_) delete accum_gradient_;
21
  }
D
dzhwinter 已提交
22
  void Update(const Tensor *gradient);
23 24

private:
D
dzhwinter 已提交
25 26 27
  Tensor *accum_gradient_;
  double epsilon_;
  double decay_;
28 29 30 31
};

}  // namespace optimizer
}  // namespace paddle