-
Notifications
You must be signed in to change notification settings - Fork 2
/
eigen.py
69 lines (63 loc) · 1.29 KB
/
eigen.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
import numpy as np
from bokeh.plotting import figure, HBox, output_file, show, VBox
from bokeh.models import Range1d
from bokeh.models import HoverTool
# Center your matrix
def center(v):
x = 0
y = 0
for i in v:
x+=i[0]
y+=i[1]
# What average?
meanX = np.mean(x)
meanY = np.mean(y)
centV = []
for i in v:
newPoint = ((i[0]-meanX), (i[1]-meanY))
centV.append(newPoint)
return centV
def col_v(v):
x = []
y = []
for i in v:
x.append(i[0])
y.append(i[1])
return (x,y)
def graph(v):
vectors = col_v(v)
x = vectors[0]
y = vectors[1]
# Output to static HTML file
output_file("lines.html", title="line plot example")
hover = HoverTool(
tooltips = [
("index", "$index"),
("(x,y)", "($x, $y)"),
]
)
TOOLS='box_zoom,box_select,crosshair,resize,reset'
p = figure(plot_width=600,plot_height=400,tools=[hover, TOOLS])
p.circle(x, y, size=20)
# Show the results
show(p)
def cov_Matrix(m):
vectors = col_v(m)
x = vectors[0]
y = vectors[1]
n = len(x)
summation = 0
for i, valx in enumerate(x):
prod = float(valx*y[i])
summation+=prod
cov = summation/n-1
return cov
def main():
v = [(-1,2), (-1,1), (1,-2),(4,2), (2,2), (-2,0), (-3,-2), (2,0)]
graph(v)
print v
centerVec = center(v)
summation = cov_Matrix(centerVec)
print centerVec
print summation
main()