diff --git a/doc/fluid/api/nn/functional.rst b/doc/fluid/api/nn/functional.rst index 551924348e956066edf7affedb78a60e7adf2df4..598b76a479602a53a4d7073bc31c65ba3eddbe53 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 0000000000000000000000000000000000000000..b5ec8c58b5a10c206e85184f36e414396fc7d9b9 --- /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 b314bbe0ef25f09151745db0d91bdc8404eb540f..b492a51cccc1c67188fd6a733a260215a46be97f 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 0000000000000000000000000000000000000000..99041e8ac0bf5c0f5558c096d6e152b8b62b9094 --- /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] +