Struct PoissonNllLoss
pub struct PoissonNllLoss {
pub log_input: bool,
pub full: bool,
pub eps: f64,
}
Expand description
Negative Log Likelihood (NLL) loss with a Poisson distribution assumption for the target.
This loss function is used when the target values are assumed to follow a Poisson distribution. The loss is defined as:
target ~ Poisson(input)
L(predictions, target) = predictions - target * log(predictions) + log(target!)
The last term (log(target!)
) can be omitted or approximated using Stirling’s
formula.
The approximation is applied for target > 1
, while for
target <= 1
, zeros are added to the loss.
For more details, see: https://en.wikipedia.org/wiki/Poisson_regression#Maximum_likelihood-based_parameter_estimation
Fields§
§log_input: bool
If true
, the predictions are expected to be in log-space.
full: bool
Whether to compute the full loss, including the Stirling approximation term.
eps: f64
A small value to avoid evaluation of log(0)
when log_input
is
false
.
Implementations§
§
impl PoissonNllLoss
impl PoissonNllLoss
pub fn forward<const D: usize,
B>(
&self,
predictions: Tensor<B, D>,
targets: Tensor<B, D>,
reduction: Reduction,
) -> Tensor<B, 1>where
B: Backend,
pub fn forward<const D: usize,
B>(
&self,
predictions: Tensor<B, D>,
targets: Tensor<B, D>,
reduction: Reduction,
) -> Tensor<B, 1>where
B: Backend,
Computes the loss element-wise for the given predictions and targets, then reduces the result to a single loss value.
§Arguments
predictions
: The predicted values.targets
: The target values.reduction
: The reduction method to apply.Reduction::Auto
behaves asReduction::Mean
.
§Shapes
predictions
:[...dims]
targets
:[...dims]
output
:[1]
§Panics
- Panics if the shapes of
predictions
andtargets
do not match. - Panics if any target value is negative.
- Panics if
log_input
isfalse
and any prediction value is negative.
pub fn forward_no_reduction<const D: usize,
B>(
&self,
predictions: Tensor<B, D>,
targets: Tensor<B, D>,
) -> Tensor<B, D>where
B: Backend,
pub fn forward_no_reduction<const D: usize,
B>(
&self,
predictions: Tensor<B, D>,
targets: Tensor<B, D>,
) -> Tensor<B, D>where
B: Backend,
Computes the loss element-wise for the given predictions and targets without reduction.
§Arguments
predictions
: The predicted values.targets
: The target values.
§Shapes
predictions
:[...dims]
targets
:[...dims]
output
:[...dims]
§Panics
- Panics if the shapes of
predictions
andtargets
do not match. - Panics if any target value is negative.
- Panics if
log_input
isfalse
and any prediction value is negative.
Trait Implementations§
§
impl<B> AutodiffModule<B> for PoissonNllLoss
where
B: AutodiffBackend,
impl<B> AutodiffModule<B> for PoissonNllLoss
where
B: AutodiffBackend,
§
type InnerModule = PoissonNllLoss
type InnerModule = PoissonNllLoss
§
fn valid(&self) -> <PoissonNllLoss as AutodiffModule<B>>::InnerModule
fn valid(&self) -> <PoissonNllLoss as AutodiffModule<B>>::InnerModule
§
impl Clone for PoissonNllLoss
impl Clone for PoissonNllLoss
§
fn clone(&self) -> PoissonNllLoss
fn clone(&self) -> PoissonNllLoss
1.0.0 · Source§
fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read
more
§
impl Debug for PoissonNllLoss
impl Debug for PoissonNllLoss
§
impl Display for PoissonNllLoss
impl Display for PoissonNllLoss
§
impl<B> Module<B> for PoissonNllLoss
where
B: Backend,
impl<B> Module<B> for PoissonNllLoss
where
B: Backend,
§
type Record = ConstantRecord
type Record = ConstantRecord
§
fn visit<V>(&self, _visitor: &mut
V)where
V: ModuleVisitor<B>,
fn visit<V>(&self, _visitor: &mut
V)where
V: ModuleVisitor<B>,
§
fn map<M>(self, _mapper: &mut
M) -> PoissonNllLoss
where
M: ModuleMapper<B>,
fn map<M>(self, _mapper: &mut
M) -> PoissonNllLoss
where
M: ModuleMapper<B>,
§
fn load_record(
self,
_record: <PoissonNllLoss as Module<B>>::Record,
) -> PoissonNllLoss
fn load_record( self, _record: <PoissonNllLoss as Module<B>>::Record, ) -> PoissonNllLoss
§
fn into_record(self) -> <PoissonNllLoss as Module<B>>::Record
fn into_record(self) -> <PoissonNllLoss as Module<B>>::Record
§
fn to_device(self, _: &<B as Backend>::Device) -> PoissonNllLoss
fn to_device(self, _: &<B as Backend>::Device) -> PoissonNllLoss
§
fn fork(self, _: &<B as Backend>::Device) -> PoissonNllLoss
fn fork(self, _: &<B as Backend>::Device) -> PoissonNllLoss
§
fn collect_devices(
&self,
devices: Vec<<B as Backend>::Device>,
) -> Vec<<B as Backend>::Device>
fn collect_devices( &self, devices: Vec<<B as Backend>::Device>, ) -> Vec<<B as Backend>::Device>
§
fn devices(&self) -> Vec<<B as Backend>::Device>
fn devices(&self) -> Vec<<B as Backend>::Device>
§
fn num_params(&self) -> usize
fn num_params(&self) -> usize
§
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>
§
fn load_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
device: &<B as Backend>::Device,
) -> Result<Self, RecorderError>
fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &<B as Backend>::Device, ) -> Result<Self, RecorderError>
§
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
§
impl ModuleDisplay for PoissonNllLoss
impl ModuleDisplay for PoissonNllLoss
§
fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
§
fn custom_content(&self, content: Content) -> Option<Content>
fn custom_content(&self, content: Content) -> Option<Content>
§
fn format(&self, passed_settings: DisplaySettings) ->
String
fn format(&self, passed_settings: DisplaySettings) -> String
§
impl ModuleDisplayDefault for PoissonNllLoss
impl ModuleDisplayDefault for PoissonNllLoss
Auto Trait Implementations§
impl Freeze for PoissonNllLoss
impl RefUnwindSafe for PoissonNllLoss
impl Send for PoissonNllLoss
impl Sync for PoissonNllLoss
impl Unpin for PoissonNllLoss
impl UnwindSafe for PoissonNllLoss
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,
§
impl<T> Instrument for T
impl<T> Instrument for T
§
fn instrument(self, span: Span) ->
Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§
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
more
Source§
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
more
§
impl<T> Pointable for T
impl<T> Pointable for T
§
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§
impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§
fn try_to_compact_string(&self)
-> Result<CompactString,
ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()
] Read more
§
fn to_compact_string(&self) ->
CompactString
fn to_compact_string(&self) -> CompactString
CompactString
].
Read more
§
impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§
fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
,
but without panic on OOM.