| 61 | */ |
| 62 | } |
| 63 | void Optimizer::ApplyRegularizerConstraint(int epoch, const string& name, |
| 64 | const Tensor& value, Tensor& grad, int step) { |
| 65 | // TODO(wangwei) need to consider the order of constraint and regularizer |
| 66 | if (regularizers_.find(name) != regularizers_.end()) { |
| 67 | regularizers_.at(name)->Apply(epoch, value, grad, step); |
| 68 | } else if (regularizer_ != nullptr) { |
| 69 | regularizer_->Apply(epoch, value, grad, step); |
| 70 | } |
| 71 | if (constraints_.find(name) != constraints_.end()) |
| 72 | constraints_.at(name)->Apply(epoch, value, grad, step); |
| 73 | else if (constraint_ != nullptr) |
| 74 | constraint_->Apply(epoch, value, grad, step); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void Optimizer::Apply(int epoch, const string& name, Tensor& grad, |