Skip to content

Potentials

posterior_estimator_based_potential(posterior_estimator, prior, x_o, enable_transform=True)

Returns the potential for posterior-based methods.

It also returns a transformation that can be used to transform the potential into unconstrained space.

The potential is the same as the log-probability of the posterior_estimator, but it is set to \(-\inf\) outside of the prior bounds.

Parameters:

Name Type Description Default
posterior_estimator DensityEstimator

The neural network modelling the posterior.

required
prior Distribution

The prior distribution.

required
x_o Optional[Tensor]

The observed data at which to evaluate the posterior.

required
enable_transform bool

Whether to transform parameters to unconstrained space. When False, an identity transform will be returned for theta_transform.

True

Returns:

Type Description
Callable

The potential function and a transformation that maps

TorchTransform

to unconstrained space.

Source code in sbi/inference/potentials/posterior_based_potential.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def posterior_estimator_based_potential(
    posterior_estimator: DensityEstimator,
    prior: Distribution,
    x_o: Optional[Tensor],
    enable_transform: bool = True,
) -> Tuple[Callable, TorchTransform]:
    r"""Returns the potential for posterior-based methods.

    It also returns a transformation that can be used to transform the potential into
    unconstrained space.

    The potential is the same as the log-probability of the `posterior_estimator`, but
    it is set to $-\inf$ outside of the prior bounds.

    Args:
        posterior_estimator: The neural network modelling the posterior.
        prior: The prior distribution.
        x_o: The observed data at which to evaluate the posterior.
        enable_transform: Whether to transform parameters to unconstrained space.
            When False, an identity transform will be returned for `theta_transform`.

    Returns:
        The potential function and a transformation that maps
        to unconstrained space.
    """

    device = str(next(posterior_estimator.parameters()).device)

    potential_fn = PosteriorBasedPotential(
        posterior_estimator, prior, x_o, device=device
    )

    theta_transform = mcmc_transform(
        prior, device=device, enable_transform=enable_transform
    )

    return potential_fn, theta_transform

likelihood_estimator_based_potential(likelihood_estimator, prior, x_o, enable_transform=True)

Returns potential \(\log(p(x_o|\theta)p(\theta))\) for likelihood-based methods.

It also returns a transformation that can be used to transform the potential into unconstrained space.

Parameters:

Name Type Description Default
likelihood_estimator DensityEstimator

The density estimator modelling the likelihood.

required
prior Distribution

The prior distribution.

required
x_o Optional[Tensor]

The observed data at which to evaluate the likelihood.

required
enable_transform bool

Whether to transform parameters to unconstrained space. When False, an identity transform will be returned for theta_transform.

True

Returns:

Type Description
Callable

The potential function \(p(x_o|\theta)p(\theta)\) and a transformation that maps

TorchTransform

to unconstrained space.

Source code in sbi/inference/potentials/likelihood_based_potential.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def likelihood_estimator_based_potential(
    likelihood_estimator: DensityEstimator,
    prior: Distribution,
    x_o: Optional[Tensor],
    enable_transform: bool = True,
) -> Tuple[Callable, TorchTransform]:
    r"""Returns potential $\log(p(x_o|\theta)p(\theta))$ for likelihood-based methods.

    It also returns a transformation that can be used to transform the potential into
    unconstrained space.

    Args:
        likelihood_estimator: The density estimator modelling the likelihood.
        prior: The prior distribution.
        x_o: The observed data at which to evaluate the likelihood.
        enable_transform: Whether to transform parameters to unconstrained space.
             When False, an identity transform will be returned for `theta_transform`.

    Returns:
        The potential function $p(x_o|\theta)p(\theta)$ and a transformation that maps
        to unconstrained space.
    """

    device = str(next(likelihood_estimator.parameters()).device)

    potential_fn = LikelihoodBasedPotential(
        likelihood_estimator, prior, x_o, device=device
    )
    theta_transform = mcmc_transform(
        prior, device=device, enable_transform=enable_transform
    )

    return potential_fn, theta_transform

ratio_estimator_based_potential(ratio_estimator, prior, x_o, enable_transform=True)

Returns the potential for ratio-based methods.

It also returns a transformation that can be used to transform the potential into unconstrained space.

Parameters:

Name Type Description Default
ratio_estimator Module

The neural network modelling likelihood-to-evidence ratio.

required
prior Distribution

The prior distribution.

required
x_o Optional[Tensor]

The observed data at which to evaluate the likelihood-to-evidence ratio.

required
enable_transform bool

Whether to transform parameters to unconstrained space. When False, an identity transform will be returned for theta_transform.

True

Returns:

Type Description
Callable

The potential function and a transformation that maps

TorchTransform

to unconstrained space.

Source code in sbi/inference/potentials/ratio_based_potential.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def ratio_estimator_based_potential(
    ratio_estimator: nn.Module,
    prior: Distribution,
    x_o: Optional[Tensor],
    enable_transform: bool = True,
) -> Tuple[Callable, TorchTransform]:
    r"""Returns the potential for ratio-based methods.

    It also returns a transformation that can be used to transform the potential into
    unconstrained space.

    Args:
        ratio_estimator: The neural network modelling likelihood-to-evidence ratio.
        prior: The prior distribution.
        x_o: The observed data at which to evaluate the likelihood-to-evidence ratio.
        enable_transform: Whether to transform parameters to unconstrained space.
            When False, an identity transform will be returned for `theta_transform`.

    Returns:
        The potential function and a transformation that maps
        to unconstrained space.
    """

    device = str(next(ratio_estimator.parameters()).device)

    potential_fn = RatioBasedPotential(ratio_estimator, prior, x_o, device=device)
    theta_transform = mcmc_transform(
        prior, device=device, enable_transform=enable_transform
    )

    return potential_fn, theta_transform