TOPSIS¶
topsis
¶
TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) implementation.
TOPSIS is a multi-criteria decision making (MCDA) method that ranks alternatives based on their distance to the ideal solution and distance from the anti-ideal solution.
Classes¶
Functions¶
topsis
¶
topsis(objectives: ndarray | DataFrame, weights: ndarray | list[float] | None = None, directions: ndarray | list[str] | list[OptimizationDirection] | None = None, normalize_method: str = 'vector', return_details: bool = False) -> ndarray | dict
Apply TOPSIS method to rank solutions.
TOPSIS ranks alternatives by calculating: 1. Distance to ideal solution (best values for each objective) 2. Distance to anti-ideal solution (worst values for each objective) 3. Closeness coefficient: distance_negative / (distance_positive + distance_negative)
Higher closeness coefficient = better solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objectives
|
ndarray | DataFrame
|
Array or DataFrame of objective values (n_solutions, n_objectives) |
required |
weights
|
ndarray | list[float] | None
|
Weights for each objective (must sum to 1). If None, equal weights |
None
|
directions
|
ndarray | list[str] | list[OptimizationDirection] | None
|
Optimization direction for each objective ('min' or 'max') If None, assumes all minimization |
None
|
normalize_method
|
str
|
Normalization method ('vector' or 'minmax') |
'vector'
|
return_details
|
bool
|
If True, return detailed results including distances |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | dict
|
If return_details=False: Array of closeness coefficients (scores) |
ndarray | dict
|
If return_details=True: Dictionary with scores, ranks, and intermediate values |
Source code in optiscope/analysis/topsis.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
topsis_from_result
¶
topsis_from_result(result: OptimizationResult, weights: dict[str, float] | None = None, subset_name: str | None = None, return_details: bool = False) -> ndarray | dict
Apply TOPSIS to OptimizationResult using metadata.
Automatically extracts optimization directions from metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
OptimizationResult
|
OptimizationResult object |
required |
weights
|
dict[str, float] | None
|
Dictionary mapping objective names to weights |
None
|
subset_name
|
str | None
|
Name of result set to analyze (if None, use all points) |
None
|
return_details
|
bool
|
Return detailed results |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | dict
|
TOPSIS scores or detailed results |
Source code in optiscope/analysis/topsis.py
interactive_topsis
¶
interactive_topsis(objectives: ndarray | DataFrame, initial_weights: ndarray | None = None, directions: ndarray | None = None, n_top: int = 10) -> dict
Prepare data for interactive TOPSIS weight adjustment.
Returns results structure that can be used with interactive widgets to adjust weights and see real-time ranking changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objectives
|
ndarray | DataFrame
|
Objective values |
required |
initial_weights
|
ndarray | None
|
Initial weights |
None
|
directions
|
ndarray | None
|
Optimization directions |
None
|
n_top
|
int
|
Number of top solutions to track |
10
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with initial results and data for interactive updates |
Source code in optiscope/analysis/topsis.py
sensitivity_analysis_topsis
¶
sensitivity_analysis_topsis(objectives: ndarray | DataFrame, base_weights: ndarray, directions: ndarray | None = None, perturbation: float = 0.1, n_samples: int = 100) -> dict
Perform sensitivity analysis on TOPSIS results.
Varies weights around base values to see how rankings change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objectives
|
ndarray | DataFrame
|
Objective values |
required |
base_weights
|
ndarray
|
Base weight vector |
required |
directions
|
ndarray | None
|
Optimization directions |
None
|
perturbation
|
float
|
Maximum perturbation as fraction (0.1 = ±10%) |
0.1
|
n_samples
|
int
|
Number of random weight samples to test |
100
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with sensitivity analysis results |
Source code in optiscope/analysis/topsis.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
compare_weight_scenarios
¶
compare_weight_scenarios(objectives: ndarray | DataFrame, weight_scenarios: dict[str, ndarray], directions: ndarray | None = None) -> DataFrame
Compare TOPSIS results across different weight scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objectives
|
ndarray | DataFrame
|
Objective values |
required |
weight_scenarios
|
dict[str, ndarray]
|
Dictionary mapping scenario names to weight vectors |
required |
directions
|
ndarray | None
|
Optimization directions |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame comparing top solutions across scenarios |