sbi-dev / sbi

Simulation-based inference toolkit
https://sbi-dev.github.io/sbi/
Apache License 2.0
573 stars 144 forks source link

SNLE and SNRE do not support Importance Sampling in build_posterior #919

Closed janfb closed 3 months ago

janfb commented 8 months ago

Description:

A limitation in the current implementations of SNLE (Sequential Neural Likelihood Estimation) and SNRE (Sequential Neural Ratio Estimation), is that when attempting to use ImportanceSamplingPosterior through the build_posterior method with the parameter sample_with="importance", a NotImplementedError is raised. This issue prevents users from leveraging importance sampling with SNLE and SNRE, thus limiting the flexibility and utility of these inference methods.

The root cause of this problem is that the build_posterior methods for SNLE and SNRE do not currently include a case to handle sample_with=="importance". As a result, users cannot take advantage of the importance sampling option, which is crucial for scenarios where it may provide more efficient or accurate posterior sampling compared to other methods.

Proposed Fix: To address this issue, we propose adding support for sample_with=="importance" in the build_posterior methods of both SNLE and SNRE. This should be included here: https://github.com/sbi-dev/sbi/blob/9e224dadd7af9a0b431880bad180e500e09c3200/sbi/inference/snle/snle_base.py#L352-L381

andwould involve implementing a new case within these methods that correctly initializes an ImportanceSamplingPosterior instance when sample_with=="importance" is specified.

Checklist

We welcome contributions from the community to implement this fix and further strengthen the SBI library.

famura commented 6 months ago

I plan to have a look at it during the hackathon