当前位置:   article > 正文

权重计算方法二:熵权法(EWM)

熵权法

目录

1.原理介绍

2.基本步骤

3.步骤详解

3.1 数据归一化(标准化)

3.2 计算第j项指标下第i个方案的指标值比重

3.3 计算第j项指标的信息熵值

3.4 计算各指标权重

4.案例分析

4.1 题目简介

4.2 标准化后数据

4.3 计算第j项指标下第i个方案的指标值比重

4.4 计算第j项指标的信息熵值

4.5  计算各指标权重

4.6 计算得分

5.代码实现

5.1 代码(Java)

5.2 运行截图


1.原理介绍

        熵是对不确定信息的度量,熵与信息量成反比,熵值越小越好。熵值越小,信息量越大,权重越大。

        前文所讲的层次分析法是一种具有很强主观性的赋权方法,而熵权法则是一种客观赋权法,即可以通过数据本身计算出权重。

2.基本步骤

3.步骤详解

3.1 数据归一化(标准化)

由于各项指标计量单位不统一,因此在计算综合权重前要先对其进行归一化处理,即把指标的绝对值转化为相对值。

对于正向指标:

对于负向指标:

         其中系数0.998和0.002的目的是为了使 x_{ij} 的值大于0,防止在后续计算ln{x_{ij}}时出现ln0的情况。这里的0.998可以更改成任意更接近于1的数,如:0.999,0.997等。

3.2 计算第j项指标下第i个方案的指标值比重

P_{ij}=\frac{x_{ij}}{ \sum_{i=1}^{n}x_{ij}},且      \sum P_{ij}=1

3.3 计算第j项指标的信息熵

e_{j}=-k\sum_{i=1}^{n}P_{ij}lnP_{ij},其中   k=\frac{1}{lnn}

3.4 计算各指标权重

\omega _j=\frac{​{1-e_j}}{\sum_{j=1}^{m}({1-e_j})}

4.案例分析

4.1 题目简介

        已知判断某一水域水质情况的好坏时可以通过x1-x9共9种指标来评判,现有A-K共11条河流的指标测量情况,请以此判断各河流水质的优良

河流x1x2x3x4x5x6x7x8x9
A886317505349642432
B7512431453311842
C794873624348727698
D7395934204654459
E36705351006742543
F4046926068192768
G20783598837035581
H6729383322734775
I383028724620504274
J952520421354565482
K40322714225968153

4.2 标准化后数据

河流x1x2x3x4x5x6x7x8x9
A0.9248530.6782550.1863330.5137470.4788510.6905310.8793890.2792210.338948
B0.7518670.020.020.4402110.0314710.7529060.4219720.2014550.441835
C0.8050930.5190.8073110.6398110.3641380.6749380.9902780.9531951.018
D0.7252531.0180.0976220.3456630.1002990.643750.7407780.020.616742
E0.2329070.7525740.5855330.0410111.0180.021.0180.2921820.452124
F0.2861330.4977661.0180.61880.650920.2227190.020.9531950.092021
G0.020.8375110.3859331.0180.8229891.0180.4774170.7198960.02
H0.6454130.3172770.41920.020.2379540.3474690.0338610.5773250.781361
I0.259520.3278940.3083110.7448630.3985520.2383120.6853330.5125190.771072
J1.0180.2748090.21960.4297050.020.76850.76850.6680520.853381
K0.2861330.3491280.2972220.1355580.1232410.8464690.0754441.0180.55501

4.3 计算第j项指标下第i个方案的指标值比重

河流x1x2x3x4x5x6x7x8x9
A0.1553030.1212860.0428840.1038430.1127660.1109540.1439030.0450720.057057
B0.1262540.0035760.0046030.0889790.0074110.1209760.0690520.0325190.074377
C0.1351920.0928080.1857990.1293230.0857520.1084480.1620490.1538640.171366
D0.1217850.1820390.0224670.0698680.023620.1034370.1212210.0032280.10382
E0.039110.1345750.1347580.0082890.2397320.0032140.1665860.0471640.076109
F0.0480480.0890110.2342890.1250770.1532870.0357860.0032730.1538640.01549
G0.0033580.1497640.0888210.2057660.1938080.1635710.0781250.1162050.003367
H0.1083790.0567350.0964770.0040430.0560360.0558310.0055410.0931910.131531
I0.0435790.0586340.0709570.1505570.0938560.0382920.1121480.0827310.129799
J0.1709440.0491410.050540.0868550.004710.1234820.1257570.1078370.143655
K0.0480480.0624310.0684050.02740.0290220.136010.0123460.1643250.093428

