数学モデリング--階層分析法(コードPython実装)
# A = [[1,1,4,1/3,3],
# [1,1,4,1/3,3],
# [1/4,1/4,1,1/3,1/2],
# [3,3,3,1,3],
# [1/3,1/3,2,1/3,1]]
モデルに関する紹介参考リンク:階層分析法.
import numpy as np # np
def ConsisTest(X): # A
#
# :
## : ( )
X = np.array(X) # X np.array
sum_X = X.sum(axis=0) # X
(n,n) = X.shape #X , , n
sum_X = np.tile(sum_X,(n,1)) # n
stand_X = X/sum_X # X(X )
## :
sum_row = stand_X.sum(axis=1)
## : n
print(" :")
print(sum_row/n)
# :
## : X
V,E = np.linalg.eig(X) #V ,E
max_value = np.max(V) #
#print(" :",max_value)
max_v_index = np.argmax(V) #
max_eiv = E[:,max_v_index] #
## :
stand_eiv = max_eiv/max_eiv.sum()
print(" :")
print(stand_eiv)
print("———————————————————————————————")
#
## : CI
CI = (max_value-n)/(n-1)
## : RI
RI = np.array([15,0,0,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
CR = CI/RI[n]
if CR < 0.1:
print("CR=",CR,", 0.1, ")
else:
print("CR=",CR,", 0.1, , ")
return None
#ConsisTest(A)