def lnprob(theta, x, y, yerr, bm, bp): lp = lnprior(theta, bm, bp) if not np.isfinite(lp): return -np.inf try: return lp + binary_lnlike(theta, x, y, yerr) except: print theta raise
# A_1, l2_1, l1_1, s, P_1, A_2, l2_2, l1_2, P_2 # theta = [-2., -2., -1.2, 1., np.log(.66), -2., -2., -1.2, -1.2, np.log(.97)] # better initialisation theta = [-7., -3., -7., 1., np.log(.66), -3.5, -2., -2., -1.6, np.log(.97)] # plot data and prediction pl.clf() pl.errorbar(x_sub, y_sub, yerr=yerr_sub, fmt='k.', capsize=0) xs = np.linspace(min(x_sub), max(x_sub), 100) pl.plot(xs, binary_predict(xs, x_sub, y_sub, yerr_sub, theta)[0], color='.7') pl.savefig('binary_data') # Compute initial likelihood print 'initial lnlike = ', binary_lnlike(theta, x, y, yerr) # bm, bp = minimum and maximum periods bm, bp = np.log(.2), np.log(2) # Sample the posterior probability for m. nwalkers, ndim = 64, len(theta) p0 = [theta+1e-4*np.random.rand(ndim) for i in range(nwalkers)] sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, args = (x, y, yerr, bm, bp)) # print("Burn-in") # p0, lp, state = sampler.run_mcmc(p0, 200) # sampler.reset() nstep = 2000 nruns = 100.