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

Implementation of TSNPE #754

Merged
merged 7 commits into from
Nov 2, 2022
Merged

Implementation of TSNPE #754

merged 7 commits into from
Nov 2, 2022

Conversation

michaeldeistler
Copy link
Contributor

@michaeldeistler michaeldeistler commented Oct 24, 2022

Contributions of this PR

  • Implement truncation for SNPE
  • Coverage diagnostic
  • Tutorial on all implemented methods in the toolbox
  • Documetion
  • Minor fixup to one of the FAQ
  • Tests for picklability

Changes to the code-base

Renamed rejection_sample_posterior_within_prior to accept_reject_sample since it is more general than to sample the posterior within the prior.

API

from sbi.inference import SNPE
from sbi.utils import get_density_thresholder, RestrictedPrior

inference = SNPE()
_ = inference.append_simulations(theta, x).train()
posterior = inference.build_posterior()

accept_reject_fn = get_density_thresholder(posterior, quantile=1e-4)
proposal = RestrictedPrior(prior, accept_reject_fn, sample_with="rejection")
from sbi.analysis import run_sbc
ranks, dap_samples = run_sbc(theta, x, reduce_fns=posterior.log_prob)

@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2022

Codecov Report

Merging #754 (3b8ef31) into main (279809b) will decrease coverage by 0.31%.
The diff coverage is 66.30%.

@@            Coverage Diff             @@
##             main     #754      +/-   ##
==========================================
- Coverage   74.26%   73.95%   -0.32%     
==========================================
  Files          79       77       -2     
  Lines        6034     6073      +39     
==========================================
+ Hits         4481     4491      +10     
- Misses       1553     1582      +29     
Flag Coverage Δ
unittests 73.95% <66.30%> (-0.32%) ⬇️

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

Impacted Files Coverage Δ
sbi/samplers/importance/sir.py 23.07% <ø> (ø)
sbi/utils/restriction_estimator.py 76.79% <56.33%> (-6.33%) ⬇️
sbi/analysis/sbc.py 80.00% <100.00%> (+1.33%) ⬆️
sbi/inference/posteriors/direct_posterior.py 98.24% <100.00%> (+0.03%) ⬆️
sbi/samplers/rejection/rejection.py 90.24% <100.00%> (+0.24%) ⬆️
sbi/utils/__init__.py 100.00% <100.00%> (ø)
sbi/neural_nets/embedding_nets.py 60.41% <0.00%> (-39.59%) ⬇️
sbi/inference/snpe/snpe_base.py 88.81% <0.00%> (ø)
sbi/__init__.py
sbi/inference/posteriors/mcmc_posterior.py 84.83% <0.00%> (+2.80%) ⬆️

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

@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 a lot.

I added a couple of comments and questions. I'm wondering about the naming, e.g., replacing threshold by truncate because threshold used as a verb could be a bit unintuitive.

sbi/analysis/sbc.py Show resolved Hide resolved
sbi/samplers/rejection/rejection.py Outdated Show resolved Hide resolved
sbi/samplers/rejection/rejection.py Show resolved Hide resolved
sbi/samplers/rejection/rejection.py Outdated Show resolved Hide resolved
sbi/utils/restriction_estimator.py Outdated Show resolved Hide resolved
sbi/utils/restriction_estimator.py Outdated Show resolved Hide resolved
sbi/utils/restriction_estimator.py Outdated Show resolved Hide resolved
sbi/utils/restriction_estimator.py Outdated Show resolved Hide resolved
sbi/utils/restriction_estimator.py Show resolved Hide resolved
sbi/utils/restriction_estimator.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!

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.

3 participants