nn_mse_loss {torch} | R Documentation |
MSE loss
Description
Creates a criterion that measures the mean squared error (squared L2 norm) between
each element in the input and target
.
The unreduced (i.e. with
reduction
set to 'none'
) loss can be described
as:
Usage
nn_mse_loss(reduction = "mean")
Arguments
reduction |
(string, optional): Specifies the reduction to apply to the output:
|
Details
where is the batch size. If
reduction
is not 'none'
(default 'mean'
), then:
and
are tensors of arbitrary shapes with a total
of
elements each.
The mean operation still operates over all the elements, and divides by .
The division by
can be avoided if one sets
reduction = 'sum'
.
Shape
Input:
where
means, any number of additional dimensions
Target:
, same shape as the input
Examples
if (torch_is_installed()) {
loss <- nn_mse_loss()
input <- torch_randn(3, 5, requires_grad = TRUE)
target <- torch_randn(3, 5)
output <- loss(input, target)
output$backward()
}