Skip to content
Snippets Groups Projects
Commit fcceee09 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Remove max iterations: keep advancing until converged

parent 3e1f51dc
No related branches found
No related tags found
1 merge request!750Improve ptemcee
......@@ -41,14 +41,13 @@ class Ptemcee(MCMCSampler):
ntemps=20, nwalkers=200, Tmax=None, betas=None,
a=2.0, loglargs=[], logpargs=[], loglkwargs={},
logpkwargs={}, adaptation_lag=10000, adaptation_time=100, random=None,
iterations=1000, thin=1, storechain=True, adapt=False,
swap_ratios=False)
adapt=False, swap_ratios=False)
def __init__(self, likelihood, priors, outdir='outdir', label='label',
use_ratio=False, check_point_plot=True, skip_import_verification=False,
resume=True, nsamples=5000, burn_in_nact=50, thin_by_nact=1,
autocorr_c=5, safety=1, frac_threshold=0.01,
autocorr_tol=50, min_tau=1, check_point_deltaT=600,
autocorr_tol=50, min_tau=1, check_point_deltaT=600,
threads=1, exit_code=77, plot=False, store_walkers=False,
**kwargs):
super(Ptemcee, self).__init__(
......@@ -80,7 +79,7 @@ class Ptemcee(MCMCSampler):
@property
def sampler_function_kwargs(self):
keys = ['iterations', 'thin', 'storechain', 'adapt', 'swap_ratios']
keys = ['adapt', 'swap_ratios']
return {key: self.kwargs[key] for key in keys}
@property
......@@ -159,8 +158,9 @@ class Ptemcee(MCMCSampler):
t0 = datetime.datetime.now()
logger.info("Starting to sample")
for (pos0, lnprob, lnlike) in sampler.sample(
pos0, **self.sampler_function_kwargs):
while True:
for (pos0, _, _) in sampler.sample(pos0, **self.sampler_function_kwargs):
pass
# Calculate time per iteration
self.time_per_check.append((datetime.datetime.now() - t0).total_seconds())
......@@ -247,14 +247,6 @@ class Ptemcee(MCMCSampler):
if last_checkpoint_s > self.check_point_deltaT:
self.write_current_state(plot=self.check_point_plot)
# Check if we reached the end without converging
if sampler.time == self.sampler_function_kwargs["iterations"]:
raise ValueError(
"Failed to reach convergence by iterations={}".format(
self.sampler_function_kwargs["iterations"]
)
)
# Run a final checkpoint to update the plots and samples
self.write_current_state(plot=self.check_point_plot)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment