随机 topsis 法
时间: 2023-08-06 08:15:34 浏览: 51
随机Topsis法是一种多属性决策分析方法,用于确定各决策方案的优劣程度。它基于TOPSIS方法,通过计算各方案到理想解和负理想解的距离,从而评估各方案的优劣程度。与传统的TOPSIS方法不同,随机Topsis法考虑了不确定性因素,通过随机生成多组权重向量,得出各方案的不确定性程度。
其步骤如下:
1. 确定决策方案及其指标。
2. 对各指标进行归一化处理。
3. 随机生成多组权重向量。
4. 计算各方案到理想解和负理想解的距离。
5. 根据距离计算各方案的不确定性程度。
以下是使用Python实现随机Topsis法的示例代码:
```python
import numpy as np
# 构建决策矩阵,这里以三个决策方案为例,每个方案有三个指标
decision_matrix = np.array([
[10, 15, 20],
[5, 10, 15],
[20, 25, 30]
])
# 归一化决策矩阵
normalized_matrix = np.zeros_like(decision_matrix)
for i in range(decision_matrix.shape[0]):
sum_of_row = np.sum(decision_matrix[i])
for j in range(decision_matrix.shape[1]):
normalized_matrix[i][j] = decision_matrix[i][j] / sum_of_row
# 随机生成多组权重向量
num_of_weights = 5
weight_vectors = np.random.rand(num_of_weights, normalized_matrix.shape[1])
weight_vectors = weight_vectors / np.sum(weight_vectors, axis=1)[:, np.newaxis]
# 计算各方案到理想解和负理想解的距离
ideal_solution = np.max(normalized_matrix, axis=0)
negative_ideal_solution = np.min(normalized_matrix, axis=0)
distance_to_ideal = np.sqrt(np.sum((normalized_matrix - ideal_solution) ** 2, axis=1))
distance_to_negative_ideal = np.sqrt(np.sum((normalized_matrix - negative_ideal_solution) ** 2, axis=1))
# 计算各方案的不确定性程度
uncertainty = distance_to_negative_ideal / (distance_to_ideal + distance_to_negative_ideal)
print("决策方案的不确定性程度为:", uncertainty)
```
这段代码中,首先构建了一个决策矩阵`decision_matrix`,然后对其进行归一化,得到`normalized_matrix`。
接着,使用`np.random.rand`函数随机生成多组权重向量`weight_vectors`,然后对其进行归一化。
接下来,计算出理想解`ideal_solution`和负理想解`negative_ideal_solution`,并计算各方案到其的距离`distance_to_ideal`和`distance_to_negative_ideal`。
最后,通过`distance_to_negative_ideal`和`distance_to_ideal`计算各方案的不确定性程度向量`uncertainty`即可。