Matlab evaluation model-TOPSIS method (good and bad solution distance method)

Evaluation model-TOPSIS method (distance method for superior and inferior solutions)

1.1 Concept

The TOPSIS method is a commonly used comprehensive evaluation method within a group, which can make full use of the information of the original data, and its results can accurately reflect the gap between the evaluation schemes. The basic process is based on the normalized original data matrix, using the cosine method to find out the optimal plan and the worst plan in the finite plan, and then calculate the distance between each evaluation object and the optimal plan and the worst plan, and obtain the The relative closeness between the evaluation object and the optimal solution is used as the basis for evaluating the advantages and disadvantages. This method has no strict restrictions on data distribution and sample content, and data calculation is simple and easy

1.2 Scope of application

The evaluation object scores, and each index value is known. (Case in the picture below)
insert image description here

The relationship between evaluation individuals and evaluation indicators

Summary of knowledge points

insert image description here

Modeling steps of TOPSIS method

**1. Normalize the original data matrix. That is, all the data corresponding to those extremely small indicators, intermediate indicators, and interval indicators are converted into extremely large indicators, which is convenient for unified calculation and processing.

  1. Normalize the normalized matrix. That is to eliminate the influence of dimension through standardization.
  2. Calculate the distance of each solution from the optimal solution and the worst solution
  3. Calculate the score and sort according to the best solution and the worst solution**
    insert image description here

Normalize the original matrix

insert image description here

very small to very large

insert image description here

Intermediate to very large

insert image description here

Interval to very large

insert image description here

normalization matrix normalization

insert image description here

%% 对正向化后的矩阵进行标准化
%X为正向化矩阵 标准化矩阵Z
Z = X ./ repmat(sum(X.*X) .^ 0.5, n, 1);
disp('标准化矩阵 Z = ')
disp(Z)

Calculate the gap between each evaluation index and the best and worst vectors

insert image description here

The closeness of the evaluation object to the optimal solution

insert image description here

%% 计算与最大值的距离和最小值的距离,并算出得分  标准化矩阵Z
D_P = sum([(Z - repmat(max(Z),n,1)) .^ 2 ],2) .^ 0.5;   % D+ 与最大值的距离向量
D_N = sum([(Z - repmat(min(Z),n,1)) .^ 2 ],2) .^ 0.5;   % D- 与最小值的距离向量
S = D_N ./ (D_P+D_N);    % 未归一化的得分 
disp('最后的得分为:')
stand_S = S / sum(S)    %归一化得分
[sorted_S,index] = sort(stand_S ,'descend')
sort sorting function
% Matlab中给一维向量排序是使用sort函数:sort(A),排序是按升序进行的,其中A为待排序的向量;
% 若欲保留排列前的索引,则可用 [sA,index] = sort(A,'descend')
% 排序后,sA是排序好的向量,index是向量sA中对A的索引。
%   sA  =  8     3     2     1
% index =  4     3     1     2

Topsis and AHP

1. The Topsis method avoids the subjectivity of the data, does not require an objective function, does not need to pass the test, and can well describe the comprehensive influence of multiple impact indicators, and has no strict restrictions on the data distribution, sample size, and number of indicators. It is suitable for small sample data, and is also suitable for large systems with multiple evaluation units and multiple indicators. It is more flexible and convenient. However, the algorithm needs the data of each indicator, and the selection of the corresponding quantitative indicators will be difficult. At the same time, it is not sure how many indicators to select, so that the influence of the indicators can be well described. 2. The
AHP The judgment matrix is ​​obtained through "expert" scoring, which is highly subjective, and n should not be too large.
The index score of the superior and inferior solution distance method is ready-made, and it is also applicable to larger m and n. Compared with the pairwise comparison of AHP, the distance method of superior and inferior solutions is less prone to confusion.

the case

Topic: Evaluate the water quality of the 20 rivers in the table below.
Note: The higher the oxygen content, the better; the closer the pH value is to 7, the better; the less the total number of bacteria, the better; the best plant nutrients are between 10-20 , more
than 20 or less than 10 are not good.
insert image description here

clear;clc
%%  第一步:导入数据data
load data_water_quality.mat

%%  第二步:判断是否需要正向化
[n,m] = size(X);
disp(['共有' num2str(n) '个评价对象, ' num2str(m) '个评价指标']) 
Judge = input(['这' num2str(m) '个指标是否需要经过正向化处理,需要请输入1 ,不需要输入0:  ']);

if Judge == 1
    Position = input('请输入需要正向化处理的指标所在的列,例如第2、3、4三列需要处理,那么你需要输入[2,3,4]: '); %[2,3,4]
    disp('请输入需要处理的这些列的指标类型(1:极小型, 2:中间型, 3:区间型) ')
    Type = input('例如:第2列是极小型,第3列是区间型,第4列是中间型,就输入[1,3,2]:  '); 
    % 注意,Position和Type是两个同维度的行向量
    for i = 1 : size(Position,2)  %这里需要对这些列分别处理,因此我们需要知道一共要处理的次数,即循环的次数
        X(:,Position(i)) = Positivization(X(:,Position(i)),Type(i),Position(i));
    % Positivization是我们自己定义的函数,其作用是进行正向化,其一共接收三个参数
    % 第一个参数是要正向化处理的那一列向量 X(:,Position(i))   回顾上一讲的知识,X(:,n)表示取第n列的全部元素
    % 第二个参数是对应的这一列的指标类型(1:极小型, 2:中间型, 3:区间型)
    % 第三个参数是告诉函数我们正在处理的是原始矩阵中的哪一列
    % 该函数有一个返回值,它返回正向化之后的指标,我们可以将其直接赋值给我们原始要处理的那一列向量
    end
    disp('正向化后的矩阵 X =  ')
    disp(X)
end

%% 第三步:对正向化后的矩阵进行标准化
Z = X ./ repmat(sum(X.*X) .^ 0.5, n, 1);
disp('标准化矩阵 Z = ')
disp(Z)

%% 第四步:计算与最大值的距离和最小值的距离,并算出得分
D_P = sum([(Z - repmat(max(Z),n,1)) .^ 2 ],2) .^ 0.5;   % D+ 与最大值的距离向量
D_N = sum([(Z - repmat(min(Z),n,1)) .^ 2 ],2) .^ 0.5;   % D- 与最小值的距离向量
S = D_N ./ (D_P+D_N);    % 未归一化的得分
disp('最后的得分为:')
stand_S = S / sum(S)
[sorted_S,index] = sort(stand_S ,'descend')


%归一化结果分数  从大到小
sorted_S =
    0.0819
    0.0713
    0.0633
    0.0592
    0.0585
    0.0551
    0.0531
    0.0519
    0.0505
    0.0498
    0.0480
    0.0480
    0.0469
    0.0461
    0.0440
    0.0428
    0.0373
    0.0323
    0.0301
    0.0299

index =
    16
     3
     1
     5
    15
     7
    14
    20
    13
     9
     4
    10
    18
    11
     8
     6
    12
    19
     2
    17

Guess you like

Origin blog.csdn.net/weixin_43599390/article/details/131358040