Python implementation of DEMATEL-ISM model - method introduction and code reproduction

foreword

This article originates from the author's group work of the "System Engineering" course. The author tried to use the DEMATEL-ISM method to analyze, model and solve, but did not find the corresponding code on the Internet, especially the collection of the DEMATEL-ISM method. So I coded the Python code of the DEMATEL-ISM model and published it as the first blog~

In the references, the author mainly refers to the research of Li Guangli et al. 1 , and this paper will also interpret the method and reproduce the code based on this paper.

In the process of searching for information on the Internet, the author found a python code library 2 of the MCDA method , which contains a lot of relevant codes for the multi-criteria decision analysis model, including the code of DEMATEL, which I made some references to.

DEMATEL-ISM analysis method

Method introduction

DEMATEL (Decision Making Trial and Evaluation Laboratory), the full name is "Decision Making Trial and Evaluation Experiment Method", which is a method of analyzing system elements by using graph theory and matrix tools. The influence relationship can judge whether there is a relationship between elements and evaluate its strength. The full name of ISM (Interpretative Structural Modeling) is "Interpretative Structural Modeling", which is characterized by decomposing a complex system into several subsystems (elements), and constructing the system into a multi-level hierarchical structural model through algebraic operations.

The DEMATEL model can use matrix operations to find the causal relationship and influence strength among factors, and reveal the key influencing factors and the degree of influence in complex problems by visualizing the causal
relationship ; however, this method cannot effectively identify the hierarchy of factors in the system structure
. The ISM rule constructs a multi-level hierarchical directed topological graph by analyzing the direct binary correlations among the subsystems (factors or elements) that constitute the system, based on Boolean algebra operations, etc., but it cannot determine the degree of influence of elements on the system.

Combining the two methods, the key elements in the system and their influence degree can be identified, and the hierarchical structure of the elements can be constructed. The procedure of the DEMATEL-ISM method is as follows:

step

Identify system elements

Clearly analyze the elements that make up the system, and mark the elements that make up the system as x 1 x_1x1, x 2 x_2 x2, x 3 x_3 x3, … \ldots , x n x_n xn

Determine the direct impact matrix

Using expert scoring method, compare xi x_ixito xj x_jxjThe influence of , since the factor has no influence compared with itself, the diagonal value of the direct influence matrix is ​​0. The direct influence matrix AA is obtained by comparingA
A = [ 0 x 12 ⋯ x 1 n x 21 0 ⋯ x 2 n ⋮ ⋮ ⋱ ⋮ x m 1 x m 2 … 0 ] \begin{align} A= \begin{bmatrix} 0&x_{12}&\cdots&x_{1n}\\ x_{21}&0&\cdots&x_{2n}\\ \vdots &\vdots&\ddots &\vdots \\ x_{m1}&x_{m2}&\dots &0 \end{bmatrix} \end{align} A= 0x21xm 1x120xm 2x1nx2 n0
式中因素 x i j ( i = 1 , 2 , … , m ; j = 1 , 2 , … , n ; i ≠ j ) x_{ij}(i=1,2, \ldots, m;j=1,2, \ldots,n;i\neq j) xij(i=1,2,,m;j=1,2,,n;i=j ) means factorxi x_ixito xj x_jxjdirect impact. i = ji=ji=j时,xij = 0 x_{ij}=0xij=0

Specification Impact Matrix

Normalize the original relationship matrix to get the canonical influence matrix. There are many normalization methods. Here, the row maximum method can be used for normalization, that is, the matrix AAEach row of A is summed, and taking the maximum value among these values, the matrixAADivide the elements in A by the maximum value to get the norm direct influence matrixBBB
B = x i j m a x ( ∑ j = 1 n x i j ) \begin{align} B=\frac{x_{ij}}{max(\sum\limits_{j=1}^n x_{ij})} \end{align} B=max(j=1nxij)xij

Computing the Comprehensive Impact Matrix

The comprehensive system matrix reflects the comprehensive effect of the influence among the various elements in the system. After the normative influence matrix is ​​continuously multiplied by itself, all values ​​of the matrix will approach 0, that is, lim ⁡ k → ∞ B k = 0 \lim\limits_{k \to \infty} B^k=0klimBk=0 . When calculating the comprehensive impact matrix,
T = ( B + B 2 + ⋯ + B k ) = ∑ k = 1 ∞ B k = B ( I − B ) − 1 \begin{align} T=(B+B^2 +\dots +B^k)=\sum\limits_{k=1}^\infty B^k=B(IB)^{-1} \end{align}T=(B+B2++Bk)=k=1Bk=B(IB)1
where III identity matrix.

