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.
andwould involve implementing a new case within these methods that correctly initializes an ImportanceSamplingPosterior instance when sample_with=="importance" is specified.
Checklist
[ ] Update the build_posterior method in SNLE and SNRE to include a case for sample_with=="importance".
[ ] Ensure that the new case correctly initializes and returns an ImportanceSamplingPosterior instance.
[ ] Add tests to verify that importance sampling works as expected with SNLE and SNRE, ensuring no regressions in functionality.
We welcome contributions from the community to implement this fix and further strengthen the SBI library.
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 thebuild_posterior
method with the parametersample_with="importance"
, aNotImplementedError
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 handlesample_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 thebuild_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-L381andwould involve implementing a new case within these methods that correctly initializes an
ImportanceSamplingPosterior
instance whensample_with=="importance"
is specified.Checklist
build_posterior
method in SNLE and SNRE to include a case forsample_with=="importance"
.ImportanceSamplingPosterior
instance.We welcome contributions from the community to implement this fix and further strengthen the SBI library.