fixed_delta = mod.particles[-1, :, ind].mean() mod._particles[-1][:, ind] = fixed_delta mod._params[ind].prior = fixed_delta mod._log_likes[-1], temp_posts = mod._calc_log_likes(mod._particles[-1]) mod._weights[-1][:] = mod._log_likes[-1][:] + \ mod.calc_log_prior(mod._particles[-1]) # run for more iterations to map posterior mod(1000, burnin=False) # joint plot pl.figure(1) pl.clf() ax = joint_plot(mod.particles[burnin:, :, :-1], mod.weights[burnin:], burnin=burnin, names=mod.param_display_names[:-1], rot=45, sep=.02) pl.show() # ppd plot pl.figure(2) violin_plot([d.ravel() for d in mod.posts[burnin:].T], positions=xData) pl.plot(xData, yData, 'xr', markersize=10) pl.show() # show best fit burnin = 400 print("Best fitting params:") best_ind = mod.weights[burnin:].argmax() indiv = [
proposal_gen=DE(gamma_best=None, rand_base=True), migration_prob=0.0, initial_zeros_ok=False, use_priors=True, save_posts=False, ) abc_rand(burnin) abc_rand.set_proposal_gen(DE(gamma_best=0.0, rand_base=True)) abc_rand(iterations) # joint plot pl.figure(1) pl.clf() ax = joint_plot( abc_true.particles, abc_true.weights, burnin=burnin, names=abc_true.param_display_names, rot=45, sep=0.02 ) pl.show() pl.figure(2) pl.clf() b = pl.hist(abc.particles[(burnin + 100) :, :, 0].flat, 50, alpha=0.3, normed=True) b = pl.hist(abc_true.particles[(burnin + 100) :, :, 0].flat, 50, alpha=0.3, normed=True) b = pl.hist(abc_rand.particles[(burnin + 100) :, :, 0].flat, 50, alpha=0.3, normed=True) pl.legend(["pda", "true", "rand"]) pl.show() pl.figure(3) pl.clf() b = pl.hist(abc.particles[(burnin + 100) :, :, 1].flat, 50, alpha=0.3, normed=True) b = pl.hist(abc_true.particles[(burnin + 100) :, :, 1].flat, 50, alpha=0.3, normed=True)
group_size=25, proposal_gen=DE(gamma_best=None, rand_base=True), migration_prob=0.0, initial_zeros_ok=False, use_priors=True, save_posts=False) abc_rand(burnin) abc_rand.set_proposal_gen(DE(gamma_best=0.0, rand_base=True)) abc_rand(iterations) # joint plot pl.figure(1) pl.clf() ax = joint_plot(abc_true.particles, abc_true.weights, burnin=burnin, names=abc_true.param_display_names, rot=45, sep=.02) pl.show() pl.figure(2) pl.clf() b = pl.hist(abc.particles[(burnin + 100):, :, 0].flat, 50, alpha=.3, normed=True) b = pl.hist(abc_true.particles[(burnin + 100):, :, 0].flat, 50, alpha=.3, normed=True) b = pl.hist(abc_rand.particles[(burnin + 100):, :, 0].flat,
abc(burnin) # fix the delta error term based on the mean ind = abc.param_names.index('delta') abc.fix_delta(ind, abc.particles[-1,:,ind].mean(), proposal_gen=DE_LOCAL(), recalc_weights=True) # run for more iterations to map prior abc(100) # joint plot pl.figure(1) pl.clf() ax = joint_plot(abc.particles[:,:,:-1],abc.weights, burnin=burnin, names=abc.param_display_names[:-1], rot=45,sep=.02) pl.show() # ppd plot pl.figure(2) violin_plot([d.ravel() for d in abc.posts[burnin:].T], positions=xData) pl.plot(xData,yData,'xr',markersize=10) pl.show() # show best fit print "Best fitting params:" best_ind = abc.weights[burnin:].argmax() indiv = [abc.particles[burnin:,:,i].ravel()[best_ind] for i in range(abc.particles.shape[-1])] for p,v in zip(abc.param_names,indiv):