Hi all,
I was wondering whether it is possible to save intermediate values of my trace while sampling. I’m asking because I am planning to do a run which is going to last for more than a day, where samples take several seconds to compute (it’s quite a complicated function for which I don’t have gradients (yet), so right now I’m using Metropolis sampling). I’d like to check some of the intermediate results to see what is happening.
Below is the code that I tried to run to achieve what I want:
with pm.Model() as model:
BoundedNormal = pm.Bound(pm.Normal, lower=0.0)
params = BoundedNormal('parameters',mu=0.5,sd=0.2,shape=(10,))
likelihood_num = pm.Normal('y_num', mu=J_mcmc_num(params), sd = log10_std_num, observed = log10_measured_num)
likelihood_weight = pm.Normal('y_weight', mu=J_mcmc_weight(params), sd = log10_std_weight, observed = log10_measured_weight)
step = pm.Metropolis()
#save some intermediate traces
for i1 in range(5):
if i1 == 0:
trace = pm.sample(1000,tune=1000,step=step,chains=2,cores=2,start=None,trace=None,discard_tuned_samples=False)
else:
trace = pm.sample(1000,tune=0,step=step,chains=2,cores=2,trace=trace)
with open(os.path.join(outDir,traceFile), 'wb') as buff:
pickle.dump({'model': model, 'trace': trace}, buff)
As you can see in this traceplot however, at 2000 samples the step doesn’t seem to be tuned anymore:
I don’t think I am able to use the live_plot argument in pm.sample since I am running my script on a cluster.
Any help would be much appreciated!