credit.losses.kcrps#
Classes#
Adapted from Nvidia Modulus. |
Module Contents#
- class credit.losses.kcrps.KCRPSLoss(reduction, biased: bool = False)#
Bases:
torch.nn.ModuleAdapted from Nvidia Modulus.
Estimate the CRPS from a finite ensemble
Computes the local Continuous Ranked Probability Score (CRPS) by using the kernel version of CRPS. The cost is O(m log m).
Creates a map of CRPS and does not accumulate over lat/lon regions. Approximates:
\[CRPS(X, y) = E[X - y] - 0.5 E[X-X']\]with
\[sum_i=1^m |X_i - y| / m - 1/(2m^2) sum_i,j=1^m |x_i - x_j|\]- Parameters:
pred (Tensor) – Tensor containing the ensemble predictions. The ensemble dimension is assumed to be the leading dimension
obs (Union[Tensor, np.ndarray]) – Tensor or array containing an observation over which the CRPS is computed with respect to.
biased (bool) –
When False, uses the unbiased estimators described in (Zamo and Naveau, 2018):
E|X-y|/m - 1/(2m(m-1)) sum_(i,j=1)|x_i - x_j| Unlike ``crps`` this is fair for finite ensembles. Non-fair ``crps`` favors less dispersive ensembles since it is biased high by E|X- X'|/ m where m is the ensemble size.
- biased = False#
- batched_forward#
- forward(target, pred)#
- single_sample_forward(target, pred)#
Forward pass for KCRPS loss for a single sample.
- Parameters:
target (torch.Tensor) – Target tensor.
pred (torch.Tensor) – Predicted tensor.
- Returns:
CRPS loss values at each lat/lon
- Return type:
torch.Tensor
- _kernel_crps_implementation(pred: torch.Tensor, obs: torch.Tensor, biased: bool) torch.Tensor#
An O(m log m) implementation of the kernel CRPS formulas