errorbar(thex, they, yerr=theyerr, fmt='ro') deg = 7 guess = np.polyfit(thex, they, deg) fitbusca = FitPoly.FitPoly(thex, they, thecov, deg) pars_nico = fitbusca.pars cov_nico = fitbusca.covpar err_nico = np.sqrt(np.diagonal(cov_nico)) m, parfit_m, errfit_m, covar_m = fitting.do_minuit(thex, they, thecov, guess) mp, parfit_mp, errfit_mp, covar_mp = fitting.do_mpfit(thex, they, thecov, guess) chain, parfit_mc, errfit_mc, covar_mc = fitting.do_emcee( thex, they, thecov, guess) clf() subplot(211) errorbar(thex, they, yerr=theyerr, fmt='ro') plot(thex, fitting.thepolynomial(thex, parfit_m), label='Minuit', lw=5) plot(thex, fitting.thepolynomial(thex, parfit_mp), label='MPFIT', lw=3) plot(thex, fitting.thepolynomial(thex, parfit_mc), label='MCMC', lw=3, ls='--') plot(thex, fitting.thepolynomial(thex, pars_nico), label='Exact', lw=3, ls=':') errorbar(thex, they, yerr=theyerr, fmt='ro') legend(loc='lower right', frameon=False) subplot(223) errorbar(arange(deg + 1) - 0.1, parfit_m, yerr=errfit_m,
errorbar(thex,they,yerr=theyerr,fmt='ro') deg=7 guess=np.polyfit(thex, they, deg) fitbusca=FitPoly.FitPoly(thex,they,thecov,deg) pars_nico=fitbusca.pars cov_nico=fitbusca.covpar err_nico=np.sqrt(np.diagonal(cov_nico)) m,parfit_m,errfit_m,covar_m=fitting.do_minuit(thex,they,thecov,guess) mp,parfit_mp,errfit_mp,covar_mp=fitting.do_mpfit(thex,they,thecov,guess) chain,parfit_mc,errfit_mc,covar_mc=fitting.do_emcee(thex,they,thecov,guess) clf() subplot(211) errorbar(thex,they,yerr=theyerr,fmt='ro') plot(thex,fitting.thepolynomial(thex,parfit_m),label='Minuit',lw=5) plot(thex,fitting.thepolynomial(thex,parfit_mp),label='MPFIT',lw=3) plot(thex,fitting.thepolynomial(thex,parfit_mc),label='MCMC',lw=3,ls='--') plot(thex,fitting.thepolynomial(thex,pars_nico),label='Exact',lw=3,ls=':') errorbar(thex,they,yerr=theyerr,fmt='ro') legend(loc='lower right',frameon=False) subplot(223) errorbar(arange(deg+1)-0.1,parfit_m,yerr=errfit_m,label='Minuit',fmt='ro') errorbar(arange(deg+1),parfit_mp,yerr=errfit_mp,label='MPFIT',fmt='bo') errorbar(arange(deg+1)+0.1,parfit_mc,yerr=errfit_mc,label='MCMC',fmt='go')
print(chi2init,ndfinit,chi2init/ndfinit,np.sqrt(chi2init/ndfinit)) ####### Fit with initial r=0.1 and initial lensing provided by BICEP2 clBBinit = clBB/2 def functsum(x,pars): bla = pars[0] / 0.1 * np.interp(x, ll, clBBinit) + pars[1] * np.interp(x, ll, clBBl) return bla mask = lcenter < 1000 guess = [2., 1.] fit = fitting.do_emcee(lcenter, BB, dBB, guess, functname = functsum,nbmc=10000,nburn=10000) chains = fit[0] res = fit[1] err = fit[2] cov = fit[3] print(res[0]/err[0]) guess = [2., 1.] factbin = lcenter * (lcenter + 1) / (2 * np.pi) dclsb, dclnb, dclb = th_errors_bins(lcenter, lll, clBBtot/fact, fsky, mukarcmin, fwhmdeg, deltal=deltal) newerrors = dclb*factbin fit2 = fitting.do_emcee(lcenter, BB, newerrors, guess, functname = functsum,nbmc=10000,nburn=10000) chains2 = fit2[0] res2 = fit2[1] err2 = fit2[2]