Skip to content
Snippets Groups Projects

Proposed rwalk change

Merged Gregory Ashton requested to merge proposed-rwalk into master
1 file
+ 8
14
Compare changes
  • Side-by-side
  • Inline
  • 92aff4bf
    Proposed rwalk change · 92aff4bf
    Gregory Ashton authored
    - Don't add the initial point to the chain (prevents bad estimated of
      the act)
    - Break strictly after maxmcmc and return a random draw from the prior
@@ -685,9 +685,9 @@ def sample_rwalk_bilby(args):
reject = 0
nfail = 0
act = np.inf
u_list = [u]
v_list = [prior_transform(u)]
logl_list = [loglikelihood(v_list[-1])]
u_list = []
v_list = []
logl_list = []
max_walk_warning = True
while len(u_list) < nact * act:
@@ -748,7 +748,7 @@ def sample_rwalk_bilby(args):
old_act=old_act, maxmcmc=maxmcmc)
# If we've taken too many likelihood evaluations then break
if accept + reject > maxmcmc and accept > 0:
if accept + reject > maxmcmc:
if max_walk_warning:
warnings.warn(
"Hit maximum number of walks {} with accept={}, reject={}, "
@@ -765,17 +765,11 @@ def sample_rwalk_bilby(args):
u = u_list[idx]
v = v_list[idx]
logl = logl_list[idx]
elif len(u_list) == 1:
logger.warning("Returning the only point in the chain")
u = u_list[-1]
v = v_list[-1]
logl = logl_list[-1]
else:
idx = np.random.randint(int(len(u_list) / 2), len(u_list))
logger.warning("Returning random point in second half of the chain")
u = u_list[idx]
v = v_list[idx]
logl = logl_list[idx]
logger.warning("Unable to find a new point using walk: returning a random point")
u = np.random.uniform(size=n)
v = prior_transform(u)
logl = loglikelihood(v)
blob = {'accept': accept, 'reject': reject, 'fail': nfail, 'scale': scale}
kwargs["old_act"] = act
Loading