权重计算方法二:熵权法(EWM)
目錄
1.原理介紹
2.基本步驟
3.步驟詳解
3.1 數(shù)據(jù)歸一化(標(biāo)準(zhǔn)化)
3.2?計(jì)算第j項(xiàng)指標(biāo)下第i個(gè)方案的指標(biāo)值比重
3.3?計(jì)算第j項(xiàng)指標(biāo)的信息熵值
3.4 計(jì)算各指標(biāo)權(quán)重
4.案例分析
4.1 題目簡(jiǎn)介
4.2 標(biāo)準(zhǔn)化后數(shù)據(jù)
4.3?計(jì)算第j項(xiàng)指標(biāo)下第i個(gè)方案的指標(biāo)值比重
4.4?計(jì)算第j項(xiàng)指標(biāo)的信息熵值
4.5? 計(jì)算各指標(biāo)權(quán)重
4.6 計(jì)算得分
5.代碼實(shí)現(xiàn)
5.1 代碼(Java)
5.2 運(yùn)行截圖
1.原理介紹
????????熵是對(duì)不確定信息的度量,熵與信息量成反比,熵值越小越好。熵值越小,信息量越大,權(quán)重越大。
????????前文所講的層次分析法是一種具有很強(qiáng)主觀性的賦權(quán)方法,而熵權(quán)法則是一種客觀賦權(quán)法,即可以通過數(shù)據(jù)本身計(jì)算出權(quán)重。
2.基本步驟
3.步驟詳解
3.1 數(shù)據(jù)歸一化(標(biāo)準(zhǔn)化)
由于各項(xiàng)指標(biāo)計(jì)量單位不統(tǒng)一,因此在計(jì)算綜合權(quán)重前要先對(duì)其進(jìn)行歸一化處理,即把指標(biāo)的絕對(duì)值轉(zhuǎn)化為相對(duì)值。
對(duì)于正向指標(biāo):
對(duì)于負(fù)向指標(biāo):
?????????其中系數(shù)0.998和0.002的目的是為了使??的值大于0,防止在后續(xù)計(jì)算時(shí)出現(xiàn)的情況。這里的0.998可以更改成任意更接近于1的數(shù),如:0.999,0.997等。
3.2?計(jì)算第j項(xiàng)指標(biāo)下第i個(gè)方案的指標(biāo)值比重
,且? ? ??
3.3?計(jì)算第j項(xiàng)指標(biāo)的信息熵值
,其中? ?
3.4 計(jì)算各指標(biāo)權(quán)重
4.案例分析
4.1 題目簡(jiǎn)介
????????已知判斷某一水域水質(zhì)情況的好壞時(shí)可以通過x1-x9共9種指標(biāo)來評(píng)判,現(xiàn)有A-K共11條河流的指標(biāo)測(cè)量情況,請(qǐng)以此判斷各河流水質(zhì)的優(yōu)良
| 河流 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 |
| A | 88 | 63 | 17 | 50 | 53 | 49 | 64 | 24 | 32 |
| B | 75 | 1 | 2 | 43 | 14 | 53 | 31 | 18 | 42 |
| C | 79 | 48 | 73 | 62 | 43 | 48 | 72 | 76 | 98 |
| D | 73 | 95 | 9 | 34 | 20 | 46 | 54 | 4 | 59 |
| E | 36 | 70 | 53 | 5 | 100 | 6 | 74 | 25 | 43 |
| F | 40 | 46 | 92 | 60 | 68 | 19 | 2 | 76 | 8 |
| G | 20 | 78 | 35 | 98 | 83 | 70 | 35 | 58 | 1 |
| H | 67 | 29 | 38 | 3 | 32 | 27 | 3 | 47 | 75 |
| I | 38 | 30 | 28 | 72 | 46 | 20 | 50 | 42 | 74 |
| J | 95 | 25 | 20 | 42 | 13 | 54 | 56 | 54 | 82 |
| K | 40 | 32 | 27 | 14 | 22 | 59 | 6 | 81 | 53 |
4.2 標(biāo)準(zhǔn)化后數(shù)據(jù)
| 河流 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 |
| A | 0.924853 | 0.678255 | 0.186333 | 0.513747 | 0.478851 | 0.690531 | 0.879389 | 0.279221 | 0.338948 |
| B | 0.751867 | 0.02 | 0.02 | 0.440211 | 0.031471 | 0.752906 | 0.421972 | 0.201455 | 0.441835 |
| C | 0.805093 | 0.519 | 0.807311 | 0.639811 | 0.364138 | 0.674938 | 0.990278 | 0.953195 | 1.018 |
| D | 0.725253 | 1.018 | 0.097622 | 0.345663 | 0.100299 | 0.64375 | 0.740778 | 0.02 | 0.616742 |
| E | 0.232907 | 0.752574 | 0.585533 | 0.041011 | 1.018 | 0.02 | 1.018 | 0.292182 | 0.452124 |
| F | 0.286133 | 0.497766 | 1.018 | 0.6188 | 0.65092 | 0.222719 | 0.02 | 0.953195 | 0.092021 |
| G | 0.02 | 0.837511 | 0.385933 | 1.018 | 0.822989 | 1.018 | 0.477417 | 0.719896 | 0.02 |
| H | 0.645413 | 0.317277 | 0.4192 | 0.02 | 0.237954 | 0.347469 | 0.033861 | 0.577325 | 0.781361 |
| I | 0.25952 | 0.327894 | 0.308311 | 0.744863 | 0.398552 | 0.238312 | 0.685333 | 0.512519 | 0.771072 |
| J | 1.018 | 0.274809 | 0.2196 | 0.429705 | 0.02 | 0.7685 | 0.7685 | 0.668052 | 0.853381 |
| K | 0.286133 | 0.349128 | 0.297222 | 0.135558 | 0.123241 | 0.846469 | 0.075444 | 1.018 | 0.55501 |
4.3?計(jì)算第j項(xiàng)指標(biāo)下第i個(gè)方案的指標(biāo)值比重
| 河流 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 |
| A | 0.155303 | 0.121286 | 0.042884 | 0.103843 | 0.112766 | 0.110954 | 0.143903 | 0.045072 | 0.057057 |
| B | 0.126254 | 0.003576 | 0.004603 | 0.088979 | 0.007411 | 0.120976 | 0.069052 | 0.032519 | 0.074377 |
| C | 0.135192 | 0.092808 | 0.185799 | 0.129323 | 0.085752 | 0.108448 | 0.162049 | 0.153864 | 0.171366 |
| D | 0.121785 | 0.182039 | 0.022467 | 0.069868 | 0.02362 | 0.103437 | 0.121221 | 0.003228 | 0.10382 |
| E | 0.03911 | 0.134575 | 0.134758 | 0.008289 | 0.239732 | 0.003214 | 0.166586 | 0.047164 | 0.076109 |
| F | 0.048048 | 0.089011 | 0.234289 | 0.125077 | 0.153287 | 0.035786 | 0.003273 | 0.153864 | 0.01549 |
| G | 0.003358 | 0.149764 | 0.088821 | 0.205766 | 0.193808 | 0.163571 | 0.078125 | 0.116205 | 0.003367 |
| H | 0.108379 | 0.056735 | 0.096477 | 0.004043 | 0.056036 | 0.055831 | 0.005541 | 0.093191 | 0.131531 |
| I | 0.043579 | 0.058634 | 0.070957 | 0.150557 | 0.093856 | 0.038292 | 0.112148 | 0.082731 | 0.129799 |
| J | 0.170944 | 0.049141 | 0.05054 | 0.086855 | 0.00471 | 0.123482 | 0.125757 | 0.107837 | 0.143655 |
| K | 0.048048 | 0.062431 | 0.068405 | 0.0274 | 0.029022 | 0.13601 | 0.012346 | 0.164325 | 0.093428 |
4.4?計(jì)算第j項(xiàng)指標(biāo)的信息熵值
| 指標(biāo) | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 |
| 信息熵值 | 0.915132 | 0.928591 | 0.888545 | 0.894166 | 0.851147 | 0.92768 | 0.884052 | 0.919145 | 0.919939 |
4.5? 計(jì)算各指標(biāo)權(quán)重
| 指標(biāo) | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 |
| 權(quán)重 | 0.09737 | 0.081928 | 0.127874 | 0.121424 | 0.17078 | 0.082974 | 0.133028 | 0.092766 | 0.091855 |
4.6 計(jì)算得分
| 河流 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | 得分 |
| A | 88 | 63 | 17 | 50 | 53 | 49 | 64 | 24 | 32 | 48.77173 |
| B | 75 | 1 | 2 | 43 | 14 | 53 | 31 | 18 | 42 | 29.30177 |
| C | 79 | 48 | 73 | 62 | 43 | 48 | 72 | 76 | 98 | 65.44425 |
| D | 73 | 95 | 9 | 34 | 20 | 46 | 54 | 4 | 59 | 40.37694 |
| E | 36 | 70 | 53 | 5 | 100 | 6 | 74 | 25 | 43 | 50.31363 |
| F | 40 | 46 | 92 | 60 | 68 | 19 | 2 | 76 | 8 | 47.95403 |
| G | 20 | 78 | 35 | 98 | 83 | 70 | 35 | 58 | 1 | 54.82417 |
| H | 67 | 29 | 38 | 3 | 32 | 27 | 3 | 47 | 75 | 33.47667 |
| I | 38 | 30 | 28 | 72 | 46 | 20 | 50 | 42 | 74 | 45.34118 |
| J | 95 | 25 | 20 | 42 | 13 | 54 | 56 | 54 | 82 | 45.64744 |
| K | 40 | 32 | 27 | 14 | 22 | 59 | 6 | 81 | 53 | 33.50219 |
由以上得分可得河流水質(zhì)情況由好到差依次為C>G>E>A>F>J>I>D>K>H>B
5.代碼實(shí)現(xiàn)
5.1 代碼(Java)
package EWM;import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Scanner;import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; import jxl.write.WriteException;public class ewm {//private String filepath;//文件路徑private double[][] orig; //原始矩陣private double[][] uniform;//歸一化后的矩陣 int rows,cols;//存儲(chǔ)Excel的行和列數(shù)Scanner input = new Scanner(System.in);//矩陣每列最大值public double[] Max(double[][] m) {double max[] = new double[m[0].length];for(int j=0;j < m[0].length;j++) {max[j] = m[0][j];for(int i=0;i < m.length;i++) {if(m[i][j] >= max[j]) {max[j] = m[i][j];}}}return max;}//矩陣每列最小值public double[] Min(double[][] m) {double min[] = new double[m[0].length];for(int j=0;j < m[0].length;j++) {min[j] = m[0][j];for(int i=0;i < m.length;i++) {if(m[i][j] <= min[j]) {min[j] = m[i][j];}}}return min;}public void matrixoutput(double[][] x) {for(int i=0;i<x.length;i++) {for(int j=0;j<x[0].length;j++) {System.out.print(x[i][j]+" ");}System.out.println();}}//讀取數(shù)據(jù)public double[][] read(String filepath) throws IOException, BiffException,WriteException {//創(chuàng)建輸入流InputStream stream = new FileInputStream(filepath);//獲取Excel文件對(duì)象Workbook rwb = Workbook.getWorkbook(stream);//獲取文件的指定工作表 默認(rèn)的第一個(gè)Sheet sheet = rwb.getSheet("Sheet1");rows = sheet.getRows();cols = sheet.getColumns();orig = new double[rows][cols];uniform = new double[rows][cols];//row為行for(int i=0;i<sheet.getRows();i++) {for(int j=0;j<sheet.getColumns();j++) {String[] str = new String[sheet.getColumns()];Cell cell = null;cell = sheet.getCell(j,i); str[j] = cell.getContents();orig[i][j] = Double.valueOf(str[j]);//uniform[i][j] = Double.valueOf(str[j]);}}return orig;}//數(shù)據(jù)歸一化public double[][] uniform(double[][] x) {List<Integer> neg = new ArrayList<Integer>();//存儲(chǔ)逆向指標(biāo)所在列for(int i=0;i<x.length;i++) {for(int j=0;j<x[0].length;j++) {uniform[i][j] = 0.998*(x[i][j] - Min(x)[j])/(Max(x)[j] - Min(x)[j]) + 0.002;}}System.out.println("數(shù)據(jù)中是否有逆向指標(biāo)?是:1,否:2");int a = input.nextInt();if(a == 1) {System.out.println("輸入逆向指標(biāo)所在列(以“/”結(jié)尾):");while(!input.hasNext("/")) {neg.add(Integer.valueOf(input.nextInt()));}for(int i=0;i<x.length;i++) {for(int j=0;j<neg.size();j++) {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;}}}return uniform;}//確定第j個(gè)指標(biāo)在第i個(gè)項(xiàng)目的比重Pijpublic double[][] Pig(double[][] m){double[][] p = new double[m.length][m[0].length];double[] sum = new double[m[0].length];//每列之和for(int j=0;j<m[0].length;j++) {sum[j] = 0;for(int i=0;i<m.length;i++) {sum[j] += m[i][j];}}for(int j=0;j<m[0].length;j++) {for(int i=0;i<m.length;i++) {p[i][j] = m[i][j]/sum[j];}}return p;}//計(jì)算第j項(xiàng)指標(biāo)的信息熵值eijpublic double[] Eij(double[][] p) {double[] e = new double[p[0].length];double k = 1/Math.log(p.length);double[] sum = new double[p[0].length];for(int j=0;j<p[0].length;j++) {sum[j] = 0;for(int i=0;i<p.length;i++) {sum[j] += p[i][j]*Math.log(p[i][j]);}}for(int j=0;j<p[0].length;j++) {e[j] = -1*k*sum[j];}return e;}//計(jì)算各指標(biāo)的權(quán)值public double[] weight(double[] e) {double[] w = new double[e.length];double sum = 0;for(int j=0;j<e.length;j++) {sum += (1-e[j]);}for(int j=0;j<e.length;j++) {w[j] = (1-e[j])/sum;}return w;} } package EWM;import java.io.IOException;import jxl.read.biff.BiffException; import jxl.write.WriteException;public class ewmmain {public static void main(String args[]) throws BiffException, WriteException, IOException {ewm ewm = new ewm();double[][] a = ewm.read("ewm.xls");//輸出原始矩陣,行為評(píng)價(jià)對(duì)象,列為評(píng)價(jià)指標(biāo)System.out.println("原始矩陣為:");ewm.matrixoutput(a);double[][] x = ewm.uniform(a);System.out.println("標(biāo)準(zhǔn)化(歸一化)矩陣:");ewm.matrixoutput(x);double[][] p = ewm.Pig(x);System.out.println("確定第j個(gè)指標(biāo)在第i個(gè)項(xiàng)目的比重Pij矩陣:");ewm.matrixoutput(p);double[] e = ewm.Eij(p);System.out.println("確定第j個(gè)指標(biāo)的信息熵值:");for(int i=0;i<e.length;i++) {System.out.print(e[i]+" ");}System.out.println();double[] w = ewm.weight(e);System.out.println("確定各指標(biāo)的權(quán)值:");for(int i=0;i<w.length;i++) {System.out.print(w[i]+" ");}} }5.2 運(yùn)行截圖
總結(jié)
以上是生活随笔為你收集整理的权重计算方法二:熵权法(EWM)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: github上优秀的源码
- 下一篇: 机顶盒网络包获取方式