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,

\[\begin{split}\begin{array}{ll} \\ g_{t} = \rho g_{t-1} + (1 - \rho)\nabla Q_{i}(w) \\ s_{t} = \rho s_{t-1} + (1 - \rho)(\nabla Q_{i}(w))^2 \\ m_{t} = \beta m_{t-1} + \frac{\eta} {\sqrt{s_{t} - g_{t}^2 + \epsilon}} \nabla Q_{i}(w) \\ w = w - m_{t} \end{array}\end{split}\]

where \(w\) represents var, which will be updated. \(g_{t}\) represents mean_gradient, \(g_{t-1}\) is the last momentent of \(g_{t}\). \(s_{t}\) represents mean_square, \(s_{t-1}\) is the last momentent of \(s_{t}\), \(m_{t}\) represents moment, \(m_{t-1}\) is the last momentent of \(m_{t}\). \(\\rho\) represents decay. \(\\beta\) is the momentum term, represents momentum. \(\\epsilon\) is a smoothing term to avoid division by zero, represents epsilon. \(\\eta\) represents learning_rate. \(\\nabla Q_{i}(w)\) 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

>>> centered_rms_prop = ops.ApplyCenteredRMSProp()
>>> input_x = Tensor(np.arange(-2, 2).astype(np.float32).reshape(2, 2), mindspore.float32)
>>> mean_grad = Tensor(np.arange(4).astype(np.float32).reshape(2, 2), mindspore.float32)
>>> mean_square = Tensor(np.arange(-3, 1).astype(np.float32).reshape(2, 2), mindspore.float32)
>>> moment = Tensor(np.arange(4).astype(np.float32).reshape(2, 2), mindspore.float32)
>>> grad = Tensor(np.arange(4).astype(np.float32).reshape(2, 2), mindspore.float32)
>>> learning_rate = Tensor(0.9, mindspore.float32)
>>> decay = 0.0
>>> momentum = 1e-10
>>> epsilon = 0.05
>>> output = centered_rms_prop(input_x, mean_grad, mean_square, moment, grad,
...                            learning_rate, decay, momentum, epsilon)
>>> output
Tensor(shape=[2, 2], dtype=Float32, value=
[[-2.00000000e+00, -5.02492237e+00],
 [-8.04984474e+00, -1.10747662e+01]])