PoissonLoss<T>
Models & Types · AiDotNet.LossFunctions
Implements the Poisson loss function for count data modeling.
Inheritance: LossFunctionBase<T> → PoissonLoss<T>
For Beginners
Poisson loss is designed for modeling count data where the target values represent the number of occurrences of an event in a fixed interval.
Examples include:
- Number of customer arrivals per hour
- Number of network failures per day
- Number of disease cases per region
The loss is derived from the Poisson probability distribution, which is ideal for modeling rare events where we know the average rate of occurrence.
The formula is: predicted - actual * log(predicted) + log(actual!)
Since log(actual!) is constant with respect to predictions, it can be omitted during optimization, so the loss is often implemented as just: predicted - actual * log(predicted)
Poisson loss is appropriate when:
- Your target values are non-negative counts
- The variance of the data is approximately equal to the mean
- You’re modeling the rate or frequency of events
Example
using AiDotNet.LossFunctions;
using AiDotNet.Tensors.LinearAlgebra;
var loss = new PoissonLoss<float>();
var predicted = new Vector<float>(new[] { 0.9f, 0.2f, 0.7f });
var actual = new Vector<float>(new[] { 1.0f, 0.0f, 1.0f });
float value = loss.CalculateLoss(predicted, actual);
Console.WriteLine($"PoissonLoss = {value:F4}");
Constructors
| Constructor | Summary |
|---|---|
PoissonLoss() |
Initializes a new instance of the PoissonLoss class. |
Methods
| Method | Summary |
|---|---|
T CalculateLoss(Vector<T> predicted, Vector<T> actual) |
Calculates the Poisson loss between predicted and actual values. |
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target) |
|
ValueTuple<T, Tensor<T>> CalculateLossAndGradientGpu(Tensor<T> predicted, Tensor<T> actual) |
Calculates both Poisson loss and gradient on GPU in a single efficient pass. |