mindspore/docs/api/api_python/nn/mindspore.nn.Adagrad.rst

80 lines
3.4 KiB
ReStructuredText
Raw Normal View History

2021-12-04 09:42:36 +08:00
mindspore.nn.Adagrad
=====================
.. py:class:: mindspore.nn.Adagrad(*args, **kwargs)
2022-01-11 09:32:02 +08:00
Adagrad算法的实现。
2021-12-04 09:42:36 +08:00
Adagrad用于在线学习和随机优化。
2021-12-04 18:37:47 +08:00
请参阅论文 `Efficient Learning using Forward-Backward Splitting <https://proceedings.neurips.cc/paper/2009/file/621bf66ddb7c962aa0d22ac97d69b793-Paper.pdf>`_
2021-12-04 20:36:47 +08:00
2021-12-04 09:42:36 +08:00
公式如下:
.. math::
\begin{array}{ll} \\
2022-03-17 20:38:19 +08:00
&\newline
&\hline \\
&\textbf{Parameters}: \text{learning rate } \gamma, \: \text{ params } w_0, \:
\: \text{ weight decay } \lambda, \\
&\hspace{12mm} \text{ initial accumulator value } state\_sum\\
&\textbf{Init}: state\_sum_0 \leftarrow 0 \\[-1.ex]
&\newline
&\hline \\
&\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
&\hspace{5mm}g_t \leftarrow \nabla_{w} f_t (w_{t-1}) \\
&\hspace{5mm} \textbf{if} \: \lambda \neq 0 \\
&\hspace{10mm} g_t \leftarrow g_t + \lambda w_{t-1} \\
&\hspace{5mm}state\_sum_t \leftarrow state\_sum_{t-1} + g^2_t \\
&\hspace{5mm}w_t \leftarrow w_{t-1}- \gamma*\frac{g_t}{\sqrt{state\_sum_t} + \epsilon} \\
&\newline
&\hline \\
&\bf{return} \: w_t \\[-1.ex]
&\newline
&\hline \\
\end{array}
:math:`state\_sum` 表示梯度平方的累积和 :math:`accum` :math:`g` 表示 `grads` :math:`\lambda` 代表 `weight_decay`
:math:`\gamma` 代表 `learning_rate`:math:`w` 代表 `params`
2021-12-04 09:42:36 +08:00
.. note::
2022-01-11 09:32:02 +08:00
.. include:: mindspore.nn.optim_note_weight_decay.rst
2021-12-04 09:42:36 +08:00
**参数:**
- **params** (Union[list[Parameter], list[dict]]) - 必须是 `Parameter` 组成的列表或字典组成的列表。当列表元素是字典时,字典的键可以是"params"、"lr"、"weight_decay"、"grad_centralization"和"order_params"
.. include:: mindspore.nn.optim_group_param.rst
.. include:: mindspore.nn.optim_group_lr.rst
.. include:: mindspore.nn.optim_group_weight_decay.rst
.. include:: mindspore.nn.optim_group_gc.rst
.. include:: mindspore.nn.optim_group_order.rst
- **accum** (float) - 累加器 :math:`h` 的初始值必须大于等于零。默认值0.1。
- **learning_rate** (Union[float, Tensor, Iterable, LearningRateSchedule]) - 默认值0.001。
2021-12-04 20:36:47 +08:00
2021-12-04 09:42:36 +08:00
.. include:: mindspore.nn.optim_arg_dynamic_lr.rst
- **update_slots** (bool) - 如果为True则更新累加器 :math:`h` 。默认值True。
2022-01-21 12:00:58 +08:00
.. include:: mindspore.nn.optim_arg_loss_scale.rst
2021-12-04 09:42:36 +08:00
- **weight_decay** (Union[float, int]) - 要乘以权重的权重衰减值必须大于等于0.0。默认值0.0。
**输入:**
2022-01-20 16:02:51 +08:00
**grads** (tuple[Tensor]) - 优化器中 `params` 的梯度形状shape`params` 相同。
2021-12-04 09:42:36 +08:00
**输出:**
Tensor[bool]值为True。
**异常:**
- **TypeError** - `learning_rate` 不是int、float、Tensor、Iterable或 `LearningRateSchedule`
- **TypeError** - `parameters` 的元素是 `Parameter` 或字典。
- **TypeError** - `accum``loss_scale` 不是float。
- **TypeError** - `update_slots` 不是bool。
- **TypeError** - `weight_decay` 不是float或int。
- **ValueError** - `loss_scale` 小于或等于0。
- **ValueError** - `accum``weight_decay` 小于0。