MCPcopy Create free account
hub / github.com/apache/singa / Apply

Method Apply

src/model/optimizer/adagrad.cc:28–47  ·  view source on GitHub ↗

history += grad*grad; value = value - lr*grad/sqrt(history+delta)

Source from the content-addressed store, hash-verified

26// history += grad*grad;
27// value = value - lr*grad/sqrt(history+delta)
28void AdaGrad::Apply(int epoch, float lr, const string& name,
29 Tensor& grad, Tensor& value, int step) {
30 if (grad.empty())
31 return;
32 ApplyRegularizerConstraint(epoch, name, value, grad, step);
33 if (learning_rate_multplier_.find(name) != learning_rate_multplier_.end())
34 lr *= learning_rate_multplier_.at(name);
35
36 if (history_gradient_.find(name) == history_gradient_.end()) {
37 history_gradient_[name].ResetLike(value);
38 history_gradient_[name].SetValue(0.0f);
39 }
40 Tensor& history = history_gradient_[name];
41 Tensor tmp = Square(grad);
42 history += tmp;
43 Add(history, delta_, &tmp);
44 Sqrt(tmp, &tmp);
45 Div(grad, tmp, &tmp);
46 Axpy(-lr, tmp, &value);
47}
48} // namespace singa
49#endif // SRC_MODEL_OPTIMIZER_ADAGRAD_H_

Callers

nothing calls this directly

Calls 8

SquareFunction · 0.85
emptyMethod · 0.80
AddFunction · 0.50
SqrtFunction · 0.50
DivFunction · 0.50
AxpyFunction · 0.50
endMethod · 0.45
SetValueMethod · 0.45

Tested by

no test coverage detected