Hello,
first of all a (late) thank you for your answers.
Looking at the autocorrelation time definitely helped, although the sampling didn't really get any more efficient with the combined DE moves.
There is however another strange thing going on in my program. The stored samples in the chain which are accessed by sampler.get_chains are not equal to the one printed out while actually doing the sampling.
Here is a minimal example of what I'm doing:
def lnlike(theta):
a,b = theta
print(a,b)
lnlike = my_program.initialize(a,b) #I call an external program to compute my log likelihood
return lnlike
def lnprior(theta):
a,b = theta
if a > 1. or b > 1. or a < 0. or b < 0.:
return -np.inf
else:
return 0.0
def lnprob(theta):
lp = lnprior(theta)
if lp < -1e+9 :
return -np.inf
else:
return lp + lnlike(theta)
initial = np.array([0.5,0.5])
ndim = len(initial)
p0 = [np.array(initial) + 1e-2 * np.random.randn(ndim) for i in range(nwalkers)]
def main(p0,nwalkers,Npoints,Ntune,ndim,lnprob):
sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob)
p0, prob, state = sampler.run_mcmc(p0, Ntune)
sampler.reset()
pos, prob, state = sampler.run_mcmc(p0, Npoints, progress=True)
return sampler, pos, prob, state
sampler, pos, prob, state = main(p0,nwalkers,Npoints,Ntune,ndim,lnprob)
samples = sampler.get_chain(flat=True)
a = samples[:,0]
b = samples[:,1]
Now I have the arrays for a and b from calling the samples as well as the values for a and b that get printed out when the lnlike function is called.
The results (for a) look like this:
a from samples / a from print statement:
0.086 / 0.086
0.114 / 0.114
0.088 / 0.093 (?)
0.132 / 0.112 (?)
0.089 / 0.089 (suddenly they are equal again)
Another thing is that the array from samples has the correct length of nwalkers*Npoints, while the lnlike function is only called some less number of times. This is due to the lnprior restrictions on the parameters I guess.
Help with this would be much appreciated, I can't figure out why the values are different.
I need them because I also want to write out additional values from my program which are wrong when the values from a and b differ.
Kind regards,
Marco