4.4 计算第j项指标的信息熵值

指标x1x2x3x4x5x6x7x8x9
信息熵值0.9151320.9285910.8885450.8941660.8511470.927680.8840520.9191450.919939

4.5  计算各指标权重

指标x1x2x3x4x5x6x7x8x9
权重0.097370.0819280.1278740.1214240.170780.0829740.1330280.0927660.091855

4.6 计算得分

河流x1x2x3x4x5x6x7x8x9得分
A88631750534964243248.77173
B751243145331184229.30177
C79487362434872769865.44425
D739593420465445940.37694
E3670535100674254350.31363
F404692606819276847.95403
G2078359883703558154.82417
H672938332273477533.47667
I38302872462050427445.34118
J95252042135456548245.64744
K4032271422596815333.50219

由以上得分可得河流水质情况由好到差依次为C>G>E>A>F>J>I>D>K>H>B

5.代码实现

5.1 代码(Java)

  1. package EWM;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Scanner;
  8. import jxl.Cell;
  9. import jxl.Sheet;
  10. import jxl.Workbook;
  11. import jxl.read.biff.BiffException;
  12. import jxl.write.WriteException;
  13. public class ewm {
  14. //private String filepath;//文件路径
  15. private double[][] orig; //原始矩阵
  16. private double[][] uniform;//归一化后的矩阵
  17. int rows,cols;//存储Excel的行和列数
  18. Scanner input = new Scanner(System.in);
  19. //矩阵每列最大值
  20. public double[] Max(double[][] m) {
  21. double max[] = new double[m[0].length];
  22. for(int j=0;j < m[0].length;j++) {
  23. max[j] = m[0][j];
  24. for(int i=0;i < m.length;i++) {
  25. if(m[i][j] >= max[j]) {
  26. max[j] = m[i][j];
  27. }
  28. }
  29. }
  30. return max;
  31. }
  32. //矩阵每列最小值
  33. public double[] Min(double[][] m) {
  34. double min[] = new double[m[0].length];
  35. for(int j=0;j < m[0].length;j++) {
  36. min[j] = m[0][j];
  37. for(int i=0;i < m.length;i++) {
  38. if(m[i][j] <= min[j]) {
  39. min[j] = m[i][j];
  40. }
  41. }
  42. }
  43. return min;
  44. }
  45. public void matrixoutput(double[][] x) {
  46. for(int i=0;i<x.length;i++) {
  47. for(int j=0;j<x[0].length;j++) {
  48. System.out.print(x[i][j]+" ");
  49. }
  50. System.out.println();
  51. }
  52. }
  53. //读取数据
  54. public double[][] read(String filepath) throws IOException, BiffException,WriteException {
  55. //创建输入流
  56. InputStream stream = new FileInputStream(filepath);
  57. //获取Excel文件对象
  58. Workbook rwb = Workbook.getWorkbook(stream);
  59. //获取文件的指定工作表 默认的第一个
  60. Sheet sheet = rwb.getSheet("Sheet1");
  61. rows = sheet.getRows();
  62. cols = sheet.getColumns();
  63. orig = new double[rows][cols];
  64. uniform = new double[rows][cols];
  65. //row为行
  66. for(int i=0;i<sheet.getRows();i++) {
  67. for(int j=0;j<sheet.getColumns();j++) {
  68. String[] str = new String[sheet.getColumns()];
  69. Cell cell = null;
  70. cell = sheet.getCell(j,i);
  71. str[j] = cell.getContents();
  72. orig[i][j] = Double.valueOf(str[j]);
  73. //uniform[i][j] = Double.valueOf(str[j]);
  74. }
  75. }
  76. return orig;
  77. }
  78. //数据归一化
  79. public double[][] uniform(double[][] x) {
  80. List<Integer> neg = new ArrayList<Integer>();//存储逆向指标所在列
  81. for(int i=0;i<x.length;i++) {
  82. for(int j=0;j<x[0].length;j++) {
  83. uniform[i][j] = 0.998*(x[i][j] - Min(x)[j])/(Max(x)[j] - Min(x)[j]) + 0.002;
  84. }
  85. }
  86. System.out.println("数据中是否有逆向指标?是:1,否:2");
  87. int a = input.nextInt();
  88. if(a == 1) {
  89. System.out.println("输入逆向指标所在列(以“/”结尾):");
  90. while(!input.hasNext("/")) {
  91. neg.add(Integer.valueOf(input.nextInt()));
  92. }
  93. for(int i=0;i<x.length;i++) {
  94. for(int j=0;j<neg.size();j++) {
  95. uniform[i][neg.get(j)] = 0.998*(Max(x)[neg.get(j)] - x[i][neg.get(j)])/(Max(x)[neg.get(j)] - Min(x)[neg.get(j)]) + 0.002;
  96. }
  97. }
  98. }
  99. return uniform;
  100. }
  101. //确定第j个指标在第i个项目的比重Pij
  102. public double[][] Pig(double[][] m){
  103. double[][] p = new double[m.length][m[0].length];
  104. double[] sum = new double[m[0].length];
  105. //每列之和
  106. for(int j=0;j<m[0].length;j++) {
  107. sum[j] = 0;
  108. for(int i=0;i<m.length;i++) {
  109. sum[j] += m[i][j];
  110. }
  111. }
  112. for(int j=0;j<m[0].length;j++) {
  113. for(int i=0;i<m.length;i++) {
  114. p[i][j] = m[i][j]/sum[j];
  115. }
  116. }
  117. return p;
  118. }
  119. //计算第j项指标的信息熵值eij
  120. public double[] Eij(double[][] p) {
  121. double[] e = new double[p[0].length];
  122. double k = 1/Math.log(p.length);
  123. double[] sum = new double[p[0].length];
  124. for(int j=0;j<p[0].length;j++) {
  125. sum[j] = 0;
  126. for(int i=0;i<p.length;i++) {
  127. sum[j] += p[i][j]*Math.log(p[i][j]);
  128. }
  129. }
  130. for(int j=0;j<p[0].length;j++) {
  131. e[j] = -1*k*sum[j];
  132. }
  133. return e;
  134. }
  135. //计算各指标的权值
  136. public double[] weight(double[] e) {
  137. double[] w = new double[e.length];
  138. double sum = 0;
  139. for(int j=0;j<e.length;j++) {
  140. sum += (1-e[j]);
  141. }
  142. for(int j=0;j<e.length;j++) {
  143. w[j] = (1-e[j])/sum;
  144. }
  145. return w;
  146. }
  147. }
  1. package EWM;
  2. import java.io.IOException;
  3. import jxl.read.biff.BiffException;
  4. import jxl.write.WriteException;
  5. public class ewmmain {
  6. public static void main(String args[]) throws BiffException, WriteException, IOException {
  7. ewm ewm = new ewm();
  8. double[][] a = ewm.read("ewm.xls");
  9. //输出原始矩阵,行为评价对象,列为评价指标
  10. System.out.println("原始矩阵为:");
  11. ewm.matrixoutput(a);
  12. double[][] x = ewm.uniform(a);
  13. System.out.println("标准化(归一化)矩阵:");
  14. ewm.matrixoutput(x);
  15. double[][] p = ewm.Pig(x);
  16. System.out.println("确定第j个指标在第i个项目的比重Pij矩阵:");
  17. ewm.matrixoutput(p);
  18. double[] e = ewm.Eij(p);
  19. System.out.println("确定第j个指标的信息熵值:");
  20. for(int i=0;i<e.length;i++) {
  21. System.out.print(e[i]+" ");
  22. }
  23. System.out.println();
  24. double[] w = ewm.weight(e);
  25. System.out.println("确定各指标的权值:");
  26. for(int i=0;i<w.length;i++) {
  27. System.out.print(w[i]+" ");
  28. }
  29. }
  30. }

5.2 运行截图

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

闽ICP备14008679号