|
58 | 58 | "from torch import ones, eye\n", |
59 | 59 | "import torch\n", |
60 | 60 | "from torch.distributions import MultivariateNormal\n", |
61 | | - "import matplotlib.pyplot as plt\n", |
62 | 61 | "\n", |
63 | 62 | "from sbi.inference import NPE, ImportanceSamplingPosterior\n", |
64 | 63 | "from sbi.utils import BoxUniform\n", |
65 | | - "from sbi.inference.potentials.base_potential import BasePotential\n", |
66 | 64 | "from sbi.analysis import marginal_plot" |
67 | 65 | ] |
68 | 66 | }, |
|
71 | 69 | "id": "4808d6d3-cb14-4ecd-a0f5-824bf54a5b01", |
72 | 70 | "metadata": {}, |
73 | 71 | "source": [ |
74 | | - "We first define a simulator and a prior which both have functions for sampling (as required for SBI) and log_prob evaluations (as required for importance sampling)." |
| 72 | + "We first define a simulator and a prior which both have a `sample` function (as required for `sbi`) and `log_prob` evaluations (as required for importance sampling)." |
75 | 73 | ] |
76 | 74 | }, |
77 | 75 | { |
|
202 | 200 | "id": "7150cc13-9911-4656-936f-9cafb867eba4", |
203 | 201 | "metadata": {}, |
204 | 202 | "source": [ |
205 | | - "With the SBI toolbox, importance sampling is a one-liner. SBI supports two methods for importance sampling:\n", |
206 | | - "- `\"importance\"`: returns `n_samples` weighted samples (as above) corresponding to `n_samples * sample_efficiency` samples from the posterior. This results in unbiased samples, but the number of effective samples may be small when the SBI estimate is inaccurate.\n", |
207 | | - "- `\"sir\"` (sampling-importance-resampling): performs rejection sampling on a batched basis with batch size `oversampling_factor`. This is a guaranteed way to obtain `N / oversampling_factor` samples, but these may be biased as the weight normalization is not performed across the entire set of samples." |
| 203 | + "With the `sbi` toolbox, importance sampling is a one-liner. `sbi` supports two methods\n", |
| 204 | + "for importance sampling:\n", |
| 205 | + "- `\"importance\"`: returns `n_samples` weighted samples (as above) corresponding to\n", |
| 206 | + " `n_samples * sample_efficiency` samples from the posterior. This results in unbiased\n", |
| 207 | + " samples, but the number of effective samples may be small when the `sbi` estimate is\n", |
| 208 | + " inaccurate.\n", |
| 209 | + "- `\"sir\"` (sampling-importance-resampling): performs rejection sampling on a batched\n", |
| 210 | + " basis with batch size `oversampling_factor`. This is a guaranteed way to obtain `N /\n", |
| 211 | + " oversampling_factor` samples, but these may be biased as the weight normalization is\n", |
| 212 | + " not performed across the entire set of samples." |
208 | 213 | ] |
209 | 214 | }, |
210 | 215 | { |
|
0 commit comments