pub struct HuberLoss {
pub delta: f32,
pub lin_bias: f32,
}
Expand description
Calculate the Huber loss between the inputs and the target.
The loss for each element of the residuals r = targets - predictions
is given by
L(r) = 0.5 * r^2 if |r| <= d
L(r) = 0.5 * d^2 + d * (|r| - d) if |r| > d
where d
is the configured delta
. In particular, this is equal to the
L2 Loss for residuals with magnitude smaller than delta
,
but behaves linearly instead of quadratically for large residuals.
This loss function is less sensitive to outliers than the mean squared error loss.
See also: https://en.wikipedia.org/wiki/Huber_loss
Fields§
§delta: f32
The bound where the Huber loss function changes from quadratic to linear behaviour.
lin_bias: f32
Precomputed value for the linear bias.
Implementations§
Source§impl HuberLoss
impl HuberLoss
Sourcepub fn forward<const D: usize, B: Backend>(
&self,
predictions: Tensor<B, D>,
targets: Tensor<B, D>,
reduction: Reduction,
) -> Tensor<B, 1>
pub fn forward<const D: usize, B: Backend>( &self, predictions: Tensor<B, D>, targets: Tensor<B, D>, reduction: Reduction, ) -> Tensor<B, 1>
Compute the loss element-wise for the predictions and targets, then reduce to a single loss value.
Reduction::Auto
behaves as Reduction::Mean
.
§Shapes
- predictions: […dims]
- targets: […dims]
- output: [1]
Trait Implementations§
Source§impl<B: AutodiffBackend> AutodiffModule<B> for HuberLoss
impl<B: AutodiffBackend> AutodiffModule<B> for HuberLoss
Source§type InnerModule = HuberLoss
type InnerModule = HuberLoss
Source§fn valid(&self) -> Self::InnerModule
fn valid(&self) -> Self::InnerModule
Source§impl<B: Backend> Module<B> for HuberLoss
impl<B: Backend> Module<B> for HuberLoss
Source§type Record = ConstantRecord
type Record = ConstantRecord
Source§fn visit<V: ModuleVisitor<B>>(&self, _visitor: &mut V)
fn visit<V: ModuleVisitor<B>>(&self, _visitor: &mut V)
Source§fn map<M: ModuleMapper<B>>(self, _mapper: &mut M) -> Self
fn map<M: ModuleMapper<B>>(self, _mapper: &mut M) -> Self
Source§fn load_record(self, _record: Self::Record) -> Self
fn load_record(self, _record: Self::Record) -> Self
Source§fn into_record(self) -> Self::Record
fn into_record(self) -> Self::Record
Source§fn to_device(self, _: &B::Device) -> Self
fn to_device(self, _: &B::Device) -> Self
Source§fn fork(self, _: &B::Device) -> Self
fn fork(self, _: &B::Device) -> Self
Source§fn collect_devices(&self, devices: Devices<B>) -> Devices<B>
fn collect_devices(&self, devices: Devices<B>) -> Devices<B>
Source§fn devices(&self) -> Devices<B>
fn devices(&self) -> Devices<B>
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn save_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
) -> Result<(), RecorderError>
fn save_file<FR, PB>( self, file_path: PB, recorder: &FR, ) -> Result<(), RecorderError>
std
only.Source§fn load_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
device: &B::Device,
) -> Result<Self, RecorderError>
fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &B::Device, ) -> Result<Self, RecorderError>
std
only.Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§impl ModuleDisplay for HuberLoss
impl ModuleDisplay for HuberLoss
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
Auto Trait Implementations§
impl Freeze for HuberLoss
impl RefUnwindSafe for HuberLoss
impl Send for HuberLoss
impl Sync for HuberLoss
impl Unpin for HuberLoss
impl UnwindSafe for HuberLoss
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.