-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
61 lines (41 loc) · 1.22 KB
/
stats.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
#!/usr/bin/env python
# This script calculates basic statistical property of a list.
# Usage: python stats.py input
# Chen-Yu Li cli56@illinois.edu
# 2014/5/20
import math, numpy, sys
import acor
def ACtime(g):
MEAN=numpy.mean(g)
STD=numpy.std(g)
for t in range(len(g)):
C = 0.0
for i in range((len(g)-t)):
C = C + (g[i]-MEAN)*(g[t+i]-MEAN)
C = C/((STD*STD)*(len(g)-t))
if C <= 0:
tCut=t
break
total = 0.0
for t in range((tCut-1)):
C = 0.0
for i in range((len(g)-t)):
C = C + (g[i]-MEAN)*(g[t+i]-MEAN)
C = C / ((STD*STD)*(len(g)-t))
total = total + C
kappa = 1 + 2 * total
return kappa
def error(g):
nEFF=len(g)/ACtime(g)
ERROR=numpy.stdev(g)/math.sqrt(nEFF)
return ERROR
def stats(g):
acor_result = acor.acor(g)
#l = [numpy.mean(g), numpy.std(g), ACtime(g), error(g)]
l = [numpy.mean(g), numpy.std(g), acor_result[0], numpy.std(g)/math.sqrt(len(g))]
return l
#g = numpy.loadtxt(sys.argv[1])
#print "mean = %f" % (numpy.mean(g))
#print "stdev = %f" % (numpy.std(g))
#print "autocorrelation time = %f" % (ACtime(g))
#print "error = %f" % (error(g))