ParametricDistributionScore#
- class bayesflow.scores.ParametricDistributionScore(**kwargs)[source]#
Bases:
ScoringRule
\(S(\hat p_\phi, \theta; k) = -\log(\hat p_\phi(\theta))\)
Base class for scoring a predicted parametric probability distribution with the log-score of the probability of the realized value.
- score(estimates: dict[str, Tensor], targets: Tensor, weights: Tensor = None) Tensor [source]#
Computes the log-score for a predicted parametric probability distribution given realized targets.
\(S(\hat p_\phi, \theta; k) = -\log(\hat p_\phi(\theta))\)
- NOT_TRANSFORMING_LIKE_VECTOR_WARNING = ()#
This variable contains names of prediction heads that should lead to a warning when the adapter is applied in inverse direction to them.
Prediction heads can output estimates in spaces other than the target distribution space. To such estimates the adapter cannot be straightforwardly applied in inverse direction, because the adapter is built to map vectors from the inference variable space. When subclassing
ScoringRule
, add the names of such heads to the following list to warn users about difficulties with a type of estimate whenever the adapter is applied to them in inverse direction.
- 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
links
for 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.