def contour(chaindir,cosmo,data,compute_param_function) : C=ChainIterator(chaindir,cosmo,'phy',data) z=numpy.arange(0,3,0.01) # find best model min_chi2 = numpy.min(C.chain.chain[:,1]) model_best_index = numpy.argmin(C.chain.chain[:,1]) print "minimum chi2 = ", min_chi2 T=C.theory(model_best_index) # compute param for this model param_best=numpy.zeros(z.shape) for i in range(z.shape[0]) : param_best[i]=compute_param_function(T,z[i]) # allocate param for +- 1 sigma param_1sigma_plus=param_best.copy() param_1sigma_minus=param_best.copy() # selection of models within 1sig model_1sig_indices=numpy.where(C.chain.chain[:,1]<=min_chi2+1)[0] print "number of models at 1 sig = ",model_1sig_indices.shape[0] # if too many, look only at those close to 1 sigma (this is for LCDM, there are too many) chi2_floor=min_chi2 while (model_1sig_indices.shape[0]>3000) : chi2_floor+=0.01 model_1sig_indices=numpy.where((C.chain.chain[:,1]<=min_chi2+1)&(C.chain.chain[:,1]>=chi2_floor))[0] print "number of selected models for the 1sig contour plot = ",model_1sig_indices.shape[0] # loop on models to find max excursion count=0 for index in model_1sig_indices : count+=1 T=C.theory(index) for i in range(z.shape[0]) : parami=compute_param_function(T,z[i]) param_1sigma_minus[i]=min(param_1sigma_minus[i],parami) param_1sigma_plus[i]=max(param_1sigma_plus[i],parami) if count%100==0 : print "done %d/%d"%(count,model_1sig_indices.shape[0]) # return -1sig,best,1sig return z,param_1sigma_minus,param_best,param_1sigma_plus
def contour(chaindir, cosmo, data, compute_param_function): C = ChainIterator(chaindir, cosmo, 'phy', data) z = numpy.arange(0, 3, 0.01) # find best model min_chi2 = numpy.min(C.chain.chain[:, 1]) model_best_index = numpy.argmin(C.chain.chain[:, 1]) print "minimum chi2 = ", min_chi2 T = C.theory(model_best_index) # compute param for this model param_best = numpy.zeros(z.shape) for i in range(z.shape[0]): param_best[i] = compute_param_function(T, z[i]) # allocate param for +- 1 sigma param_1sigma_plus = param_best.copy() param_1sigma_minus = param_best.copy() # selection of models within 1sig model_1sig_indices = numpy.where(C.chain.chain[:, 1] <= min_chi2 + 1)[0] print "number of models at 1 sig = ", model_1sig_indices.shape[0] # if too many, look only at those close to 1 sigma (this is for LCDM, there are too many) chi2_floor = min_chi2 while (model_1sig_indices.shape[0] > 3000): chi2_floor += 0.01 model_1sig_indices = numpy.where((C.chain.chain[:, 1] <= min_chi2 + 1) & (C.chain.chain[:, 1] >= chi2_floor))[0] print "number of selected models for the 1sig contour plot = ", model_1sig_indices.shape[ 0] # loop on models to find max excursion count = 0 for index in model_1sig_indices: count += 1 T = C.theory(index) for i in range(z.shape[0]): parami = compute_param_function(T, z[i]) param_1sigma_minus[i] = min(param_1sigma_minus[i], parami) param_1sigma_plus[i] = max(param_1sigma_plus[i], parami) if count % 100 == 0: print "done %d/%d" % (count, model_1sig_indices.shape[0]) # return -1sig,best,1sig return z, param_1sigma_minus, param_best, param_1sigma_plus
if 'True' in Plot_1D: a = 0 for datasets in datasetl: b = 0 for params in params_1D: b += 1 pylab.subplot(1, len(params_1D), b) C = cosmochain(dire + model_1D + '_' + datasets, 'auto') C = ChainIterator('chains_140411_155701', 'LCDM', 'phy', 'BBAO+CMBP') grlist = [] wlist = [] for i in range(0, C.N, 1000): T = C.theory(i) grlist.append(T.growth(10.0)) wlist.append(C.weight(i)) grlist = array(grlist) wlist = array(wlist) mn = (grlist * wlist).sum() / wlist.sum() er = sqrt((grlist**2 * wlist).sum() / wlist.sum() - mn**2) print("growth z=10/z=0 = ", mn, "+/-", er) a += 1 xx, yy = C.GetHisto(params, NormPeak=True, nbins=NBins_1D) pylab.plot(xx, yy, colour(a), label=cosmodata(datasets)) if 'True' in xrange: xmin = "xmin_" + str(b)
b=0 for params in params_1D: b+=1 pylab.subplot(1,len(params_1D),b) #fname=self.get_filename(dire,model,extra,dataset) C=cosmochain(dire+ model_1D+'_'+datasets,'auto') if(True): #Compute functions= ratio of Fig 2 at z=0.57/0 dire2 = 'chains/DR12/' D=ChainIterator(dire2, 'LCDM','phy', 'CombBAOzb3') grlist=[] wlist=[] for i in range(0,D.N,1000): T=D.theory(i) #grlist.append(T.Da_z(0.57)/T.Hinv_z(0)/(1.0*N.log(1.57))) #grlist.append(T.DaOverrd(0.51)) grlist.append(T.HIOverrd(0.61)) wlist.append(D.weight(i)) grlist=array(grlist) wlist=array(wlist) mn=(grlist*wlist).sum()/wlist.sum() er=sqrt((grlist**2*wlist).sum()/wlist.sum()-mn**2) #print "H(0.0)/(1.0) \over c*ln(1.57)/D_m(0.57) = ",mn,"+/-",er print "z = 0.38 = ",mn,"+/-",er a+=1 xx,yy=C.GetHisto(params,NormPeak=True,nbins=NBins_1D) pylab.plot(xx, yy, colour(a), label=cosmodata(datasets))
if 'True' in Plot_1D: a=0 for datasets in datasetl: b=0 for params in params_1D: b+=1 pylab.subplot(1,len(params_1D),b) C=cosmochain(dire+ model_1D+'_'+datasets,'auto') C=ChainIterator('chains_140411_155701','LCDM','phy','BBAO+CMBP') grlist=[] wlist=[] for i in range(0,C.N,1000): T=C.theory(i) grlist.append(T.growth(10.0)) wlist.append(C.weight(i)) grlist=array(grlist) wlist=array(wlist) mn=(grlist*wlist).sum()/wlist.sum() er=sqrt((grlist**2*wlist).sum()/wlist.sum()-mn**2) print "growth z=10/z=0 = ",mn,"+/-",er a+=1 xx,yy=C.GetHisto(params,NormPeak=True,nbins=NBins_1D) pylab.plot(xx, yy, colour(a), label=cosmodata(datasets))