You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enhancementImprovement planned or wanted by the maintainersfeature requestRequested by a user, not yet planned by the maintainershackathonFor our in-person hackathons with maintainers present, not a general up-for-grabs listkarmaKarma issues: potentially annoying but very important issues
More context: At the moment, we only implement multi-round NPE via
SNPE-A with post-hoc correction,
and SNPE-C based on learning the proposal posterior.
SNPE-B enables multi-round NPE using an importance weighted loss. Although the with importance weighs can be unstable, SNPE-B can still be useful for some applications and would be "nice to have".
Hello,
I'm trying to implement SNPE-B with @touronc and @plcrodrigues as suggested in Issue #199.
According to the paper Flexible statistical inference for mechanistic models of neural dynamics, Lueckmann, Gonçalves et al., NeurIPS 2017,
during the training phase, the loss should be weighted by $\frac{p(\theta)}{\tilde{p}(\theta)}$ for $\theta$ sampled from the proposal prior.
But in the sbi code, when we consider multiple rounds (sequential NPE), the method self.get_dataloaders of the class NeuralInference creates shuffled batches of $\theta$'s coming from the prior (first round) or from the prior and from the proposal (next rounds).
In some cases, the prior has heavier tail than the proposal : so for some $\theta$'s coming from the prior, $\tilde{p}(\theta)$ is almost $0$ whereas $p(\theta)$ is strictly positive. Thus the importance weight $\frac{p(\theta)}{\tilde{p}(\theta)}$ is not well defined and throws $inf$ values.
To illustrate this problem, we use the package sbibm with the task gaussian_mixture : in this task, the prior is uniform between $-10$ and $10$, and $\theta$ has $2$ dimensions.
Here is a case where the problem may happen (we represent the second dimension only): if $\theta$ is sampled from the prior between $5$ and $10$, it will have $\tilde{p}(\theta) \approx 0$ and the ratio won't be well defined.
To avoid this problem, we propose the following solution :
thanks to the masks_batch contained in the batches of the train_loader and val_loader, we can know whether each $\theta$ of the batch comes from the prior or not.
So for $\theta$ in the batch coming from the proposal, we compute the importance weight as suggested in the paper, and for $\theta$ coming from the prior, we set the importance weight to $1$.
This method seems more stable as we try on other examples fromsbibm.
As you know, there still remains the potential problem of having $\theta$ samples from the tail of the proposal, in which case the ratio may also be unstable ($\tilde{p}(\theta) \approx 0$) .
In our experiments with gaussian_mixture, we encountered this case : some $\theta$ are on the tail of the proposal
as shown below. However, for the moment, we still have finite values for the ratio.
Question: Do you know if anyone else is working on SNPE-B as well ? Do you think the solution proposed above could be interesting ?
enhancementImprovement planned or wanted by the maintainersfeature requestRequested by a user, not yet planned by the maintainershackathonFor our in-person hackathons with maintainers present, not a general up-for-grabs listkarmaKarma issues: potentially annoying but very important issues
Activity
jan-matthis commentedon Jun 18, 2020
@michaeldeistler Did this get fixed?
michaeldeistler commentedon Jun 18, 2020
No, not fixed yet. SNPE-B raises a
NotImplementedError.[-]SNPE-B bug[/-][+]SNPE-B[/+]Ziaeemehr commentedon Sep 30, 2021
Hi,
Is SNPE-B is available in sbi? I just searched in documentation and found no match.
cheers.
michaeldeistler commentedon Sep 30, 2021
no it's not available yet
[-]SNPE-B[/-][+]Implement SNPE-B[/+]janfb commentedon Feb 27, 2024
More context: At the moment, we only implement multi-round NPE via
SNPE-B enables multi-round NPE using an importance weighted loss. Although the with importance weighs can be unstable, SNPE-B can still be useful for some applications and would be "nice to have".
Link to paper: https://proceedings.neurips.cc/paper/2017/hash/addfa9b7e234254d26e9c7f2af1005cb-Abstract.html
rough outline for a PR:
sbi/tests/linearGaussian_snpe_test.py
Line 44 in 3aeb775
etouron1 commentedon Apr 3, 2024
Hello,$\frac{p(\theta)}{\tilde{p}(\theta)}$ for $\theta$ sampled from the proposal prior.
I'm trying to implement SNPE-B with @touronc and @plcrodrigues as suggested in Issue #199.
According to the paper Flexible statistical inference for mechanistic models of neural dynamics, Lueckmann, Gonçalves et al., NeurIPS 2017,
during the training phase, the loss should be weighted by
But in the$\theta$ 's coming from the prior (first round) or from the prior and from the proposal (next rounds).$\theta$ 's coming from the prior, $\tilde{p}(\theta)$ is almost $0$ whereas $p(\theta)$ is strictly positive. Thus the importance weight $\frac{p(\theta)}{\tilde{p}(\theta)}$ is not well defined and throws $inf$ values.$-10$ and $10$ , and $\theta$ has $2$ dimensions.$\theta$ is sampled from the prior between $5$ and $10$ , it will have $\tilde{p}(\theta) \approx 0$ and the ratio won't be well defined.
sbicode, when we consider multiple rounds (sequential NPE), the methodself.get_dataloadersof the classNeuralInferencecreates shuffled batches ofIn some cases, the prior has heavier tail than the proposal : so for some
To illustrate this problem, we use the package
sbibmwith the taskgaussian_mixture: in this task, the prior is uniform betweenHere is a case where the problem may happen (we represent the second dimension only): if
To avoid this problem, we propose the following solution :$\theta$ of the batch comes from the prior or not.$\theta$ in the batch coming from the proposal, we compute the importance weight as suggested in the paper, and for $\theta$ coming from the prior, we set the importance weight to $1$ .
thanks to the
masks_batchcontained in the batches of thetrain_loaderandval_loader, we can know whether eachSo for
Here is a piece of the code :
This method seems more stable as we try on other examples from
sbibm.As you know, there still remains the potential problem of having$\theta$ samples from the tail of the proposal, in which case the ratio may also be unstable ($\tilde{p}(\theta) \approx 0$ ) .$\theta$ are on the tail of the proposal
In our experiments with
gaussian_mixture, we encountered this case : someas shown below. However, for the moment, we still have finite values for the ratio.
Question: Do you know if anyone else is working on SNPE-B as well ? Do you think the solution proposed above could be interesting ?
janfb commentedon Apr 3, 2024
Thanks a lot for looking into this and adding the detailed report 👍
I am tagging @jan-matthis because he probably encountered similar implementation issues in
delfiback then.See also https://github.com/mackelab/delfi/blob/main/delfi/inference/SNPEB.py
janfb commentedon Jul 22, 2024
@etouron1 would you be up for making a PR implementing SNPE-B? That would be awesome!
Implementing NPE-B (#199) and adapt SNPE tests for testing (S)NPE-B (#…
janfb commentedon Aug 15, 2025
fixed with #1471