Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose enable_transform for all methods. #756

Merged
merged 3 commits into from
Nov 2, 2022
Merged

Conversation

janfb
Copy link
Contributor

@janfb janfb commented Oct 25, 2022

the current API does not allow to not perform sampling in unconstrained space.
In scenarios where one has already transformed parameters to unconstrained space, one workaround is to manually build potential functions and pass them to the posterior object.

But it would be nice to enable this for build_posterior as well, as it offers more flexibility to switch between sampling methods etc.

This PR exposes the enable_transform argument from mcmc_transform at the top level to allow this for all methods.
Note: To keep things parallel for all three methods, this PR reverts #714, which enabled custom transforms for NPE.

@janfb janfb added the enhancement New feature or request label Oct 25, 2022
@janfb janfb self-assigned this Oct 25, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 25, 2022

Codecov Report

Merging #756 (b4acede) into main (a240efb) will increase coverage by 0.19%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #756      +/-   ##
==========================================
+ Coverage   73.87%   74.07%   +0.19%     
==========================================
  Files          78       78              
  Lines        6071     6067       -4     
==========================================
+ Hits         4485     4494       +9     
+ Misses       1586     1573      -13     
Flag Coverage Δ
unittests 74.07% <100.00%> (+0.19%) ⬆️

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

Impacted Files Coverage Δ
sbi/inference/posteriors/direct_posterior.py 98.21% <ø> (ø)
sbi/inference/posteriors/importance_posterior.py 29.03% <ø> (ø)
sbi/inference/posteriors/mcmc_posterior.py 82.02% <ø> (ø)
sbi/inference/posteriors/rejection_posterior.py 82.05% <ø> (ø)
sbi/inference/posteriors/vi_posterior.py 78.83% <ø> (ø)
sbi/inference/snle/snle_base.py 91.58% <ø> (ø)
sbi/inference/snre/snre_base.py 91.45% <ø> (ø)
sbi/samplers/importance/sir.py 23.07% <ø> (ø)
sbi/utils/posterior_ensemble.py 27.72% <ø> (ø)
sbi/utils/potentialutils.py 100.00% <ø> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@michaeldeistler michaeldeistler left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this! I like the idea of exposing enable_transform in likelihood_estimator_based_potential() (etc).

I'm less sure about exposing it also in build_posterior() (instead of just leaving it as a feature of the sampler interface), but I could see pros and cons for this so I'm fine with merging this.

sbi/inference/posteriors/direct_posterior.py Outdated Show resolved Hide resolved
@janfb
Copy link
Contributor Author

janfb commented Oct 31, 2022

I see your point and agree, we can expose it only in the sampler interface. build_posterior will then default to enable_transform=True.
The DirectPosterior still needs the enable_transform arg in the constructor because it builds the potential function internally and it should be possible to turn that off.

I encountered the additional problem that TransformedDistribution would result in an AttributeError in mcmc_transform, which is fixed now as well. So in that case it is possible to still use the convenience of build_posterior.

Copy link
Contributor

@michaeldeistler michaeldeistler left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@janfb janfb merged commit 2ba63b9 into main Nov 2, 2022
@janfb janfb deleted the expose-enable-transform branch November 2, 2022 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants