当前位置:   article > 正文

层次分析法、熵值法、博弈论确定指标权重_博弈论 计算最优权重

博弈论 计算最优权重

我们在进行综合评价的时候需要确定每个指标的权重,权重设置的差异会导致出现完全不同的评价结果,然而权重的确定是一个令人头疼的事情。权重的确定方法主要可以分成三大类,主观赋权以及客观赋权,以及主客观相结合的方式。这里我们不讨论各种方式的优缺点,以及各种方法的理论,直接使用代码实现三大类方法各一种

层次分析法(AHP)

  1. ## 层次分析法权重计算
  2. def AHP(A):
  3. A=A
  4. #step:计算特征值和对应的特征向量
  5. A_lambda,A_vector=np.linalg.eig(A)
  6. #step2:获取对他的特征值
  7. A_maxlambda=max(A_lambda).real.round(4)
  8. #step3:获取对打特征值的索引号
  9. A_index=np.argmax(A_lambda)
  10. #step4:获取最大特征值对应的特征向量
  11. A_maxvector=A_vector[:,A_index].real.round(4)
  12. # step5: 特征值法求权重
  13. A_weight=A_maxvector/A_maxvector.sum()
  14. # 进行一致性检验
  15. RI_list = [0, 0, 0.58 , 0.90, 1.12, 1.24, 1.32, 1.41, 1.45]
  16. A_CI=(A_maxlambda-A.shape[0])/(A.shape[0]-1)
  17. A_RI=RI_list[A.shape[0]-1]
  18. A_CR=A_CI/RI_list[A.shape[0]-1]
  19. if A_CR<0.1 :
  20. print('CR值为',A_CR,' 小于0.1 通过一致性检验')
  21. return A_weight,A_maxlambda
  22. else:
  23. print('CR值为',A_CR,' 未通过一致性检验')

熵值法

  1. import math
  2. from numpy import array
  3. # 定义熵值法确定权重
  4. def cla_entry_weight(data):
  5. x=data
  6. #求k
  7. rows=x.index.size # 行
  8. cols=x.columns.size # 列
  9. k=1.0/math.log(rows)
  10. lnf = [[None] * cols for i in range(rows)]
  11. #矩阵计算
  12. #信息熵
  13. x = array(x)
  14. lnf = [[None] * cols for i in range(rows)]
  15. lnf = array(lnf)
  16. for i in range(0, rows):
  17. for j in range(0, cols):
  18. if x[i][j] == 0:
  19. lnfij = 0.0
  20. else:
  21. p = x[i][j] / x.sum(axis=0)[j]
  22. lnfij = math.log(p) * p * (-k)
  23. lnf[i][j] = lnfij
  24. lnf = pd.DataFrame(lnf)
  25. E = lnf
  26. # 计算冗余度
  27. d = 1 - E.sum(axis=0)
  28. # 计算各指标的权重
  29. w = [[None] * 1 for i in range(cols)]
  30. for j in range(0, cols):
  31. wj = d[j] / sum(d)
  32. w[j] = wj
  33. # 计算各样本的综合得分,用最原始的数据
  34. w=pd.DataFrame(w)
  35. return w

博弈论

  1. import pandas as pd
  2. import numpy as np
  3. #层次分析法获取权重
  4. w1=np.array([[0.1675,0.06,0.025,0.345,0.105,0.105,0.195]])
  5. #熵值法获取权重
  6. w2=np.array([0.344,0,0.074,0.184,0.096,0,0.302])
  7. def game_throry(w1,w2):
  8. '''
  9. w1:方法1计算的权重
  10. w2:方法2计算的权重
  11. d1:博弈论中w1的占比
  12. d2:博弈论中w2的占比
  13. w:计算结果
  14. '''
  15. w1=w1
  16. w2=w2
  17. w1_T=w1.T
  18. w2_T=w2.T
  19. AA=w1.dot(w1_T).reshape(1)
  20. BB=w1.dot(w2_T).reshape(1)
  21. CC=w2.dot(w1_T).reshape(1)
  22. DD=w2.dot(w2_T).reshape(1)
  23. mm=np.array([[AA,BB],[CC,DD]]).reshape(2,2)
  24. Y=np.concatenate((AA,DD)).reshape(2,1)
  25. re=np.linalg.solve(mm,Y)
  26. d1=re[0]/(re.sum())
  27. d2=re[1]/(re.sum())
  28. w=w1*d1+w2*d2
  29. return d1,d2,w

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/496260
推荐阅读
相关标签
  

闽ICP备14008679号