Skip to content

Instantly share code, notes, and snippets.

@Gabriel-p
Last active September 7, 2019 13:09
Show Gist options
  • Save Gabriel-p/df4336ac320a7690c7d15fa72ae0658a to your computer and use it in GitHub Desktop.
Save Gabriel-p/df4336ac320a7690c7d15fa72ae0658a to your computer and use it in GitHub Desktop.
resume ptemcee sampler
# Define the sampler
ptsampler = sampler.Sampler()
available_time = # some number of hours (seconds)
pos0 = # some initial random positions
# Timing params
elapsed, start_t = 0, t.time()
# Fixed number of steps
steps = 50
while True:
# Run sampler for 'steps' iterations
for (pos, lnprob, lnlike) in ptsampler.sample(
pos0, iterations=steps, adapt=True):
pass
# Update position
pos0 = ptsampler._p0
# Update also the betas?
# Catch and remove nans and infs (this shouldn't happen)
if np.any(np.isinf(pos0)):
print(runs, "infs")
pos0[np.isinf(pos0)] = 0.
if np.any(np.isnan(pos0)):
print(runs, "nans")
pos0[np.isnan(pos0)] = 0.
elapsed += t.time() - start_t
if elapsed_time > available_time:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment