topsis灵敏度分析代码
时间: 2024-02-06 21:07:54 浏览: 100
Topsis(Technique for Order of Preference by Similarity to Ideal Solution)是一种多属性决策分析方法,用于评估和排序一组候选方案。灵敏度分析是在Topsis方法中的一种技术,用于评估输入数据的变化对最终结果的影响程度。
以下是一个简单的Topsis灵敏度分析的代码示例:
```python
import numpy as np
def topsis_sensitivity_analysis(data, weights):
# Step 1: Normalize the data
normalized_data = data / np.sqrt(np.sum(data**2, axis=0))
# Step 2: Calculate the weighted normalized decision matrix
weighted_normalized_data = normalized_data * weights
# Step 3: Calculate the ideal and negative-ideal solutions
ideal_solution = np.max(weighted_normalized_data, axis=0)
negative_ideal_solution = np.min(weighted_normalized_data, axis=0)
# Step 4: Calculate the Euclidean distances to the ideal and negative-ideal solutions
distance_to_ideal = np.sqrt(np.sum((weighted_normalized_data - ideal_solution)**2, axis=1))
distance_to_negative_ideal = np.sqrt(np.sum((weighted_normalized_data - negative_ideal_solution)**2, axis=1))
# Step 5: Calculate the relative closeness to the ideal solution
relative_closeness = distance_to_negative_ideal / (distance_to_ideal + distance_to_negative_ideal)
return relative_closeness
# Example usage
data = np.array([[3, 4, 5], [2, 6, 8], [5, 7, 9], [1, 3, 2]])
weights = np.array([0.4, 0.3, 0.3])
sensitivity_analysis_result = topsis_sensitivity_analysis(data, weights)
print(sensitivity_analysis_result)
```
这段代码实现了Topsis灵敏度分析的基本步骤。首先,输入数据被归一化处理,然后根据权重计算加权归一化决策矩阵。接下来,计算理想解和负理想解,并计算每个方案到理想解和负理想解的欧氏距离。最后,根据欧氏距离计算相对接近度。
阅读全文