Calculate the influence degree, affected degree, central degree and cause degree of each element

Influence index matrix TTThe value sum of each row in T represents the comprehensive influence value of each row element on all other elements, which is recorded as D i D_iDi,有:
D i = ∑ j = 1 n x i j , ( i = 1 , 2 , … , n ) \begin{align} D_i=\sum\limits_{j=1}^n x_{ij},(i=1,2,\dots,n) \end{align} Di=j=1nxij,(i=1,2,,n)
Influenced degree refers to the matrix TTThe sum of the column values ​​in T represents the comprehensive influence value of each column element on all other elements, which is recorded asC i C_iCi,有:
C i = ∑ j = 1 n x j i , ( i = 1 , 2 , … , n ) \begin{align} C_i=\sum\limits_{j=1}^n x_{ji},(i=1,2,\dots,n) \end{align} Ci=j=1nxji,(i=1,2,,n)
The centrality indicates the position of a factor in the evaluation system and the size of its effect. The centrality of a certain element is the sum of the degree of influence and the degree of influence, which is recorded as M i M_iMi,有:
M i = D i + C i \begin{align} M_i=D_i+C_i \end{align} Mi=Di+Ci
The degree of cause is obtained by subtracting the degree of influence and the degree of being affected by an element, which is written as:
R i = D i − C i \begin{align} R_i=D_i-C_i \end{align}Ri=DiCi
When the cause degree is greater than 0, it means that the element has a great influence on other elements, which is called the cause element; when the cause degree is less than 0, the element is the result element.

draw a cause-and-effect diagram

The centrality M i M_iMiAs the abscissa, the cause degree R i R_iRiAs an ordinate, draw a cause-and-effect diagram. This graph can visually show the cause and effect relationship.

Determine the overall impact matrix

The overall influence matrix is ​​obtained by adding the comprehensive influence matrix and the identity matrix.

Determine reachability matrix

