From 92aff4bfdb5be56a94b1d6e9d19db401d958c701 Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Wed, 29 Apr 2020 14:48:29 +1000 Subject: [PATCH] Proposed rwalk change - 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 --- bilby/core/sampler/dynesty.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/bilby/core/sampler/dynesty.py b/bilby/core/sampler/dynesty.py index 6dcf9fd13..64e1b1882 100644 --- a/bilby/core/sampler/dynesty.py +++ b/bilby/core/sampler/dynesty.py @@ -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 -- GitLab