Skip to content

Commit

Permalink
BUG: ensure infinite ACT estimates are properly handled (#39)
Browse files Browse the repository at this point in the history
* BUG: ensure infinite ACT estimates are properly handled

* REFACTOR: promote debug to warning for poor sampling

* FMT: remove excess empty line

* FMT: remove excess whitespace
  • Loading branch information
ColmTalbot authored Oct 29, 2024
1 parent 0d4b91f commit 8b2f6cf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bilby/core/sampler/dynesty_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def update_user(self, blob, update=True):

# update walks to match target naccept
accept_prob = max(0.5, blob["accept"]) / self.kwargs["walks"]
delay = self.nlive // 10 - 1
delay = max(self.nlive // 10 - 1, 0)
n_target = getattr(_SamplingContainer, "naccept", 60)
self.walks = (self.walks * delay + n_target / accept_prob) / (delay + 1)
self.kwargs["walks"] = min(int(np.ceil(self.walks)), _SamplingContainer.maxmcmc)
Expand Down Expand Up @@ -220,7 +220,7 @@ def build_cache(self):

# Setup
current_u = args.u
check_interval = int(np.ceil(self.act))
check_interval = self.integer_act
target_nact = 50
next_check = check_interval
n_checks = 0
Expand Down Expand Up @@ -300,11 +300,11 @@ def build_cache(self):
)
reject += nfail
blob = {"accept": accept, "reject": reject, "scale": args.scale}
iact = int(np.ceil(self.act))
iact = self.integer_act
thin = self.thin * iact

if accept == 0:
logger.debug(
logger.warning(
"Unable to find a new point using walk: returning a random point"
)
u = common_kwargs["rstate"].uniform(size=len(current_u))
Expand Down Expand Up @@ -359,6 +359,13 @@ def _calculate_act(accept, iteration, samples, most_failures):
return np.inf
return max(calculate_tau(samples), naive_act, most_failures)

@property
def integer_act(self):
if np.isinf(self.act):
return self.act
else:
return int(np.ceil(self.act))


class AcceptanceTrackingRWalk:
"""
Expand Down

0 comments on commit 8b2f6cf

Please sign in to comment.