目录

  • 层次分析法概述
    • 定义
    • 步骤归纳
    • 例子
    • 应用实例
  • Python实现
    • 程序如下:
    • 运行结果截图

层次分析法概述

定义

本文所有图片均来自本人的OneNote笔记

步骤归纳



例子

  1. 建立层次结构模型

  2. 构造判断(成对比较)矩阵


    第二层A的各个因素对目标层Z的成对比较矩阵(专家打分法)

    说明C2的重要性是C1的两倍
    第三层B的各个因素A1,A2……A5的成对比较矩阵分别如下:

  3. 层次单排序及其一致性检验











    0.6=1/(1+1/2+1/6) 矩阵中其他数值同理
    0.587=1/3(0.6+0.615+0.545)

  4. 层次单排序及其一致性检验





应用实例





Python实现

程序如下:

(本程序配的案例,现在是机密,先不能公开,但看程序仍可以理解)

import numpy as np# A--D的判断矩阵
A_D = np.array([[1, 2, 6, 4],[1 / 2, 1, 5, 2],[1 / 6, 1 / 5, 1, 1 / 2],[1 / 4, 1 / 2, 2, 1]
])
# A1-A4的判断矩阵
A1_A4 = np.array([[1, 4, 5, 4],[1 / 4, 1, 4, 2],[1 / 5, 1 / 4, 1, 1 / 3],[1 / 4, 1 / 2, 3, 1]
])
# B1-B3的判断矩阵
B1_B3 = np.array([[1, 2, 3],[1 / 2, 1, 3],[1 / 3, 1 / 3, 1]
])
# C1--C2
C1_C2 = np.array([[1, 2],[1 / 2, 1]
])
# D1--D2
D1_D2 = np.array([[1, 1],[1, 1]
])
# A11_A14的判断矩阵
A11_A14 = np.array([[1, 1 / 5, 1 / 4, 1 / 2],[5, 1, 2, 3],[4, 1 / 2, 1, 2],[2, 1 / 3, 1 / 2, 1]
])
# A1的评价矩阵
A1_Emat = np.array([[0.109, 0.176, 0.142, 0.302, 0.27],[0.077, 0.062, 0.145, 0.324, 0.392],[0.057, 0.118, 0.159, 0.34, 0.327],[0.074, 0.173, 0.221, 0.402, 0.131]
])
# A21--A22
A21_A22 = np.array([[1, 1 / 2],[2, 1]
])
# A2的评价矩阵
A2_Emat = np.array([[0.182, 0.198, 0.245, 0.265, 0.11],[0.133, 0.147, 0.126, 0.318, 0.276]
])# A31--A33
A31_A33 = np.array([[1, 2, 1],[1 / 2, 1, 1 / 2],[1, 2, 1]
])
# A3的评价矩阵
A3_Emat = np.array([[0.088, 0.206, 0.234, 0.265, 0.207],[0.093, 0.129, 0.25, 0.34, 0.188],[0.007, 0.255, 0.221, 0.341, 0.176]
])
# A41--A42
A41_A42 = np.array([[1, 1 / 2],[2, 1]
])
# A4的评价矩阵
A4_Emat = np.array([[0.124, 0.211, 0.235, 0.248, 0.182],[0.098, 0.182, 0.203, 0.302, 0.214]
])
# B11--B13
B11_B13 = np.array([[1, 1 / 2, 1 / 3],[2, 1, 1 / 2],[3, 2, 1]
])
# B1的评价矩阵
B1_Emat = np.array([[0.067, 0.194, 0.195, 0.193, 0.351],[0.06, 0.161, 0.191, 0.206, 0.382],[0.097, 0.134, 0.233, 0.353, 0.284]
])
# B21--B23
B21_B23 = np.array([[1, 1 / 2, 1 / 3],[2, 1, 1 / 2],[3, 2, 1]
])
# B2的评价矩阵
B2_Emat = np.array([[0.098, 0.182, 0.303, 0.302, 0.114],[0.074, 0.163, 0.221, 0.312, 0.231],[0.082, 0.198, 0.145, 0.365, 0.21]
])
# B31--B33
B31_B33 = np.array([[1, 1 / 4, 1 / 3],[4, 1, 2],[3, 1 / 2, 1]
])
# B3的评价矩阵
B3_Emat = np.array([[0.06, 0.157, 0.335, 0.312, 0.136],[0.007, 0.199, 0.223, 0.355, 0.216],[0.065, 0.054, 0.186, 0.391, 0.304]
])# C11--C12
C11_C12 = np.array([[1, 3 / 2],[2 / 3, 1]
])
# C1的评价矩阵
C1_Emat = np.array([[0.093, 0.225, 0.331, 0.249, 0.101],[0.093, 0.213, 0.335, 0.265, 0.095]
])
# C21--C23
C21_C23 = np.array([[1, 3, 1 / 3],[1 / 3, 1, 1 / 5],[3, 5, 1]
])
# C2的评价矩阵
C2_Emat = np.array([[0.06, 0.161, 0.291, 0.306, 0.182],[0.097, 0.234, 0.333, 0.253, 0.084],[0.067, 0.194, 0.295, 0.293, 0.151]
])
# D11--D12
D11_D12 = np.array([[1, 4 / 3],[3 / 4, 1]
])
# D1的评价矩阵
D1_Emat = np.array([[0.074, 0.163, 0.221, 0.312, 0.231],[0.097, 0.234, 0.233, 0.253, 0.184]
])
# D21--D23
D21_D23 = np.array([[1, 2, 2],[1 / 2, 1, 1 / 2],[1 / 2, 2, 1]
])
# D2的评价矩阵
D2_Emat = np.array([[0.079, 0.198, 0.321, 0.29, 0.112],[0.093, 0.199, 0.35, 0.278, 0.08],[0.097, 0.234, 0.333, 0.253, 0.084]
])def Eigenvalues_Feature_vector(phalanx):# 计算判断矩阵的特征值和特征向量a, b = np.linalg.eig(phalanx)# print("特征值是\n", a)print("特征值实部:", a.real)  # 显示特征值实部max_eigenvalue = max(a.real)print("最大特征值:", max_eigenvalue)num_shape = phalanx.shapeCI = (max_eigenvalue - num_shape[0]) / (num_shape[0] - 1)print("---->> CI=", CI)if num_shape[0] == 2:RI = 0elif num_shape[0] == 3:RI = 0.52else:RI = 0.89if RI == 0 and CI == 0:CR = 0print("---->> CR=", CR)else:CR = CI / RIprint("---->> CR=", CR)if CR < 0.1:print("---->> 一致性比例可接受!")else:print("---->> 一致性检验不通过!")print("\n")# print("特征向量是\n", b)  # numpy的特征向量是竖方向的,numpy输出的特征向量是单位化后的向量print("特征向量实部:", b.real)return bdef Weight_vector(phalanx):# 计算判断矩阵的权向量num = 0b = Eigenvalues_Feature_vector(phalanx)for i in range(len(b.real)):num += b.real[i][0]print("\n")print("指标权重是:")weight_list = []for j in range(len(b.real)):weight_num = b.real[j][0] / numweight_list.append(weight_num)print(weight_list)print("\n")return np.array([weight_list])def get_point(phalanx, Emat):# 计算得分vec = Weight_vector(phalanx)Eva = np.dot(vec, Emat)print(Eva)grade = np.array([[20, 40, 60, 80, 100]])Eva_point = np.dot(Eva, grade.T)print("评价得分:----------->>", Eva_point[0][0])print("*" * 80)return Eva_point[0][0]A_D_weightmat = Weight_vector(A_D)
A1_A4_weightmat = Weight_vector(A1_A4)
B1_B3_weightmat = Weight_vector(B1_B3)
C1_C2_weightmat = Weight_vector(C1_C2)
D1_D2_weightmat = Weight_vector(D1_D2)
point_A1 = get_point(A11_A14, A1_Emat)
point_A2 = get_point(A21_A22, A2_Emat)
point_A3 = get_point(A31_A33, A3_Emat)
point_A4 = get_point(A41_A42, A4_Emat)
point_B1 = get_point(B11_B13, B1_Emat)
point_B2 = get_point(B21_B23, B2_Emat)
point_B3 = get_point(B31_B33, B3_Emat)
point_C1 = get_point(C11_C12, C1_Emat)
point_C2 = get_point(C21_C23, C2_Emat)
point_D1 = get_point(D11_D12, D1_Emat)
point_D2 = get_point(D21_D23, D2_Emat)def standard_layer_score(weightmat, point1, point2, point3=0, point4=0):# 标准层的得分pointlist = []for i in [point1, point2, point3, point4]:if i > 0:pointlist.append(i)pointmat = np.array(pointlist)print(pointlist)standard_point = np.dot(weightmat, pointmat.T)print("------>>>标准层得分", standard_point)return standard_point[0]point_A = standard_layer_score(A1_A4_weightmat, point_A1, point_A2, point_A3, point_A4)
point_B = standard_layer_score(B1_B3_weightmat, point_B1, point_B2, point_B3)
point_C = standard_layer_score(C1_C2_weightmat, point_C1, point_C2)
point_D = standard_layer_score(D1_D2_weightmat, point_D1, point_D2)def total_Score(weightmat, point1, point2, point3, point4):# 计算总得分pointlist = []for i in [point1, point2, point3, point4]:if i > 0:pointlist.append(i)pointmat = np.array(pointlist)print(pointlist)total_Score = np.dot(weightmat, pointmat.T)print("------>>>总得分", total_Score[0])total_Score(A_D_weightmat, point_A, point_B, point_C, point_D)#如果要用层次分析法问卷调查的数据,用一下程序进行归一化
a1=np.array([0.109,0.176,0.142,0.302,0.270])#评价矩阵分隔开的向量
A3_Emat = np.array([[0.088, 0.206, 0.234, 0.265, 0.207],[0.093, 0.129, 0.25, 0.34, 0.188],[0.007, 0.255, 0.221, 0.341, 0.176]
])
a2=np.array([20,40,60,80,100])
points=np.dot(A3_Emat,a2.T)
print(points)
#归一化处理,归到1-5之内
for point in points:point_num=point/100print("%.3f"%float(point_num))

