BrierScore#
- class bayesflow.networks.inference.scoring.scoring_rules.BrierScore(**kwargs)[source]#
Bases:
PolynomialScore\(S(\hat p_{1\ldots C}, y) = \sum_{c=1}^C (\hat p_c - y_c)^2\)
The (multi-class) Brier score, realised as the
PolynomialScorespecial case with \(\alpha = 2\). It is minimized in expectation by the true posterior model probabilities, i.e. when \(\mathrm{softmax}(\hat y)_m = 1\) for the true model \(m\).Note
For one-hot targets the Brier score is an exact affine map of the \(\alpha = 2\) Tsallis polynomial score, \(S_{\mathrm{Brier}} = 2\,S_{\mathrm{poly}} + 1\). The heavy lifting is therefore inherited from
PolynomialScore;score()only applies this transform so that the reported value is the true Brier score. (The scale and offset are immaterial for Bayes-risk minimization — same minimizer and gradient direction — but keep the metric interpretable.)- TRANSFORMATION_TYPE: dict[str, str] = {}#
Defines nonstandard transformation behaviour for de-standardization.
The standard transformation
x_i = x_i’ * sigma_i + mu_i
is referred to as “location_scale”. Keys not specified here will fallback to that default.
- classmethod from_config(config)#
- get_config()#
- get_head(key: str, output_shape: tuple[int, ...]) Sequential#
For a specified head key and output shape, request corresponding head network.
A head network has the following components that are called sequentially:
subnet: A keras.Layer.
dense: A trainable linear projection with as many units as are required by the next component.
reshape: Changes shape of output of projection to match requirements of next component.
link: Transforms unconstrained values into a constrained space for the final estimator. See
linksfor examples.
This method initializes the components in reverse order to meet all requirements and returns them.
- Parameters:
- keystr
Name of head for which to request a link.
- output_shape: Shape
The necessary shape of estimated values for the given key as returned by
get_head_shapes_from_target_shape().
- Returns:
- headkeras.Sequential
Head network consisting of a learnable projection, a reshape and a link operation to parameterize estimates.
- get_head_shapes_from_target_shape(target_shape: tuple[int, ...]) dict[str, tuple[int, ...]]#
Request a dictionary of names and output shapes of required heads from the score.
- get_link(key: str) Layer#
For a specified key, request a link from network output to estimation target.
If no link was specified for the key (e.g. upon initialization), return a linear activation.
- Parameters:
- keystr
Name of head for which to request a link.
- Returns:
- linkkeras.Layer
Activation function linking network output to estimation target.
- get_subnet(key: str) Layer#
For a specified key, request a subnet to be used for projecting the shared condition embedding before further projection and reshaping to the heads output shape.
If no subnet was specified for the key (e.g. upon initialization), return just an instance of keras.layers.Identity.
- Parameters:
- keystr
Name of head for which to request a subnet.
- Returns:
- linkkeras.Layer
Subnet projecting the shared condition embedding.
- score(estimates: dict[str, Tensor], targets: Tensor, weights: Tensor = None) Tensor[source]#
Computes the (optionally weighted) mean Brier score from logits.
Reuses
PolynomialScore.score()(the \(\alpha = 2\) Tsallis score) and rescales it to the classical Brier score. Becauseweighted_meanis affine-preserving, applying the transform to the aggregated score is equivalent to applying it per sample.- Parameters:
- estimatesdict[str, Tensor]
Must contain
"probs"with shape(..., num_models).- targetsTensor
One-hot encoded target labels of shape
(..., num_models).- weightsTensor, optional
Per-sample weights for a weighted mean.
- Returns:
- Tensor
(Optionally weighted) mean Brier score over the batch.