adadelta_optimizer.h 1010 字节
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 AdadeltaOptimizer : public ParameterOptimizer {
9
public:
D
dzhwinter 已提交
10 11 12
  AdadeltaOptimizer(
      Tensor *parameter, LrPolicy *lr, double rho, double epsilon, double decay)
      : ParameterOptimizer(parameter, lr),
D
dzhwinter 已提交
13 14 15
        accum_gradient_(new Tensor(parameter->size())),
        accum_delta_(new Tensor(parameter->size())),
        update_delta_(new Tensor(parameter->size())),
16 17
        rho_(rho),
        epsilon_(epsilon),
D
dzhwinter 已提交
18 19
        decay_(decay) {}

20
  ~AdadeltaOptimizer() {
D
dzhwinter 已提交
21 22 23
    if (accum_gradient_) delete accum_gradient_;
    if (accum_delta_) delete accum_delta_;
    if (update_delta_) delete update_delta_;
24
  }
D
dzhwinter 已提交
25
  void Update(const Tensor *gradient);
26
  std::string SerializeState();
D
dzhwinter 已提交
27
  void DeserializeState(const std::string &state);
28 29

private:
D
dzhwinter 已提交
30 31 32 33 34 35
  Tensor *accum_gradient_;
  Tensor *accum_delta_;
  Tensor *update_delta_;
  double rho_;
  double epsilon_;
  double decay_;
36 37 38 39
};

}  // namespace optimizer
}  // namespace paddle