运行结果截图

层次分析法原理分析及Python实现层析分析法相关推荐

  1. python空间分析_读书笔记——《python地理空间分析指南》

    本文为<Python地理空间分析指南(第2版)>的读书摘录,顺便挖个坑,进一步对python的几个包做学习整理. 本笔记的用途:了解python地理空间处理的技术框架和实现途径. 第三章 ...

  2. python交叉验证法_详解python实现交叉验证法与留出法

    在机器学习中,我们经常在训练集上训练模型,在测试集上测试模型.最终的目标是希望我们的模型在测试集上有最好的表现. 但是,我们往往只有一个包含m个观测的数据集D,我们既要用它进行训练,又要对它进行测试. ...

  3. 牛顿-拉夫逊法 原理讲解以及python算例实现

    文章目录 一.基本原理 二.原理深入讲解 1 .切线是曲线的线性逼近 2. 牛顿-拉夫逊法 3 .牛顿-拉夫逊法是否总是收敛(总是可以求得足够近似的根)? 三.pythons实例 总结 一.基本原理 ...

  4. 数据分析系列:绩效(效率)评价与python实现(层析分析、topsis、DEA)

    当分析一个项目是否可行,或多个决策中挑选出最优的一个进行执行,对以往的项目或人员进行绩效评价时,我们需要对一项业务或人员的绩效(效率)进行打分.这就是绩效(效率)评价的目标. 假设有下面一个案例,我们 ...

  5. Python实现熵值法确定权重

    该文为转载文章,无排版,链接直达 Python实现熵值法确定权重 本文从以下四个方面,介绍用Python实现熵值法确定权重: 一. 熵值法介绍 二. 熵值法实现 三. Python实现熵值法示例1 四 ...

  6. 详述激光三角测距法原理

    详述激光三角测距法原理 博主介绍 前言 激光雷达四大核心组件 激光三角测距法原理 1.直射式激光三角测距法 2.斜射式激光三角测距法

  7. 灰色关联分析法详解及python实践

    1. 关于灰色关联分析 1.1. 什么是灰色关联分析 灰色关联分析是指对一个系统发展变化态势的定量描述和比较的方法,其基本思想是通过确定参考数据列和若干个比较数据列的几何形状相似程度来判断其联系是否紧 ...

  8. Matlab基于SEIRD模型,NSIR预测模型,AHP层次分析法新冠肺炎预测与评估分析

    全文链接:http://tecdat.cn/?p=32175 分析师:Jiahui Zhao 新型冠状病毒肺炎COVID-19 给中国乃至全世界都带来了深重的灾难,对世界经济也造成了不可逆的影响(点击 ...

  9. 【编译原理】 实验三 LL(1)分析法(LL1分析表的自动生成)

    写在前面 由于代码较长,csdn对文章总长度有字数限制,想只看完整代码的请移步另一篇博客. https://blog.csdn.net/qq_46640863/article/details/1257 ...

