def create_ngmix_guess(imsky_shape, n_components): means_guess, covars_guess, weights_guess = generate_random_params(imsky_shape, n_components) guess = convert_to_ngmix(means_guess, covars_guess, weights_guess) return guess
theta_12 = convert_params(*psf_12) image_12 = model(image.shape, *psf_12) print(lnprior(image_2, *psf_2)) print(lnprob(theta_2, image_12, theta_1)) # <codecell> # now mcmc to determine theta_2... ndim = len(theta_2) nwalkers = np.max([2 * ndim, 50]) # pos = np.array([generate_random_params(image_2.shape, len(psf_2[0]))[1] # for i in range(nwalkers)]) pos0 = np.array([convert_params(*generate_random_params(image_2.shape, len(psf_2[0]))) for i in range(nwalkers)]) # pos0 = np.array([theta_2 * np.random.uniform(0.95, 1.05, len(theta_2)) # for i in range(nwalkers)]) sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, args=(image_12, theta_1)) pos, prob, state = sampler.run_mcmc(pos0, 200) # <codecell> burnin = 0 samples = sampler.flatchain[burnin * nwalkers :] lnprobs = sampler.flatlnprobability[burnin * nwalkers :] # theta_quantiles = np.array(map(lambda v: (v[1], v[2]-v[1], v[1]-v[0]), # zip(*np.percentile(samples, [16, 50, 84], # axis=0)))).T # theta_2_fit = theta_quantiles[0] theta_2_fit = samples[np.argmax(lnprobs)]