A threshold λ \lambda needs to be introduced when determining the reachability matrixλ is used to eliminate the less influential relationship between factors, so as to clarify the division of the hierarchical structure. Introduce thresholdλ \lambdaλ on the overall influence matrixEEE is processed, and the reachable matrixFFF。则有:
f i j = { 1 e i j ≥ λ ( i , j = 1 , 2 , … , n ) 0 e i j < λ ( i , j = 1 , 2 , … , n ) \begin{equation} f_{ij}= \begin{cases} 1 & & {e_{ij}\geq\lambda(i,j=1,2,\dots,n)}\\ 0 & & {e_{ij}<\lambda(i,j=1,2,\dots,n)} \end{cases} \end{equation} fij={ 10eijλ(i,j=1,2,,n)eij<λ(i,j=1,2,,n)

Hierarchy

By reachability matrix FFF 'siiFind the reachable setR ( x 1 ) = { xi ∣ F ij = 1 } R(x_1)=\{x_i|F_{ij} =1\} from the factor corresponding to the column with a value of 1 on row iR(x1)={ xiFij=1 } , which means from factorxi x_ixiStarting from the collection of all factors that can be reached, the reachable matrix FFF 'siiThe factor corresponding to the row with the value 1 on the i column is obtained to obtain the antecedent set S ( x 1 ) = { xi ∣ F ji = 1 } S(x_1)=\{x_i|F_{ji} =1\}S(x1)={ xiFji=1 } , which means the set of all factors that can reach the factor. IfR ( x 1 ) R(x_1)R(x1) andS ( x 1 ) S(x_1)S(x1)满足 R ( x 1 ) ∩ S ( x 1 ) = R ( x 1 ) R(x_1)\cap S(x_1)=R(x_1) R(x1)S(x1)=R(x1) , it means that the corresponding elements in can find antecedents in , and this element is called a high-level element. Then the corresponding rows and columns are removed from the reachability matrix, and the highest-level factors are extracted from the matrix, and the process is repeated until all rows and columns are removed.

Plot hierarchical hierarchies among factors

According to the order of removing factors, a multi-level hierarchical directed topology graph among system elements is drawn.

Examples and Code

DEMATEL-ISM calculation

Here the author directly gives a set of data, 10 factors, which directly affect the matrix AAA is as follows.
directly affect matrix A

The following is the Python code for the DEMETAL-ISM calculation:

#导入所需库
import numpy as np
import pandas as pd

#直接影响矩阵A
A = np.array([[0, 2, 0, 2, 3, 2, 3, 2, 3, 2],
       [0, 0, 0, 1, 3, 2, 0, 1, 1, 2],
       [0, 1, 0, 0, 2, 1, 0, 0, 0, 1],
       [0, 2, 0, 0, 3, 2, 0, 0, 0, 1],
       [1, 3, 0, 2, 0, 1, 1, 0, 1, 1],
       [0, 2, 0, 2, 1, 0, 1, 1, 0, 2],
       [2, 2, 0, 0, 2, 1, 0, 1, 2, 1],
       [0, 2, 0, 0, 1, 1, 1, 0, 1, 2],
       [3, 2, 0, 1, 2, 2, 2, 2, 0, 1],
       [0, 2, 0, 0, 1, 2, 1, 1, 2, 0]])

#行和最大值归一化,得到规范影响矩阵B
row_sum = np.sum(A, axis = 1)
max_sum = np.max(row_sum)
B = A/max_sum

#综合影响矩阵T
T = np.matmul (B, np.linalg.inv(np.identity(A.shape[0]) - B))

#计算影响度D,被影响度C,中心度M,原因度R
D = np.sum(T, axis = 1)
C = np.sum(T, axis = 0)
M = D + C
R = D - C

#判断输出结果要素和原因要素
causal_factors = ''
result_factors = ''
for i in range(len(R)):
    if R[i] > 0:
            causal_factors = causal_factors + 'x' + str(i + 1) + ' '
    elif R[i] < 0:
            result_factors = result_factors + 'x' + str(i + 1) + ' '
print("原因要素:" + causal_factors)
print("结果要素:" + result_factors)

#使用相应的lambda值计算可达矩阵F,并输出节点度排序
E = T + np.identity(A.shape[0])
lbd = 0.20      # 相应的lambda值
F = E
for i in range(A.shape[0]):
    for j in range(A.shape[1]):
        if E[i, j] > lbd:
            F[i,j] = 1
        elif E[i, j] < lbd:
            F[i, j] = 0
node_degree = np.sum(F, axis = 0) + np.sum(F, axis = 1)
print(sorted(node_degree, reverse=True))

Some matrices and values ​​calculated by the above code are more important, such as the comprehensive impact matrix TTT , degree of influenceCCC. Influence degreeDDD. Cause degreeMMM , centralityRRR , etc. It is also useful to draw the data below. The author has no output here. In the process of doing research, the pandas library can be used to output the corresponding value to the excel table.
λ \lambdaThe value of λ is also critical. The specific value will be explained below. Here, 0.20 is used to obtain the final reachable matrix as shown in the figure below.
reachability matrix

cause-effect diagram

Next, use the results of the above calculations to draw a cause-effect diagram. In this diagram, you can see the magnitude of the mutual influence between each factor and the magnitude of the influence on the research content, as shown in the figure below.
cause-effect diagram
The first category is the set of strong causal factors (section I), which have a very significant impact on the formation of the research object and have a greater impact on other result factors; the second category is the set of weak causal factors (section I). Area II), this type of factor also has an important impact on the formation of the research object, and also has a certain impact on other result factors; the third type is the set of weak result factors (area III), this type of factor is a combination of other causal factors The result of the action has a certain influence on the formation of the research object; the fourth category is the strong result factor set (region IV), which is also the result of the comprehensive action of other causal factors, but it is very important to the formation of the research object. Impact. The greater the centrality of the factors calculated by DEMATEL, the greater the degree of influence. Therefore, it is necessary to focus on the strong cause factor set in area I and the strong effect factor set in area IV.

The following is the code of the reason-result graph. For the sake of beautiful graphics, the author’s code level is also very limited, so a lot of adjustments have been made, and you can watch yourself.

import matplotlib as mpl
import matplotlib.pyplot as plt

#设置图形格式
config = {
    
    
            "font.family": 'serif',
            "font.size": 14,
            "mathtext.fontset": 'stix',
            "font.serif": ['SimSun'],
            'axes.unicode_minus': False
          }
mpl.rcParams.update(config)

#x轴为上文计算出的中心度
x = [2.9456079466124003,
 3.243636237536544,
 0.5565493379272154,
 1.9429001271455832,
 3.205862930468748,
 2.627384244237508,
 2.4431692291267364,
 1.891879956077375,
 3.017054245988732,
 2.609503379763571]

y = [1.5128414543332274,
 -0.9939990519336557,
 0.5565493379272154,
 -0.1661886145842798,
 -0.8173828786366384,
 -0.6568575842419181,
 0.3753242725311403,
 -0.015046149922503416,
 0.6625117023194962,
 -0.4577524877920831]

#因子名
factors_name = [r'$x_1$', r'$x_2$', r'$x_3$', r'$x_4$', r'$x_5$',
                r'$x_6$', r'$x_7$', r'$x_8$', r'$x_9$', r'$x_{10}$']

#画散点图,并增加相应名称、线段和调整大小和位置
plt.scatter(x, y, s=3, c='k')

plt.xlabel('中心度')
plt.ylabel('原因度')
for i in range(len(x)):
    if i == 0:
        plt.text(x[i]+0.025, y[i]-0.085, factors_name[i], fontsize=17)
    elif i == 3:
        plt.text(x[i]+0.025, y[i]-0.1, factors_name[i], fontsize=17)
    elif i == 6:
        plt.text(x[i]-0.18, y[i]-0.1, factors_name[i], fontsize=17)
    elif i == 7:
        plt.text(x[i]-0.15, y[i]-0.12, factors_name[i], fontsize=17)
    else:
        plt.text(x[i]+0.025, y[i]+0.025, factors_name[i], fontsize=17)

plt.vlines(sum(x)/len(x), -1.55, 1.55, colors='k', linestyles='dashed')
plt.hlines(0, sum(x)/len(x)-2, sum(x)/len(x)+2, colors='k', linestyles='dashed')

plt.xlim(sum(x)/len(x)-2, sum(x)/len(x)+2)
plt.ylim(-1.55, 1.55)

plt.text(sum(x)/len(x)+2-0.2, 1.4-0.1, 'Ⅰ')
plt.text(sum(x)/len(x)-2+0.1, 1.4-0.1, 'Ⅱ')
plt.text(sum(x)/len(x)-2+0.1, -1.55+0.1, 'Ⅲ')
plt.text(sum(x)/len(x)+2-0.2, -1.55+0.1, 'Ⅳ')

plt.show()

node degree graph

The sum of the row and column of each factor in the accessibility matrix is ​​called the node degree of the factor, and the node degrees corresponding to each threshold are arranged from large to small, and the node degrees of the anxiety formation factors of college students under different thresholds can be obtained Decay scatterplot.
In order to obtain the reachable matrix, it is necessary to introduce the threshold value to eliminate the relationship with less influence, λ \lambdaλ is usually compared by empirical value. Here, the corresponding codes of 0.18, 0.20, 0.24 and 0.27
node degree graph
are as follows:

import matplotlib as mpl
import matplotlib.pyplot as plt

#设置图片格式
config = {
    
    
            "font.family": 'serif',
            "font.size": 14,
            "mathtext.fontset": 'stix',
            "font.serif": ['SimSun'],
            'axes.unicode_minus': False
         }
mpl.rcParams.update(config)

#x轴为递增的整数,y轴分别为不同lambda值时候的节点度,节点度在上文代码中可以算出
x = list(range(1, 11))

y_1 = [13.0, 12.0, 12.0, 11.0, 10.0, 10.0, 9.0, 7.0, 6.0, 2.0]   # lbd = 0.15
y_2 = [12.0, 11.0, 11.0, 8.0, 7.0, 7.0, 6.0, 5.0, 5.0, 2.0]      # lbd = 0.18
y_3 = [11.0, 8.0, 8.0, 7.0, 5.0, 4.0, 4.0, 4.0, 3.0, 2.0]        # lbd = 0.20
y_4 = [8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 3.0, 2.0, 2.0, 2.0]         # lbd = 0.24

#画图
plt.plot(x, y_1, marker='o', linestyle='-', label='λ=0.15', linewidth=1, color='black')
plt.plot(x, y_2, marker='x', linestyle='-', label='λ=0.18', linewidth=1, color='black')
plt.plot(x, y_3, marker='*', linestyle='-', label='λ=0.20', linewidth=1, color='black')
plt.plot(x, y_4, marker='D', linestyle='-', label='λ=0.24', linewidth=1, color='black')

plt.legend()
plt.xlabel("序号")
plt.ylabel("节点度")
plt.show()

ISM diagram

Through the last step, a multi-level hierarchical directed topology diagram between system elements can be made, which will not be shown here. According to the steps, the relationship between them can be obtained immediately and drawn.

postscript

The DEMATEL-ISM model is more of a mutual calculation between matrices, and it is relatively easy to get the result.
It can be used to analyze the relationship between factors and make a step-by-step relationship model diagram, but it also has disadvantages such as strong subjectivity.
Because the author's level is limited, the analysis and code may not be satisfactory, please include more~


  1. Li Guangli, Yan Yizhi, Liu Wenqi, Chen Yaoguang, Wu Zeyu. Research on Forming Factors of Miners’ Insecurity Based on DEMATEL-ISM[J]…Chinese Journal of Safety Science, 2021,31(07):30-37.DOI:10.16265/j. cnki.issn1003-3033.2021.07.005. ↩︎

  2. A python library for MCDA methods. ↩︎

Guess you like

Origin blog.csdn.net/cros1/article/details/128245613