1
1
# What should I do when my 'posterior samples are outside the prior support' in SNPE?
2
2
3
- When working with ** multi-round** SNPE, you might have experienced the following
4
- warning:
3
+ When working with ** multi-round** NPE (i.e., SNPE) , you might have experienced the
4
+ following warning:
5
5
6
6
``` python
7
7
Only x% posterior samples are within the prior support. It may take a long time to
8
8
collect the remaining 10000 samples. Consider interrupting (Ctrl- C) and switching to
9
9
' sample_with_mcmc=True' .
10
10
```
11
11
12
- The reason for this issue is described in more detail
13
- [ here] ( https://arxiv.org/abs/2002.03712 ) and
12
+ The reason for this issue is described in more detail
13
+ [ here] ( https://arxiv.org/abs/2210.04815 ) ,
14
+ [ here] ( https://arxiv.org/abs/2002.03712 ) , and
14
15
[ here] ( https://arxiv.org/abs/1905.07488 ) . The following fixes are possible:
15
16
17
+ - use truncated proposals for SNPE (TSNPE)
18
+ ``` python
19
+ from sbi.inference import NPE
20
+ from sbi.utils import RestrictedPrior, get_density_thresholder
21
+
22
+ inference = NPE(prior)
23
+ proposal = prior
24
+ for _ in range (num_rounds):
25
+ theta = proposal.sample((num_sims,))
26
+ x = simulator(theta)
27
+ _ = inference.append_simulations(theta, x).train(force_first_round_loss = True )
28
+ posterior = inference.build_posterior().set_default_x(x_o)
29
+
30
+ accept_reject_fn = get_density_thresholder(posterior, quantile = 1e-4 )
31
+ proposal = RestrictedPrior(prior, accept_reject_fn, sample_with = " rejection" )
32
+ ```
33
+
16
34
- sample with MCMC: ` samples = posterior((num_samples,), x=x_o, sample_with_mcmc=True) ` .
17
35
This approach will make sampling slower, but samples will not "leak".
18
36
19
- - resort to single-round SNPE and (if necessary) increase your simulation budget.
37
+ - resort to single-round NPE and (if necessary) increase your simulation budget.
20
38
21
39
- if your prior is either Gaussian (torch.distributions.MultivariateNormal) or
22
40
Uniform (sbi.utils.BoxUniform), you can avoid leakage by using a mixture density
@@ -25,5 +43,5 @@ interface](https://sbi-dev.github.io/sbi/tutorial/03_flexible_interface/), set
25
43
` density_estimator='mdn' ` . When running inference, there should be a print
26
44
statement "Using SNPE-C with non-atomic loss".
27
45
28
- - use a different algorithm, e.g., SNRE and SNLE . Note, however, that these algorithms
29
- can have different issues and potential pitfalls.
46
+ - use a different algorithm, e.g., Sequential NRE and Sequential NLE . Note, however,
47
+ that these algorithms can have different issues and potential pitfalls.
0 commit comments