Skip to content

Keep prior optional and remove unnecessary copies of theas from ImproperPrior. #1635

Closed

Description

@manuelgloeckler

Problem

The refactored .build_posterior method now effectively requires a prior.
If none is provided, _resolve_prior will raise an error (unless overridden).

However, a prior is only truly required in specific cases — e.g., sequential methods (nle, nre).
It might be preferable to raise an error only when a prior is actually needed, rather than unconditionally.
That said, implementing this conditional behavior might be more work than simply overriding the method in cases where the prior isn’t used.

At present, most methods that don’t need a prior bypass this requirement by using an ImproperEmpirical prior:

```python
theta_prior = self.get_simulations()[0].to(self._device)
self._prior = ImproperEmpirical(
    theta_prior, ones(theta_prior.shape[0], device=self._device)
)
```

This workaround is somewhat inefficient — it stores another copy of theta inside the prior and an extra weight tensor, even though neither is truly needed.

Solution

The ImproperEmpirical prior avoids the error but is never meaningfully used. The only cases I’m aware of are:

  • Sequential methods: calls to prior.log_prob, which always return zeros.
  • Support checks: redundant here, since it already has “real” support.
  • mcmc_transform: used for z-scoring, but this only needs mean and standard deviation.

In most cases, we could replace ImproperEmpirical with a much simpler placeholder class.
Alternatively, we could skip any auxiliary logic that requires the prior when it’s None (e.g., skip rejection sampling if there’s no bounded support).

Activity

  1. self-assigned this
    on Nov 14, 2025
  2. added
    inference
    on Aug 11, 2026
  3. janfb commented on Aug 11, 2026

    @janfb
    Contributor

    Both halves of this are done. PR #1803 made the prior check conditional, so a
    missing prior no longer raises. PRs #1700 and #1822 removed the copies from
    ImproperEmpirical. Closing as done.

  4. added a commit that references this issue on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

inference

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions