huber_loss#
- ivy.huber_loss(true, pred, /, *, delta=1.0, reduction='mean', out=None)[source]#
Compute the Huber loss (smooth L1 loss) between true and predicted values.
- Parameters:
true (array_like) – The true (ground truth) values.
pred (array_like) – The predicted values by the model.
delta (float, optional) – The threshold parameter that determines the point where the loss transitions fro -m squared error to absolute error. Default is 1.0.
reduction (str, optional) – The type of reduction to apply to the loss. Possible values are “mean” (default) and “sum”.
out (array_like, optional) – Optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret (array_like) – The Huber loss between the true and predicted values.
Examples
>>> true = ivy.array([2, 4, 7, 1]) >>> pred = ivy.array([2.5, 3.5, 8, 0.8]) >>> huber_loss(true, pred, delta=1.0) ivy.array([0.125, 0.125, 0.5 , 0.125])
>>> huber_loss(true, pred, delta=2.0) ivy.array([0.125, 0.125, 0.5 , 0.2 ])
>>> huber_loss(true, pred, delta=0.5) ivy.array([0.25 , 0.25 , 0. , 0.125])
- Array.huber_loss(self, target, /, *, reduction='mean', delta=1.0, out=None)[source]#
ivy.Array instance method variant of huber_loss. This method simply wraps the function, and so the docstring for huber_loss also applies to this method with minimal changes.
- Parameters:
self (
Array) – input array containing true labels.target (
Union[Array,NativeArray]) – input array containing targeted labels.reduction (str, optional) – The type of reduction to apply to the loss. Possible values are “mean” (default) and “sum”.
delta (
Optional[float], default:1.0) – The threshold parameter that determines the point where the loss transitions from squared error to absolute error. Default is 1.0.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 Huber loss between the true and predicted values.
Examples
>>> true = ivy.array([2, 4, 7, 1]) >>> pred = ivy.array([2.5, 3.5, 8, 0.8]) >>> loss = true.huber_loss(pred, delta=1.0) >>> print(loss) ivy.array([0.125, 0.125, 0.5 , 0.125])
- Container.huber_loss(self, pred, /, *, delta=1.0, reduction='mean', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of huber_loss. This method simply wraps the function, and so the docstring for huber_loss also applies to this method with minimal changes.
- Parameters:
self (
Container) – true container containing true labels.pred (
Union[Container,Array,NativeArray]) – true array or container containing the predicted labels.delta (
Optional[Union[float,Container]], default:1.0) – The threshold parameter that determines the point where the loss transitions from squared error to absolute error. Default is 1.0.reduction (str, optional) – The type of reduction to apply to the loss. Possible values are “mean” (default) and “sum”.
key_chains (
Optional[Union[List[str],Dict[str,str],Container]], default:None) – The key-chains to apply or not apply the method to. Default isNone.to_apply (
Union[bool,Container], default:True) – If true, the method will be applied to key_chains, otherwise key_chains will be skipped. Default istrue.prune_unapplied (
Union[bool,Container], default:False) – Whether to prune key_chains for which the function was not applied. Default isFalse.map_sequences (
Union[bool,Container], default:False) – Whether to also map method to sequences (lists, tuples). Default isFalse.out (
Optional[Container], default:None) – optional output container, for writing the result to. It must have a shape that the trues broadcast to.
- Return type:
Container- Returns:
ret – The Huber loss between the true and predicted values.
Examples
>>> x = ivy.Container(a=ivy.array([1, 0, 3]), b=ivy.array([0, 0, 2])) >>> y = ivy.Container(a=ivy.array([1.5, 0.2, 2.8]), b=ivy.array([0.5, 0.2, 1.9]) ) >>> z = x.huber_loss(y, delta=1.0) >>> print(z) { a: ivy.array(0.0575), b: ivy.array(0.005) }