Skip to content

Fix ImproperEmpirical: remove Empirical inheritance, constant log_pro… - #1822

Merged
manuelgloeckler merged 1 commit into
sbi-dev:mainfrom
patelshivani2283-lab:fix-improper-empirical
Mar 31, 2026
Merged

manuelgloeckler merged 1 commit into
sbi-dev:mainfrom
patelshivani2283-lab:fix-improper-empirical

Conversation

@patelshivani2283-lab

Copy link
Copy Markdown
Contributor

…b, fix to() #1812

This PR addresses the issues with ImproperEmpirical:

  • Removed inheritance from pyro.distributions.Empirical to avoid storing simulations.
  • Updated class to inherit from torch.distributions.Distribution.
  • Implemented constant log_prob() returning zeros.
  • Disabled sample() as it is not supported.
  • Fixed .to() method to return self and removed invalid super call.

This simplifies the implementation and avoids unnecessary memory usage.

@patelshivani2283-lab

Copy link
Copy Markdown
Contributor Author

@manuelgloeckler could you please review this when you have time? Thanks!

@patelshivani2283-lab

Copy link
Copy Markdown
Contributor Author

Hi @manuelgloeckler, could you please trigger the CI checks for this PR? Thanks!

@codecov

codecov Bot commented Mar 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.39%. Comparing base (937efc2) to head (327ee10).
⚠️ Report is 42 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sbi/utils/sbiutils.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1822      +/-   ##
==========================================
- Coverage   88.54%   86.39%   -2.16%     
==========================================
  Files         137      143       +6     
  Lines       11515    17537    +6022     
==========================================
+ Hits        10196    15151    +4955     
- Misses       1319     2386    +1067     
Flag Coverage Δ
fast 82.79% <66.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sbi/utils/sbiutils.py 85.94% <66.66%> (-1.60%) ⬇️

... and 71 files with indirect coverage changes

@manuelgloeckler manuelgloeckler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Just have one question on the log_prob adjustment.

Comment thread sbi/utils/sbiutils.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, that this error should be adapted i.e. this will now be catched by resolve_prior introduced in adapted in #1793 . Any reason why to avoid raising here?

Effectively any method that would use these log_prob would be wrong.

So if there is not reason for allowing this I would just make this error more generic i.e. Evaluating log_prob from ImproperEmpirical is not supported, please pass a proper prior if log_prob's are required.

I can imagine it might be called by a method that aims to resolve the support i.e. that log_prob is finite. But to avoid this it might be good to impelement torch distirbutions support and return Real (i.e. full support).

@patelshivani2283-lab

Copy link
Copy Markdown
Contributor Author

Hi @manuelgloeckler, thanks for the suggestion!
The constant log_prob (zeros) is intentional to mimic an improper uniform prior when no proper prior is available. This avoids unintended sample rejection during inference.
Raising an error could break parts of the pipeline where log_prob is called internally, even if its value isn’t meaningful here. Returning a constant keeps the behavior neutral.
Happy to adjust if you think raising an error would be safer.

@manuelgloeckler manuelgloeckler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks @patelshivani2283-lab for fixing. I think this reasoning makes sense.

With #1803 the ImproperPrior will anyway be catched at the build_posterior stage and will raise an error (if the prior log_prob is required). Hence lets merge this.

Thanks!

@manuelgloeckler
manuelgloeckler merged commit 1afebab into sbi-dev:main Mar 31, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants