PoissonD2Score#
- class ibl_bwb_eval.metrics.PoissonD2Score(num_outputs=None, degenerate_value=None, eps=1e-09, validate_finite=True, **kwargs)[source]#
Bases:
torchmetrics.metric.MetricMinimal implementation of Cohen pseudo-R^2 score for Poisson NLL loss.
Supports 1D tensors (single output) and 2D tensors of shape (T, N) (multiple outputs). Assumes log-rates for the predictions.
For 2D inputs, per-output R^2 scores are computed and the mean is returned. Outputs with zero total counts are excluded from the mean; if all outputs are degenerate the degenerate_value is returned.
The number of outputs is inferred automatically from the last dimension of the first call to
update(), or can be provided explicitly vianum_outputs.- Parameters:
num_outputs (
Optional[int]) – Number of outputs. If provided, states are pre-allocated eagerly; otherwise the size is inferred from the last dim of the firstupdate()call.degenerate_value (
Optional[Tensor]) – The value to return when the metric is degenerate.eps (
float) – The epsilon value to use for numerical stability.validate_finite (
bool) – Whether to checkpredsfor NaN/inf on everyupdate(). Disable only when the caller already trustspredsis finite (e.g. scoring predictions written by a validated pipeline).
The pseudo-R2 score is computed as:
\[1 - \frac{N_{pred} - N_{saturated}}{N_{null} - N_{saturated}}\]where \(N_{pred}\) is the predicted Poisson NLL loss, \(N_{saturated}\) is the saturated loss, and \(N_{null}\) is the null (mean-rate) loss.