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 99 100 101 102 103
| from statistics import geometric_mean
import numpy as np from pandas.core.ops import arithmetic_op
A = np.array([[1, 5, 3, 2], [1/5, 1, 2, 1/3], [1/3, 1/2, 1, 2], [1/2, 3, 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.26, 1.36, 1.41, 1.46, 1.49, 1.52, 1.54, 1.56, 1.58, 1.59]
CR = CI / RI[n]
print('一致性指标CI=', CI) print('一致性比例CR=', CR)
if CR < 0.10: print('因为CR<0.10,所以该判断矩阵A的一致性可以接受!') else: print('注意: CR >= 0.10,因此该判断矩阵A需要进行修改!')
def arithmetic_mean_method (array):
A = array
ASum = np.sum(A, axis=0)
n, _ = A.shape
Stand_A = A / ASum
ASumr = np.sum(Stand_A, axis=1)
weights = ASumr / n
return weights
def geometric_mean_method (array) :
A = array
n, _ = A.shape
prod_A = np.prod(A, axis=1)
prod_n_A = np.power(prod_A, 1 / n)
re_prod_A = prod_n_A / np.sum(prod_n_A)
return re_prod_A
def eigenvalue_averaging_method (array) :
A = np.array([[1, 5, 3, 2], [1 / 5, 1, 1 / 2, 1 / 3], [1 / 3, 2, 1, 1 / 2], [1 / 2, 3, 2, 1]])
n, _ = A.shape
eig_values, eig_vectors = np.linalg.eig(A)
max_index = np.argmax(eig_values)
max_vector = eig_vectors[:, max_index]
weights = max_vector / np.sum(max_vector)
return weights
|