-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck3.py
More file actions
64 lines (46 loc) · 1.51 KB
/
Copy pathcheck3.py
File metadata and controls
64 lines (46 loc) · 1.51 KB
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
import numpy
import sys
import os
from scipy.optimize import minimize
p = os.path.realpath(__file__)
sys.path.append(f'{p[:-10]}/../../lib/python')
from chiexp import chisquare
dat = numpy.loadtxt('../freefield-32x12-m0.25-r001.dat.gz')
(ncnfg, T) = dat.shape
xx=numpy.arange(T//2+1)
yy=numpy.mean(dat,axis=0)[0:T//2+1]
dy=numpy.sqrt(numpy.var(dat,axis=0))[0:T//2+1]
f = lambda x, a, m: a*(numpy.exp(-m*x) + numpy.exp(-m*(T-x)))
df = lambda x, a, m: [(numpy.exp(-m*x) + numpy.exp(-m*(T-x))),
a*(-m*numpy.exp(-m*x) + m*numpy.exp(-m*(T-x)))]
x0min = range(T//4)
p0 = [yy[0], 0.2]
res = []
for x0 in x0min:
idx=slice(x0,T//2+1,None)
print(f'\nFit with range [{x0}, {xx[-1]}]')
W = numpy.diag(1./dy[idx]**2)
cs = chisquare(xx[idx],yy[idx],W,f,df)
cs.fit(p0, minimize)
print(f'parameters = {cs.p}')
print(f'chi^2 = {cs.c2:g}')
[ce,dce,_] = cs.chiexp(dat[:,idx])
print(f'chiexp = {ce:g} +- {dce:g}')
[p,dp,h] = cs.pvalue()
print(f'chiexp from MC = {numpy.mean(h):g} +- {numpy.sqrt(numpy.var(h)/len(h)):g}')
res.append([cs.c2, ce, dce, p, dp])
res = numpy.array(res)
try:
import matplotlib.pyplot as plt
plt.figure()
plt.xlabel('x0min')
plt.ylabel('Chi^2 / ChiExp')
plt.errorbar(x0min,res[:,0]/res[:,1],res[:,0]/res[:,1]**2*res[:,2],fmt='.')
plt.show()
plt.figure()
plt.xlabel('x0min')
plt.ylabel('Quality of fit')
plt.errorbar(x0min,res[:,3],res[:,4],fmt='.')
plt.show()
except:
pass