-
Notifications
You must be signed in to change notification settings - Fork 207
Description
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).