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
| import numpy as np
A = np.array([[1,2,3,5],[1/2,1,1/2,2],[1/3,2,1,2],[1/5,1/2,1/2,1]])
n = A.shape[0]
eig_val,eig_vec = np.linalg.eig(A) max_eig = max(eig_val)
CI = (max_eig - n)/(n-1) RI = [0,0.0001,0.52,0.89,1.12,1.36,1.41,1.46,1.49,1.52,1.54,1.56,1.58,1.59]
CR = CI/RI[n-1] print(CR)
A_sum = np.sum(A,axis=0)
Stand_A = A/A_sum
Asumr = np.sum(Stand_A,axis=1)
weights = Asumr/n
prodA = np.prod(A,axis=1)
prodnA = np.power(prodA,1/n)
weights1 = prodnA/np.sum(prodnA)
eig1,eig2 = np.linalg.eig(A)
maxindex = np.argmax(eig1)
maxv = eig2[:,maxindex]
weights2 = maxv/np.sum(maxv) print(weights2)
|