You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.Adagrad.rst 3.4 kB

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