mindspore.nn.NaturalExpDecayLR

class mindspore.nn.NaturalExpDecayLR(learning_rate, decay_rate, decay_steps, is_stair=False)[source]

Calculates learning rate base on natural exponential decay function.

For the i-th step, the formula of computing decayed_learning_rate[i] is:

\[decayed\_learning\_rate[i] = learning\_rate * e^{-decay\_rate * p}\]

Where :

\[p = \frac{current\_step}{decay\_steps}\]

If is_stair is True, the formula is :

\[p = floor(\frac{current\_step}{decay\_steps})\]
Parameters
  • learning_rate (float) – The initial value of learning rate.

  • decay_rate (float) – The decay rate.

  • decay_steps (int) – A value used to calculate decayed learning rate.

  • is_stair (bool) – If true, learning rate is decayed once every decay_steps time. Default: False.

Inputs:

Tensor. The current step number.

Outputs:

Tensor. The learning rate value for the current step.

Examples

>>> learning_rate = 0.1
>>> decay_rate = 0.9
>>> decay_steps = 4
>>> global_step = Tensor(2, mstype.int32)
>>> natural_exp_decay_lr = nn.NaturalExpDecayLR(learning_rate, decay_rate, decay_steps, True)
>>> result = natural_exp_decay_lr(global_step)
>>> print(result)
0.1