import csv import numpy as np import tensorflow as tf from sklearn.preprocessing import MinMaxScaler from numpy import * class AHP: def __init__(self, array): self.row = len(array) self.col = len(array[0]) def get_tezheng(self, array):# 获取特征值和特征向量 te_val, te_vector = np.linalg.eig(array) list1 = list(te_val) print("特征值为:", te_val) print("特征向量为:", te_vector) # 得到最大特征值对应的特征向量 max_val = np.max(list1) index = list1.index(max_val) max_vector = te_vector[:, index] print("最大的特征值:" + str(max_val) + " 对应的特征向量为:" + str(max_vector)) return max_val, max_vector def RImatrix(self, n): # 建立RI矩阵 print(n) n1 = [1, 2, 3, 4, 5, 6, 7, 8, 9] n2 = [0, 0, 0.58, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45] d = dict(zip(n1,n2)) print("该矩阵在一致性检测时采用的RI值为:", d[n]) return d[n] def test_consitstence(self, max_val, RI): # 测试一致性 CI = (max_val - self.row) / (self.row - 1) if RI == 0: print("判断矩阵的RI值为 " + str(0) + " 通过一致性检验") return True else: CR = CI / RI if CR < 0.10:
Python实现AHP(层次分析法)
最新推荐文章于 2025-03-13 14:08:57 发布