最新文章

  1. 简单两行,实现无线WiFi共享上网,手机抓包再也不用愁了
  2. 武汉科技大学ACM:1002: 华科版C语言程序设计教程(第二版)例题6.6
  3. shiro学习总结(一)----初识shiro
  4. 深度学习核心技术精讲100篇(七十九)-深度学习应用实战案例:携程金融自动化迭代反欺诈模型体系
  5. postman 怎么调试pos_SpringBoot|第十五章:基于Postman的RESTful接口测试
  6. linux下的C语言开发(ATT 汇编语言)
  7. sd-card on android 5.0,Android5.0以上SDCard文件删除问题
  8. 如何计算给定一个unigram语言模型_数位语音处理Lesson3-初识前端信号处理、语言模型...
  9. flume学习(三):Flume Interceptors的使用
  10. JAR包自动启动脚本
  11. 计算机管理格式化硬盘,教你电脑怎么格式化硬盘
  12. matlab/simulink电力电子仿真斜坡信号Ramp设置和使用
  13. 动效设计入门工具小手册(微交互)
  14. 计算机课代表中段考总结,第一学期中段考试总结
  15. SQLConverter SQLserver数据库转换为SQLLite数据库
  16. 谁动了我的奶酪 读后感
  17. 动手学PyTorch | (35) 长短期记忆(LSTM)
  18. 东方程序员眼中的西方程序员是怎样的?
  19. python3中字符串的切片练习
  20. Python与人工智能入门实践——简易人脸识别系统

热门文章

  1. 2020 web前端面试题及答案大全
  2. 汇编语言,大写字母转换为小写
  3. C#免费教程(bili网站搜罗VSTO免费视频资源)
  4. hdu2907 凸包+简单搜索
  5. 计算机高级搜索文章内容,外文信息计算机检索
  6. OSChina 周二乱弹 —— 对!公交车绝缘体
  7. PhoneGapjQuery Mobile应用开发环境配置(For Android)
  8. 【MATLAB教程案例16】基于GWO灰狼优化算法的函数极值计算matlab仿真及其他应用
  9. js中图片base64格式转文件对象
  10. C/java 实现爱心