mindspore.ops.ApplyCenteredRMSProp
- class mindspore.ops.ApplyCenteredRMSProp(*args, **kwargs)[source]
Optimizer that implements the centered RMSProp algorithm. Please refer to the usage in source code of nn.RMSProp.
The updating formulas of ApplyCenteredRMSProp algorithm are as follows,
where
represents var, which will be updated. represents mean_gradient, is the last momentent of . represents mean_square, is the last momentent of , represents moment, is the last momentent of . represents decay. is the momentum term, represents momentum. is a smoothing term to avoid division by zero, represents epsilon. represents learning_rate. represents grad.- Parameters
use_locking (bool) – Whether to enable a lock to protect the variable and accumlation tensors from being updated. Default: False.
- Inputs:
var (Tensor) - Weights to be update.
mean_gradient (Tensor) - Mean gradients, must have the same type as var.
mean_square (Tensor) - Mean square gradients, must have the same type as var.
moment (Tensor) - Delta of var, must have the same type as var.
grad (Tensor) - Gradient, must have the same type as var.
learning_rate (Union[Number, Tensor]) - Learning rate. Must be a float number or a scalar tensor with float16 or float32 data type.
decay (float) - Decay rate.
momentum (float) - Momentum.
epsilon (float) - Ridge term.
- Outputs:
Tensor, parameters to be update.
- Raises
TypeError – If use_locking is not a bool.
TypeError – If var, mean_gradient, mean_square, moment or grad is not a Tensor.
TypeError – If learing_rate is neither a Number nor a Tensor.
TypeError – If dtype of learing_rate is neither float16 nor float32.
TypeError – If dtype of decay, momentum or epsilon is not float.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> import mindspore.ops as ops >>> import mindspore.nn as nn >>> from mindspore import Tensor >>> from mindspore import Parameter >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.apply_centerd_rms_prop = ops.ApplyCenteredRMSProp() ... self.var = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="var") ... ... def construct(self, mean_grad, mean_square, moment, grad, decay, momentum, epsilon, lr): ... out = self.apply_centerd_rms_prop(self.var, mean_grad, mean_square, moment, grad, ... lr, decay, momentum, epsilon) ... return out ... >>> net = Net() >>> mean_grad = Tensor(np.ones([2, 2]).astype(np.float32)) >>> mean_square = Tensor(np.ones([2, 2]).astype(np.float32)) >>> moment = Tensor(np.ones([2, 2]).astype(np.float32)) >>> grad = Tensor(np.ones([2, 2]).astype(np.float32)) >>> output = net(mean_grad, mean_square, moment, grad, 0.0, 1e-10, 0.001, 0.01) >>> print(net.var.asnumpy()) [[0.68377227 0.68377227] [0.68377227 0.68377227]]