From d7650aef95a06605030663eb7f9d69b9e9ac828e Mon Sep 17 00:00:00 2001 From: Bai Yifan Date: Mon, 17 Aug 2020 16:03:06 +0800 Subject: [PATCH] Add mse_loss_cn doc (#2385) * add mse_loss_cn doc * add index * add index --- doc/fluid/api/nn/functional.rst | 1 + doc/fluid/api/nn/functional/mse_loss.rst | 10 +++ doc/fluid/api_cn/nn_cn/functional_cn.rst | 1 + .../nn_cn/functional_cn/mse_loss_cn.rst | 66 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 doc/fluid/api/nn/functional/mse_loss.rst create mode 100644 doc/fluid/api_cn/nn_cn/functional_cn/mse_loss_cn.rst diff --git a/doc/fluid/api/nn/functional.rst b/doc/fluid/api/nn/functional.rst index 551924348..598b76a47 100644 --- a/doc/fluid/api/nn/functional.rst +++ b/doc/fluid/api/nn/functional.rst @@ -7,3 +7,4 @@ functional functional/l1_loss.rst functional/nll_loss.rst + functional/mse_loss.rst diff --git a/doc/fluid/api/nn/functional/mse_loss.rst b/doc/fluid/api/nn/functional/mse_loss.rst new file mode 100644 index 000000000..b5ec8c58b --- /dev/null +++ b/doc/fluid/api/nn/functional/mse_loss.rst @@ -0,0 +1,10 @@ +.. _api_nn_functional_mse_loss: + +mse_loss +------ + +.. autoclass:: paddle.nn.functional.mse_loss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api_cn/nn_cn/functional_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn.rst index b314bbe0e..b492a51cc 100644 --- a/doc/fluid/api_cn/nn_cn/functional_cn.rst +++ b/doc/fluid/api_cn/nn_cn/functional_cn.rst @@ -11,3 +11,4 @@ functional functional_cn/l1_loss_cn.rst functional_cn/nll_loss_cn.rst functional_cn/margin_ranking_loss_cn.rst + functional_cn/mse_loss_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/mse_loss_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/mse_loss_cn.rst new file mode 100644 index 000000000..99041e8ac --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/mse_loss_cn.rst @@ -0,0 +1,66 @@ +mse_loss +------------------------------- + +.. py:function:: paddle.nn.functional.mse_loss(input, label, reduction='mean', name=None) + +该OP用于计算预测值和目标值的均方差误差。 + +对于预测值input和目标值label,公式为: + +当 `reduction` 设置为 ``'none'`` 时, + + .. math:: + Out = (input - label)^2 + +当 `reduction` 设置为 ``'mean'`` 时, + + .. math:: + Out = \operatorname{mean}((input - label)^2) + +当 `reduction` 设置为 ``'sum'`` 时, + + .. math:: + Out = \operatorname{sum}((input - label)^2) + + +参数: +::::::::: + - **input** (Tensor) - 预测值,维度为 :math:`[N_1, N_2, ..., N_k]` 的多维Tensor。数据类型为float32或float64。 + - **label** (Tensor) - 目标值,维度为 :math:`[N_1, N_2, ..., N_k]` 的多维Tensor。数据类型为float32或float64。 + +返回 +::::::::: +``Tensor``, 输入 ``input`` 和标签 ``label`` 间的 `mse loss` 损失。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + # static graph mode + paddle.enable_static() + mse_loss = paddle.nn.loss.MSELoss() + input = paddle.data(name="input", shape=[1]) + label = paddle.data(name="label", shape=[1]) + place = paddle.CPUPlace() + input_data = np.array([1.5]).astype("float32") + label_data = np.array([1.7]).astype("float32") + output = mse_loss(input,label) + exe = paddle.static.Executor(place) + exe.run(paddle.static.default_startup_program()) + output_data = exe.run( + paddle.static.default_main_program(), + feed={"input":input_data, "label":label_data}, + fetch_list=[output], + return_numpy=True) + print(output_data) + # [array([0.04000002], dtype=float32)] + # dynamic graph mode + paddle.disable_static() + input = paddle.to_variable(input_data) + label = paddle.to_variable(label_data) + output = mse_loss(input, label) + print(output.numpy()) + # [0.04000002] + -- GitLab