Skip to content

Commit 0ff9e9b

Browse files
authored
Fix bug in pseudo_likelihood computation (#4672)
* fix bug in pseudo_likelihood computation * add test * update release notes
1 parent 842a696 commit 0ff9e9b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
### Maintenance
55
+ A deprecation warning from the `semver` package we use for checking backend compatibility was dealt with (see [#4547](https://github.com/pymc-devs/pymc3/pull/4547)).
66
+ `theano.printing.pydotprint` is now hotfixed upon import (see [#4594](https://github.com/pymc-devs/pymc3/pull/4594)).
7+
+ Fix bug in the computation of the log pseudolikelihood values (SMC-ABC). (see [#4672](https://github.com/pymc-devs/pymc3/pull/4672)).
78

89
### New Features
910
+ BART with non-gaussian likelihoods (see [#4675](https://github.com/pymc-devs/pymc3/pull/4675)).

pymc3/smc/smc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ def resample(self):
190190
self.prior_logp = self.prior_logp[resampling_indexes]
191191
self.likelihood_logp = self.likelihood_logp[resampling_indexes]
192192
self.posterior_logp = self.prior_logp + self.likelihood_logp * self.beta
193-
if self.save_sim_data:
193+
if self.kernel == "abc" and self.save_sim_data:
194194
self.sim_data = self.sim_data[resampling_indexes]
195+
if self.kernel == "abc" and self.save_log_pseudolikelihood:
196+
self.log_pseudolikelihood = self.log_pseudolikelihood[resampling_indexes]
195197

196198
def update_proposal(self):
197199
"""Update proposal based on the covariance matrix from tempered posterior."""

pymc3/tests/test_smc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def abs_diff(eps, obs_data, sim_data):
141141
"s", normal_sim, params=(a, b), sum_stat="sort", epsilon=1, observed=self.data
142142
)
143143

144+
with pm.Model() as self.SMABC_log_pseudolikelihood:
145+
a = pm.Normal("a", mu=0, sigma=1)
146+
b = pm.HalfNormal("b", sigma=10)
147+
s = pm.Simulator(
148+
"s", normal_sim, params=(a, b), sum_stat="mean", epsilon=0.2, observed=self.data
149+
)
150+
144151
def test_one_gaussian(self):
145152
with self.SMABC_test:
146153
trace = pm.sample_smc(draws=1000, kernel="ABC")
@@ -210,3 +217,9 @@ def normal_sim(a, b):
210217
)
211218
with pytest.raises(NotImplementedError, match="named models"):
212219
pm.sample_smc(draws=10, kernel="ABC")
220+
221+
def test_log_pseudolikelihood(self):
222+
with self.SMABC_log_pseudolikelihood:
223+
trace = pm.sample_smc(draws=1000, chains=2, kernel="ABC")
224+
assert trace.report.log_pseudolikelihood[0].var() < 1
225+
assert trace.report.log_pseudolikelihood[1].var() < 1

0 commit comments

Comments
 (0)