Skip to content

Commit

Permalink
Fix minor bug in multi-thread evidence integration
Browse files Browse the repository at this point in the history
  • Loading branch information
johnveitch committed Jan 26, 2021
1 parent 66f45d5 commit 22345ce
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cpnest/NestedSampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def reset(self):
self.logLs = [-inf] # Likelihoods sampled
self.log_vols = [0.0] # Volumes enclosed by contours

def increment(self, logL, nlive=None):
def increment(self, logL, nlive=None, nreplace=1):
"""
Increment the state of the evidence integrator
Simply uses rectangle rule for initial estimate
Expand All @@ -52,7 +52,7 @@ def increment(self, logL, nlive=None):
if nlive is None:
nlive = self.nlive
oldZ = self.logZ
logt=-1.0/nlive
logt=-nreplace/nlive
Wt = self.logw + logL + logsubexp(0,logt)
self.logZ = logaddexp(self.logZ,Wt)
# Update information estimate
Expand Down Expand Up @@ -253,12 +253,11 @@ def consume_sample(self):
and updates the evidence logZ
"""
# Increment the state of the evidence integration
logLmin = self.get_worst_n_live_points(len(self.manager.consumer_pipes))
logLtmp = []
for k in self.worst:
self.state.increment(self.params[k].logL)
self.nested_samples.append(self.params[k])
logLtmp.append(self.params[k].logL)
nreplace = len(self.manager.consumer_pipes)
logLmin = self.get_worst_n_live_points(nreplace)
self.state.increment(self.params[nreplace-1].logL, nreplace=nreplace)
self.nested_samples.extend(self.params[:nreplace])
logLtmp=[p.logL for p in self.params[:nreplace]]

# Make sure we are mixing the chains
for i in np.random.permutation(range(len(self.worst))): self.manager.consumer_pipes[self.worst[i]].send(self.params[self.worst[i]])
Expand Down

0 comments on commit 22345ce

Please sign in to comment.