forked from BeamCtrl/Airiana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics.py
executable file
·98 lines (93 loc) · 1.94 KB
/
statistics.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
#!/usr/bin/python3
import threading
import numpy
import math
def meanAbsError(a,b):
sum = 0
for x,y in zip(a,b):
sum += abs(x-y)
return sum/len(a)
def meanErrorSq(a,b):
sum = 0
for x,y in zip(a,b):
sum += (x-y)**2
return sum/len(a)
def rmsError(a,b):
sum=0
for x,y in zip(a,b):
sum += (x-y)**2
return math.sqrt(sum/len(a))
def mean(data):
sum=0
for each in data:
sum+= each
return sum/len(data)
def stddev(data):
ave = mean(data)
dev = int()
for each in data:
dev += (each-ave)**2
return ave ,numpy.sqrt(dev/len(data))
def z_test(x,y):
tx = threaded_stddev()
tx.data = x
tx.start()
ty = threaded_stddev()
ty.data = y
ty.start()
tx.join()
ty.join()
Z=(tx.ave-ty.ave)/ty.dev
return Z
def covariance(x,y):
tx = threaded_mean()
tx.data = x
tx.start()
ty = threaded_mean()
ty.data = y
ty.start()
tx.join()
ty.join()
sum =0
for each in range(len(x)):
sum+= (x[each]-tx.mean)*(y[each]-ty.mean)
return float(sum/len(x)-1)
def correlation(x,y):
tx = threaded_stddev()
tx.data = x
tx.start()
ty = threaded_stddev()
ty.data = y
ty.start()
tx.join()
ty.join()
return covariance(x,y)/(tx.dev*ty.dev)
class threaded_mean(threading.Thread):
def run (self):
self.data
self.mean=mean(self.data)
class threaded_stddev(threading.Thread):
def run(self):
self.data
self.ave, self.dev = stddev(self.data)
def chi2test(measured, calculated):
chi = 0
for x,y in zip( measured, calculated):
sq = (x-y)*(x-y)
chi += float(sq)/y
return chi/len(measured)
if __name__ == "__main__":
"""datax = [0,123,242,32342,4234,54234,334,74234,8423,944,14234]
datay = [0,100,200,30000,4000,50000,333,70000,8000,900,14000]
print "mean:", mean(datax)
print "stddev:",stddev(datax)
thread= threaded_mean()
thread.data = datax
thread.start()
dev_thread=threaded_stddev()
dev_thread.data=datax
dev_thread.start()
print "Correlation coef:", correlation(datax,datay)
print "Z", z_test(datax,datay)
"""
chi2test([1,2,3,4],[1,5,2,4])