l1_loss#

ivy.l1_loss(input, target, /, *, reduction='mean', out=None)[source]#

Compute L1 loss (Mean Absolute Error - MAE) between targeticted and input values.

Parameters:
  • input (Union[ivy.Array, ivy.NativeArray]) – Input array containing input values.

  • target (Union[ivy.Array, ivy.NativeArray]) – Input array containing targeted values.

  • reduction (str, optional) – Reduction method for the output loss. Options: “none” (no reduction), “mean” (mean of losses), “sum” (sum of losses). Default: “mean”.

  • out (Optional[ivy.Array], optional) – Optional output array for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ivy.Array – The L1 loss (MAE) between the given input and targeticted values.

Examples

>>> x = ivy.array([1.0, 2.0, 3.0])
>>> y = ivy.array([0.5, 2.5, 2.0])
>>> ivy.l1_loss(x, y)
ivy.array(0.666)
>>> a = ivy.array([[1.0, 2.0], [3.0, 4.0]])
>>> b = ivy.array([[0.5, 1.5], [2.5, 3.5]])
>>> ivy.l1_loss(a, b)
ivy.array(0.5)
Array.l1_loss(self, target, /, *, reduction='mean', out=None)[source]#

ivy.Array instance method variant of ivy.l1_loss. This method simply wraps the function, and so the docstring for ivy.l1_loss also applies to this method with minimal changes.

Parameters:
  • self (Union[Array, NativeArray]) – input array containing true labels.

  • target (Union[Array, NativeArray]) – input array containing targeted labels.

  • reduction (Optional[str], default: 'mean') – 'mean': The output will be averaged. 'sum': The output will be summed. 'none': No reduction will be applied to the output. Default: 'mean'.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The L1 loss between the input array and the targeticted values.

Examples

>>> x = ivy.array([1.0, 2.0, 3.0])
>>> y = ivy.array([0.7, 1.8, 2.9])
>>> z = x.l1_loss(y)
>>> print(z)
ivy.array(0.20000000000000004)
Container.l1_loss(self, target, /, *, reduction='mean', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.l1_loss. This method simply wraps the function, and so the docstring for ivy.l1_loss also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container.

  • target (Union[Container, Array, NativeArray]) – input array or container containing the targeticted values.

  • reduction (Optional[Union[str, Container]], default: 'mean') – 'mean': The output will be averaged. 'sum': The output will be summed. 'none': No reduction will be applied to the output. Default: 'mean'.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If input, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is input.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • out (Optional[Container], default: None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – The L1 loss between the input array and the targeticted values.

Examples

>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([4, 5, 6]))
>>> y = ivy.Container(a=ivy.array([2, 2, 2]), b=ivy.array([5, 5, 5]))
>>> z = x.l1_loss(y)
>>> print(z)
{
    a: ivy.array(0.),
    b: ivy.array(0.)
}