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: 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§
§impl PoissonNllLoss
impl PoissonNllLoss
pub fn forward<const D: usize>(
&self,
predictions: Tensor<D>,
targets: Tensor<D>,
reduction: Reduction,
) -> Tensor<1>
pub fn forward<const D: usize>( &self, predictions: Tensor<D>, targets: Tensor<D>, reduction: Reduction, ) -> Tensor<1>
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.
pub fn forward_no_reduction<const D: usize>(
&self,
predictions: Tensor<D>,
targets: Tensor<D>,
) -> Tensor<D>
pub fn forward_no_reduction<const D: usize>( &self, predictions: Tensor<D>, targets: Tensor<D>, ) -> Tensor<D>
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§
§impl Clone for PoissonNllLoss
impl Clone for PoissonNllLoss
§fn clone(&self) -> PoissonNllLoss
fn clone(&self) -> PoissonNllLoss
1.0.0 (const: unstable) · 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 Module for PoissonNllLoss
impl Module for PoissonNllLoss
§fn visit<V>(&self, _visitor: &mut V)where
V: ModuleVisitor,
fn visit<V>(&self, _visitor: &mut V)where
V: ModuleVisitor,
§fn map<M>(self, _mapper: &mut M) -> PoissonNllLosswhere
M: ModuleMapper,
fn map<M>(self, _mapper: &mut M) -> PoissonNllLosswhere
M: ModuleMapper,
§fn to_device(self, _: &Device) -> PoissonNllLoss
fn to_device(self, _: &Device) -> PoissonNllLoss
§fn fork(self, _: &Device) -> PoissonNllLoss
fn fork(self, _: &Device) -> PoissonNllLoss
§fn collect_devices(&self, devices: Vec<Device>) -> Vec<Device>
fn collect_devices(&self, devices: Vec<Device>) -> Vec<Device>
§fn materialize(self) -> PoissonNllLoss
fn materialize(self) -> PoissonNllLoss
§fn valid(&self) -> PoissonNllLoss
fn valid(&self) -> PoissonNllLoss
§fn train(self) -> PoissonNllLoss
fn train(self) -> PoissonNllLoss
§fn devices(&self) -> Vec<Device>
fn devices(&self) -> Vec<Device>
§fn set_require_grad(self, require_grad: bool) -> Self
fn set_require_grad(self, require_grad: bool) -> Self
§fn set_require_grad_group(self, group: ParamGroup, require_grad: bool) -> Self
fn set_require_grad_group(self, group: ParamGroup, require_grad: bool) -> Self
§fn no_grad(self) -> Self
fn no_grad(self) -> Self
§fn freeze_group(self, group: ParamGroup) -> Self
fn freeze_group(self, group: ParamGroup) -> Self
§fn unfreeze_group(self, group: ParamGroup) -> Self
fn unfreeze_group(self, group: ParamGroup) -> Self
§fn num_params(&self) -> usize
fn num_params(&self) -> usize
§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
§fn quantize_weights_group(
self,
quantizer: &mut Quantizer,
group: ParamGroup,
) -> Self
fn quantize_weights_group( self, quantizer: &mut Quantizer, group: ParamGroup, ) -> Self
§fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
Reparameterizer. Read more§fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
§fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
§fn into_record(self) -> ModuleRecordwhere
Self: Sized,
fn into_record(self) -> ModuleRecordwhere
Self: Sized,
ModuleRecord. Read more§fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
§fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
ModuleRecord to this module, returning the loaded
module. Read more§fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
ModuleRecord to this module, consuming and returning
it. Read more§fn save_file<P>(self, path: P) -> Result<(), RecordError>
fn save_file<P>(self, path: P) -> Result<(), RecordError>
§fn load_file<P>(self, path: P) -> Self
fn load_file<P>(self, path: P) -> Self
§fn try_load_file<P>(self, path: P) -> Result<Self, RecordError>
fn try_load_file<P>(self, path: P) -> Result<Self, RecordError>
§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 UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§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 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§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> Read<Exclusive, BecauseExclusive> 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