-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeasurement_vs_theory.py
201 lines (147 loc) · 6.76 KB
/
measurement_vs_theory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import os
import numpy as np
import scipy
from scipy import integrate
import matplotlib.pyplot as plt
import pickle
def load_obj(name):
with open(name + '.pkl', 'rb') as f:
return pickle.load(f)#, encoding='latin1')
def save_obj(name, obj):
with open(name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
f.close()
def covariance_jck(TOTAL_PHI,jk_r,type_cov):
if type_cov=='jackknife':
fact=(jk_r-1.)/(jk_r)
elif type_cov=='bootstrap':
fact=1./(jk_r)
# Covariance estimation
average=np.zeros(TOTAL_PHI.shape[0])
cov_jck=np.zeros((TOTAL_PHI.shape[0],TOTAL_PHI.shape[0]))
err_jck=np.zeros(TOTAL_PHI.shape[0])
for kk in range(jk_r):
average+=TOTAL_PHI[:,kk]
average=average/(jk_r)
# print average
for ii in range(TOTAL_PHI.shape[0]):
for jj in range(ii+1):
for kk in range(jk_r):
cov_jck[jj,ii]+=TOTAL_PHI[ii,kk]*TOTAL_PHI[jj,kk]
cov_jck[jj,ii]=(-average[ii]*average[jj]*jk_r+cov_jck[jj,ii])*fact
cov_jck[ii,jj]=cov_jck[jj,ii]
for ii in range(TOTAL_PHI.shape[0]):
err_jck[ii]=np.sqrt(cov_jck[ii,ii])
# print err_jck
#compute correlation
corr=np.zeros((TOTAL_PHI.shape[0],TOTAL_PHI.shape[0]))
for i in range(TOTAL_PHI.shape[0]):
for j in range(TOTAL_PHI.shape[0]):
corr[i,j]=cov_jck[i,j]/(np.sqrt(cov_jck[i,i]*cov_jck[j,j]))
average=average*fact
return {'cov' : cov_jck,
'err' : err_jck,
'corr':corr,
'mean':average}
f_sky = 0.11542924245198567
x = np.array([21.0,33.6,54.,86., 137.6, 220.16])
#scalecut
sm = x
eebin = "2_3"
eeebin = "3_2_2"
EE = []
EEE = []
for i in range(2):
EE.append( load_obj("./masked_noised_cov/EE_" +eebin+ "_"+ str(i)))
EEE.append(load_obj("./masked_noised_cov/EEE_"+eeebin+"_"+ str(i)))
EE_ = np.concatenate(EE, axis = 0)
EEE_ = np.concatenate(EEE, axis = 0)
EE = {'mean': np.average(EE_, axis = 0),
'err': np.std(EE_, axis = 0)/np.sqrt(200)
}
EEE = {'mean': np.average(EEE_, axis = 0),
'err': np.std(EEE_, axis = 0)/np.sqrt(200)
}
kp20 = load_obj('./fisher/kp2param0_'+eebin)
kp3sc = load_obj('./fisher/kp3param0SC_'+eeebin)/f_sky
kp3gm = load_obj('./fisher/kp3param0GM_'+ eeebin)/f_sky
i,j = np.diag_indices(len(x), 2)
i = i[:-1]
j = j[1:]
plt.errorbar(x[i], x[i]*EE['mean'][i,j], yerr= x[i]*EE['err'][i,j], label = 'simulations')
plt.plot(sm[:-1],sm[:-1]*kp20[i,j], label = 'theory, $\chi^2 =$' + str(np.sum(((EE['mean'][i,j]-kp20[i,j])/EE['err'][i,j])**2)))
plt.legend(loc = 4)
plt.xscale('log')
plt.title("2*nd moment $\\theta_2 = 1.6\\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$\\theta_1 < \kappa_{\\theta_1}\kappa_{\\theta_2}>$")
plt.show()
i,j = np.diag_indices(len(x), 2)
plt.errorbar(x[i], x[i]*EE['mean'][i,j], yerr= x[i]*EE['err'][i,j], label = 'simulations')
plt.plot(sm, sm*kp20[i,j], label = 'theory, $\chi^2 =$' + str(np.sum(((EE['mean'][i,j]-kp20[i,j])/EE['err'][i,j])**2)))
plt.legend(loc = 4)
plt.xscale('log')
plt.title("2*nd moment $\\theta_2 = \\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$\\theta_1 < \kappa_{\\theta_1}\kappa_{\\theta_2}>$")
plt.show()
i,j,k = np.diag_indices(len(x), 3)
i = i[:-2]
j = j[1:-1]
k = k[2:]
plt.plot(sm[:-2],sm[:-2]**2*kp3sc[i,j,k], label = 'SC, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3sc[i,j,k])/EEE['err'][i,j,k])**2)))
plt.plot(sm[:-2],sm[:-2]**2*kp3gm[i,j,k], label = 'GM, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3gm[i,j,k])/EEE['err'][i,j,k])**2)))
plt.errorbar(x[i], x[i]**2*EEE['mean'][i,j,k], yerr= x[i]**2*EEE['err'][i,j,k], label = 'simulations')
plt.xscale('log')
plt.legend(loc = 4)
plt.title("3rd moment $\\theta_3 = 1.6\\theta_2 = 1.6^2\\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$\\theta_1^2 < \kappa_{\\theta_1}\kappa_{\\theta_2}\kappa_{\\theta_3}>$")
plt.show()
plt.plot(x[i] ,(EEE['mean'][i,j,k]-kp3sc[i,j,k])/kp3sc[i,j,k], label = 'SC, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3sc[i,j,k])/EEE['err'][i,j,k])**2)))
plt.plot(x[i] ,(EEE['mean'][i,j,k]-kp3gm[i,j,k])/kp3gm[i,j,k], label = 'GM, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3gm[i,j,k])/EEE['err'][i,j,k])**2)))
plt.xscale('log')
plt.legend(loc = 4)
plt.title("3rd moment $\\theta_3 = 1.6\\theta_2 = 1.6^2\\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$({\\rm measurement-theory})/({\\rm theory})$")
plt.show()
i,j,k = np.diag_indices(len(x), 3)
i = i[:-1]
j = j[:-1]
k = k[1:]
plt.plot(sm[:-1],sm[:-1]**2*kp3sc[i,j,k], label = 'SC, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3sc[i,j,k])/EEE['err'][i,j,k])**2)))
plt.plot(sm[:-1],sm[:-1]**2*kp3gm[i,j,k], label = 'GM, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3gm[i,j,k])/EEE['err'][i,j,k])**2)))
plt.errorbar(x[i], x[i]**2*EEE['mean'][i,j,k], yerr= x[i]**2*EEE['err'][i,j,k], label = 'simulations')
plt.xscale('log')
plt.legend(loc = 4)
plt.title("3rd moment $\\theta_3 = 1.6\\theta_2 = 1.6\\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$\\theta_1^2 < \kappa_{\\theta_1}\kappa_{\\theta_2}\kappa_{\\theta_3}>$")
plt.show()
plt.plot(x[i] ,(EEE['mean'][i,j,k]-kp3sc[i,j,k])/kp3sc[i,j,k], label = 'SC, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3sc[i,j,k])/EEE['err'][i,j,k])**2)))
plt.plot(x[i] ,(EEE['mean'][i,j,k]-kp3gm[i,j,k])/kp3gm[i,j,k], label = 'GM, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3gm[i,j,k])/EEE['err'][i,j,k])**2)))
plt.xscale('log')
plt.legend(loc = 4)
plt.title("3rd moment $\\theta_3 = 1.6\\theta_2 = 1.6\\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$({\\rm measurement-theory})/({\\rm theory})$")
plt.show()
i,j,k = np.diag_indices(len(x), 3)
plt.plot(sm ,sm**2*kp3sc[i,j,k], label = 'SC, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3sc[i,j,k])/EEE['err'][i,j,k])**2)))
plt.plot(sm ,sm**2*kp3gm[i,j,k], label = 'GM, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3gm[i,j,k])/EEE['err'][i,j,k])**2)))
plt.errorbar(x[i], x[i]**2*EEE['mean'][i,j,k], yerr= x[i]**2*EEE['err'][i,j,k], label = 'simulations')
plt.xscale('log')
plt.legend(loc = 4)
plt.title("3rd moment $\\theta_3 = \\theta_2 = \\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$\\theta_1^2 < \kappa_{\\theta_1}\kappa_{\\theta_2}\kappa_{\\theta_3}>$")
plt.show()
plt.plot(sm ,(EEE['mean'][i,j,k]-kp3sc[i,j,k])/kp3sc[i,j,k], label = 'SC, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3sc[i,j,k])/EEE['err'][i,j,k])**2)))
plt.plot(sm ,(EEE['mean'][i,j,k]-kp3gm[i,j,k])/kp3gm[i,j,k], label = 'GM, $\chi^2 =$' + str(np.sum(((EEE['mean'][i,j,k]-kp3gm[i,j,k])/EEE['err'][i,j,k])**2)))
plt.xscale('log')
plt.legend(loc = 4)
plt.title("3rd moment $\\theta_3 = \\theta_2 = \\theta_1$")
plt.xlabel("$\\theta_1$ (arcmin)")
plt.ylabel("$({\\rm measurement-theory})/({\\rm theory})$")
plt.show()