Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.11.1
- Bug fix for log_prob() in SNRE (#275)


# v0.11.0

- Changed the API to do multi-round inference (#273)
Expand Down
17 changes: 9 additions & 8 deletions sbi/inference/posterior.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,24 @@ def _log_prob_snpe(self, theta: Tensor, x: Tensor, norm_posterior: bool) -> Tens
return masked_log_prob - log_factor

def _log_prob_ratio_estimator(self, theta: Tensor, x: Tensor) -> Tensor:
log_ratio = self.net(torch.cat((theta, x)).reshape(1, -1))
log_ratio = self.net(torch.cat((theta, x), dim=1)).reshape(-1)
return log_ratio + self._prior.log_prob(theta)

def _log_prob_snre_a(self, theta: Tensor, x: Tensor) -> Tensor:
warn(
"The log probability from SRE is only correct up to a normalizing constant."
)
return self._log_prob_ratio_estimator(theta, x)

def _log_prob_snre_b(self, theta: Tensor, x: Tensor) -> Tensor:
if self._num_trained_rounds > 1:
warn(
"The log-probability from AALR beyond round 1 is only correct "
"The log-probability from AALR / SNRE-A beyond round 1 is only correct "
"up to a normalizing constant."
)
return self._log_prob_ratio_estimator(theta, x)

def _log_prob_snre_b(self, theta: Tensor, x: Tensor) -> Tensor:
warn(
"The log probability from SNRE_B is only correct up to a normalizing "
"constant."
)
return self._log_prob_ratio_estimator(theta, x)

def _log_prob_snle(self, theta: Tensor, x: Tensor) -> Tensor:
warn(
"The log probability from SNL is only correct up to a normalizing constant."
Expand Down
2 changes: 1 addition & 1 deletion tests/linearGaussian_snpe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def simulator(theta):
posterior, x_o[0], likelihood_shift, likelihood_cov, prior_mean, prior_cov
)

max_dkl = 0.1 if num_dim == 1 else 0.8
max_dkl = 0.1

assert (
dkl < max_dkl
Expand Down
2 changes: 1 addition & 1 deletion tests/linearGaussian_snre_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def simulator(theta):
posterior, x_o[0], likelihood_shift, likelihood_cov, prior_mean, prior_cov
)

max_dkl = 0.1 if num_dim == 1 else 0.8
max_dkl = 0.1

assert (
dkl < max_dkl
Expand Down