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

Allow for the potential_fn to be a Callable #943

Merged
merged 4 commits into from
Feb 16, 2024
Merged

Conversation

michaeldeistler
Copy link
Contributor

@michaeldeistler michaeldeistler commented Feb 14, 2024

We now only require that the potential_fn takes theta and x_o as inputs.

def potential(theta, x_o):
    return sim.log_prob(theta, x_o) + prior.log_prob(theta)


posterior = MCMCPosterior(
    potential_fn=potential,
    proposal=posterior.set_default_x(x_o),
)
samples = posterior.sample((100,), x=x_o)

The newly added tests take 2.14 seconds in total.

Closes #765

@michaeldeistler michaeldeistler changed the title First working draft of potential_fn being a Callable [WIP] First working draft of potential_fn being a Callable Feb 14, 2024
@michaeldeistler michaeldeistler changed the title [WIP] First working draft of potential_fn being a Callable First working draft of potential_fn being a Callable Feb 15, 2024
@michaeldeistler michaeldeistler changed the title First working draft of potential_fn being a Callable Allow for the potential_fn to be a Callable Feb 15, 2024
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3b1f34e) 75.29% compared to head (db89fc7) 75.94%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #943      +/-   ##
==========================================
+ Coverage   75.29%   75.94%   +0.65%     
==========================================
  Files          80       80              
  Lines        6285     6306      +21     
==========================================
+ Hits         4732     4789      +57     
+ Misses       1553     1517      -36     
Flag Coverage Δ
unittests 75.94% <100.00%> (+0.65%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@janfb janfb left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! Good idea to use a wrapper here.

I added a couple of questions regarding documentation and making sure the passed potential has what we need.

sbi/inference/posteriors/base_posterior.py Outdated Show resolved Hide resolved
sbi/inference/posteriors/vi_posterior.py Show resolved Hide resolved
sbi/inference/potentials/base_potential.py Outdated Show resolved Hide resolved
tests/potential_test.py Show resolved Hide resolved
Copy link
Contributor

@janfb janfb left a comment

Choose a reason for hiding this comment

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

Great! Just one final comment about the typing.

sbi/inference/posteriors/base_posterior.py Show resolved Hide resolved
sbi/inference/posteriors/base_posterior.py Show resolved Hide resolved
Copy link
Contributor

@janfb janfb left a comment

Choose a reason for hiding this comment

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

looks good and ready to go into main. Thanks!

@michaeldeistler michaeldeistler merged commit b7851cc into main Feb 16, 2024
3 checks passed
@michaeldeistler michaeldeistler deleted the potential branch February 16, 2024 13:52
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.

Potentials should not have to inherit from BasePotential
2 participants