hbmep.metrics

hbmep.metrics#

hbmep.metrics.lp_risk(true, samples, *, weights=None, p=1, axis=-1, root=False, ignore_nan=True)[source]#

Compute posterior expected Lp risk error.

Parameters:
  • true (Array) – True values, broadcast-compatible with samples, with posterior sample axis either present as size 1 or absent.

  • samples (Array) – Posterior samples.

  • p (int | float) – Power of the Lp loss.

  • axis (int) – Posterior sample axis.

  • root (bool) – If False, computes \(\mathbb{E}[|x - y|^p]\), otherwise \(\mathbb{E}[|x - y|^p]^{1/p}\).

  • ignore_nan (bool) – If True, use jnp.nanmean; otherwise use jnp.mean.

Returns:

Posterior expected Lp risk with the posterior sample axis removed.

Return type:

Array

Notes

  • p=1, root=False: L1 risk / MAE

  • p=2, root=False: L2 risk / MSE

  • p=2, root=True: RMSE

hbmep.metrics.crps_unbiased(true, samples, *, axis=-1, batch_size=256)[source]#

Unbiased Monte Carlo estimator of CRPS.

Parameters:
  • true (Array) – True values, broadcast-compatible with samples, with posterior sample axis either present as size 1 or absent.

  • samples (Array) – Posterior samples.

  • axis (int) – Posterior sample axis.

  • batch_size (int) – Number of non-posterior elements processed per batch. Larger values use more memory.

Returns:

CRPS with posterior sample axis removed.

Return type:

Array

Notes

  • Computes \(\mathbb{E}[|X - y|] - \frac{1}{2}\mathbb{E}[|X - X'|]\) using the unbiased finite-sample estimator.