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: boolIf true, the predictions are expected to be in log-space.
full: boolWhether to compute the full loss, including the Stirling approximation term.
eps: f64A small value to avoid evaluation of log(0) when log_input is false.
Implementations§
Source§impl PoissonNllLoss
impl PoissonNllLoss
Sourcepub 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::Autobehaves asReduction::Mean.
§Shapes
predictions:[...dims]targets:[...dims]output:[1]
§Panics
- Panics if the shapes of
predictionsandtargetsdo not match. - Panics if any target value is negative.
- Panics if
log_inputisfalseand any prediction value is negative.
Sourcepub 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
predictionsandtargetsdo not match. - Panics if any target value is negative.
- Panics if
log_inputisfalseand any prediction value is negative.
Trait Implementations§
Source§impl<B> AutodiffModule<B> for PoissonNllLosswhere
B: AutodiffBackend,
impl<B> AutodiffModule<B> for PoissonNllLosswhere
B: AutodiffBackend,
Source§type InnerModule = PoissonNllLoss
type InnerModule = PoissonNllLoss
Source§fn valid(&self) -> <PoissonNllLoss as AutodiffModule<B>>::InnerModule
fn valid(&self) -> <PoissonNllLoss as AutodiffModule<B>>::InnerModule
Source§impl Clone for PoissonNllLoss
impl Clone for PoissonNllLoss
Source§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 moreSource§impl Debug for PoissonNllLoss
impl Debug for PoissonNllLoss
Source§impl Display for PoissonNllLoss
impl Display for PoissonNllLoss
Source§impl<B> Module<B> for PoissonNllLosswhere
B: Backend,
impl<B> Module<B> for PoissonNllLosswhere
B: Backend,
Source§type Record = ConstantRecord
type Record = ConstantRecord
Source§fn visit<V>(&self, _visitor: &mut V)where
V: ModuleVisitor<B>,
fn visit<V>(&self, _visitor: &mut V)where
V: ModuleVisitor<B>,
Source§fn map<M>(self, _mapper: &mut M) -> PoissonNllLosswhere
M: ModuleMapper<B>,
fn map<M>(self, _mapper: &mut M) -> PoissonNllLosswhere
M: ModuleMapper<B>,
Source§fn load_record(
self,
_record: <PoissonNllLoss as Module<B>>::Record,
) -> PoissonNllLoss
fn load_record( self, _record: <PoissonNllLoss as Module<B>>::Record, ) -> PoissonNllLoss
Source§fn into_record(self) -> <PoissonNllLoss as Module<B>>::Record
fn into_record(self) -> <PoissonNllLoss as Module<B>>::Record
Source§fn to_device(self, _: &<B as Backend>::Device) -> PoissonNllLoss
fn to_device(self, _: &<B as Backend>::Device) -> PoissonNllLoss
Source§fn fork(self, _: &<B as Backend>::Device) -> PoissonNllLoss
fn fork(self, _: &<B as Backend>::Device) -> PoissonNllLoss
Source§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>
Source§fn devices(&self) -> Vec<<B as Backend>::Device>
fn devices(&self) -> Vec<<B as Backend>::Device>
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>
Source§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>
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§impl ModuleDisplay for PoissonNllLoss
impl ModuleDisplay for PoissonNllLoss
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
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,
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 more