Creates a criterion that measures the mean absolute error (MAE) between each
element in the input
nn_l1_loss(reduction = "mean")
(string, optional): Specifies the reduction to apply to the output:
'none'
| 'mean'
| 'sum'
. 'none'
: no reduction will be applied,
'mean'
: the sum of the output will be divided by the number of
elements in the output, 'sum'
: the output will be summed.
Input:
Target:
Output: scalar. If reduction
is 'none'
, then
The unreduced (i.e. with reduction
set to 'none'
) loss can be described
as:
where reduction
is not 'none'
(default 'mean'
), then:
The sum operation still operates over all the elements, and divides by reduction = 'sum'
.
if (torch_is_installed()) {
loss <- nn_l1_loss()
input <- torch_randn(3, 5, requires_grad = TRUE)
target <- torch_randn(3, 5)
output <- loss(input, target)
output$backward()
}
Run the code above in your browser using DataLab