scoring_rules#

A collection of scoring rules for Bayes risk minimization with ScoringRuleNetwork.

Examples#

>>> # A network to estimate both point estimates and parameters of a multivariate normal distribution.
>>> from bayesflow.scoring_rules import MeanScore, QuantileScore, MvNormalScore
>>> import bayesflow as bf
>>> inference_network = bf.networks.ScoringRuleNetwork(
...     mean=MeanScore(),
...     quantiles=QuantileScore(),
...     mvn=MvNormalScore(),
... )
>>> # A network to estimate posterior model probabilities with multiple categorical scoring rules.
>>> from bayesflow.scoring_rules import (
...     CrossEntropyScore,
...     BrierScore,
...     PolynomialScore,
...     ExponentialScore,
...     LogisticScore,
... )
>>> comparison_network = bf.networks.ScoringRuleNetwork(
...     cross_entropy=CrossEntropyScore(),
...     brier=BrierScore(),
...     polynomial=PolynomialScore(alpha=2.0),
...     exponential=ExponentialScore(links={"logits": bf.links.Leaky(power=2.0)}),
...     logistic=LogisticScore(),
...     power_logistic=LogisticScore(alpha=1.0),
... )

Inherit from ScoringRule to build your own custom scoring rule.

Classes

BrierScore(**kwargs)

\(S(\hat p_{1\ldots C}, y) = \sum_{c=1}^C (\hat p_c - y_c)^2\)

CategoricalScoringRule([subnets, ...])

Base class for scoring rules over categorical (one-hot encoded) targets.

CrossEntropyScore(**kwargs)

\(S(\hat p_{1\ldots C}, y) = -\sum_{c=1}^C y_c \log \hat p_c\)

ExponentialScore(**kwargs)

\(S(\{f_k\}, m) = \sum_{k \neq m} \exp\!\left(\tfrac{1}{2}(f_k - f_m)\right)\)

LogisticScore([alpha])

\(S(\{f_k\}, m; \alpha) = \sum_{k \neq m} \left(1 + e^{(f_k - f_m)/(\alpha+1)}\right)^\alpha\) for \(\alpha > 0\), and its \(\alpha \to 0\) limit

MeanScore(**kwargs)

\(S(\hat \theta, \theta) = | \hat \theta - \theta |^2\)

MedianScore(**kwargs)

\(S(\hat \theta, \theta) = | \hat \theta - \theta |\)

MixtureScore([components, weight_head, ...])

\(S(\hat p_{\phi_{1\ldots K},w_{1\ldots K}},\theta)=-\sum_{k=1}^{K} \log w_k+\log(\hat p_{\phi_k}(\theta))\)

MvNormalScore([dim, links])

\(S(\hat p_{\mu, \Sigma}, \theta; k) = -\log( \mathcal N (\theta; \mu, \Sigma))\)

NormedDifferenceScore(k, **kwargs)

\(S(\hat \theta, \theta; k) = | \hat \theta - \theta |^k\)

ParametricDistributionScore(**kwargs)

\(S(\hat p_\phi, \theta; k) = -\log(\hat p_\phi(\theta))\)

PolynomialScore([alpha, links])

\(S(\hat p_{1\ldots C}, y; \alpha) = \tfrac{\alpha-1}{\alpha}\sum_c \hat p_c^\alpha - \hat p_y^{\alpha-1}\)

QuantileScore([q, links])

\(S(\hat \theta_i, \theta; \tau_i) = (\hat \theta_i - \theta)(\mathbf{1}_{\hat \theta - \theta > 0} - \tau_i)\)

ScoringRule([subnets, subnets_kwargs, links])

Base class for scoring rules.