blob: 3a2043ed70f112a5304c4741d3845a84dc7c1c0f (
plain) (
blame)
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
|
#!/usr/bin/python
#/usr/local/bin/python2.7
import numpy as np
def main():
dataz = np.genfromtxt('example.csv', delimiter=',', names=True)
y = dataz['attitude']
x = dataz['correct']
print 'x = {} {}'.format(x, np.mean(x))
print 'y = {} {}'.format(y, np.mean(y))
delta_x = x - np.mean(x)
delta_y = y - np.mean(y)
delta_xy = delta_x*delta_y
delta2_x = delta_x**2
delta2_y = delta_y**2
print 'delta_x = {} {}'.format(delta_x, np.sum(delta_x))
print 'delta_y = {} {}'.format(delta_y, np.sum(delta_y))
print 'delta_xy = {} {}'.format(delta_xy, np.sum(delta_xy))
print 'delta2_x = {} {}'.format(delta2_x, np.sum(delta2_x))
print 'delta2_y = {} {}'.format(delta2_y, np.sum(delta2_y))
Sx = np.sqrt(np.sum(delta2_x)/(delta2_x.size - 1))
Sy = np.sqrt(np.sum(delta2_y)/(delta2_y.size - 1))
r = np.sum(delta_xy)/np.sqrt(np.sum(delta2_x)*np.sum(delta2_y))
print 'Sx = {}'.format(Sx)
print 'Sy = {}'.format(Sy)
print 'r = {}'.format(r)
print 'r^2 = {}'.format(r**2)
b = r*(Sy/Sx)
a = np.mean(y) - b*np.mean(x)
print 'b = {}'.format(b)
print 'a = {}'.format(a)
print ' (attitude) \t= {}(correct) + {}'.format(b, a)
if __name__ == '__main__':
main()
|