-
Notifications
You must be signed in to change notification settings - Fork 159
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
SNPE_C won't draw samples from the posterior #1287
Comments
Can you try using truncated proposals? from sbi.inference import NPE
from sbi.utils import RestrictedPrior, get_density_thresholder
inference = NPE(prior)
proposal = prior
for _ in range(num_rounds):
theta = proposal.sample((num_sims,))
x = simulator(theta)
_ = inference.append_simulations(theta, x).train(force_first_round_loss=True)
posterior = inference.build_posterior().set_default_x(x_o)
accept_reject_fn = get_density_thresholder(posterior, quantile=1e-4)
proposal = RestrictedPrior(prior, accept_reject_fn, sample_with="rejection") |
|
To expand on this a bit:
The "issue" lies within The issue in your case actually is your code: simulator = lambda theta: ((1/scale_true)*torch.sin(-t/scale_true) + 0.05*torch.rand_like(theta)).float() Note that in your simulator, the parameters theta are just used here, In the end this leads to the estimator learning "non-sense" because the data you give it is "non-sense". For certain input it then just predicts stuff outside the prior domains, which all gets rejected. |
Closing this issue, in favor of #1292 |
Describe the bug
I have implemented SNPE_C with a uniform prior and a sine simulator with noise. However, it randomly won't sample/sample very slowly from the posterior, even after the network converges.
To Reproduce
1.
Python version: 3.9.13
SBI version: 0.23.1
2. Minimal code example:
Example 1:
Example 2:
Expected behavior
Sampling from the posterior in a few seconds.
The text was updated successfully, but these errors were encountered: