-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerMethod2.py
50 lines (38 loc) · 1.36 KB
/
PowerMethod2.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
import numpy as np
A = np.array([[0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0]])
G = np.zeros((A.shape[0], A.shape[0]))
N = np.zeros(A.shape[0])
for i in range(A.shape[0]):
s = 0
for j in range(A.shape[0]):
s += A[i, j]
N[i] = s
q = 0.15
n = A.shape[0]
for i in range(A.shape[0]):
for j in range(A.shape[0]):
G[i, j] = (q / n) + ((A[j, i] * (1 - q)) / N[j])
def eigenvector(A):
P = np.full(A.shape[0], 1)
for b in range(20000):
P = np.dot(G, P)
s = 0
for i in range(A.shape[0]):
s += P[i]
for i in range(A.shape[0]):
P[i] /= s
print(P)
eigenvector(A)