Skip to content

Commit 7ef2de4

Browse files
authored
make sure weights always sum up to 1, fix #4369 (#4370)
* make sure weights always sum up to 1, fix #4369 * always normalize self.weights in update_weights_beta * rephrase
1 parent 84c88c2 commit 7ef2de4

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pymc3/smc/smc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def update_weights_beta(self):
177177
self.log_marginal_likelihood += logsumexp(log_weights_un) - np.log(self.draws)
178178
self.beta = new_beta
179179
self.weights = np.exp(log_weights)
180+
# We normalize again to correct for small numerical errors that might build up
181+
self.weights /= self.weights.sum()
180182

181183
def resample(self):
182184
"""Resample particles based on importance weights."""

0 commit comments

Comments
 (0)