Skip to content

Multi-criteria ranking (quakecascade.mcda)

What it computes

topsis ranks alternatives (districts, grid cells, candidate sites) by the Technique for Order Preference by Similarity to Ideal Solution (Hwang & Yoon 1981). For a decision matrix \(x_{ij}\) (alternative \(i\), criterion \(j\)):

  1. Vector normalisation: \(r_{ij} = x_{ij} \big/ \sqrt{\sum_k x_{kj}^2}\).
  2. Weighting: \(v_{ij} = w_j\, r_{ij}\), with \(\sum_j w_j = 1\).
  3. Ideal and anti-ideal: for a benefit criterion \(A^+_j = \max_i v_{ij}\), \(A^-_j = \min_i v_{ij}\); for a cost criterion the other way round.
  4. Separations: \(S^+_i = \lVert v_i - A^+ \rVert_2\), \(S^-_i = \lVert v_i - A^- \rVert_2\).
  5. Relative closeness:
\[ C_i = \frac{S^-_i}{S^+_i + S^-_i} \in [0, 1], \]

ranked in descending order (rank 1 = closest to the ideal). Ties share the lower rank.

Incomplete rows

An alternative with any missing criterion (NaN or ±inf) is left out of the ranking: it gets score = NaN, rank = <NA> and a status, and it does not enter the normalisation or the ideal points of the others (its presence does not move their scores; tested). Missing values are never filled with a neutral value.

topsis_status Meaning
computed all criteria present, ranked
no_<criterion> exactly that criterion is missing
no_criteria two or more criteria are missing

result.attrs holds n_ranked, n_unranked and the normalised weights.

Parameters

Parameter Default Note
weights equal (\(1/m\)) sequence, or mapping / pandas Series keyed by criterion name; normalised to sum 1; must be non-negative
benefit required True where higher is better, per criterion (sequence, mapping / Series by name, or one bool for all). Only booleans (or 0/1): a label such as "cost" raises instead of counting as True. The direction is a property of each indicator and is never assumed
criteria c0.. names for array input

When every ranked alternative is identical on every criterion, \(S^+ = S^- = 0\) and all scores are set to 0.5 (a full tie).

Caveats

  • TOPSIS scores are relative to the set being ranked: adding or removing an alternative can change the others' scores (rank reversal).
  • Weights express priorities; report the weights used and, where they are contested, a sensitivity run.
  • Criteria on very different scales are handled by the vector normalisation, but strongly skewed indicators dominate \(A^\pm\).

Example

import numpy as np
import pandas as pd
from quakecascade import mcda

indicators = pd.DataFrame({"hazard": [1.0, 2.0, 3.0, np.nan],
                           "exposure": [2.0, 1.0, 3.0, 1.0]}, index=list("abcd"))
rank = mcda.topsis(indicators, benefit={"hazard": True, "exposure": True})
print(rank[["score", "rank", "topsis_status"]].round(3))
print(rank.attrs["n_unranked"])        # 1

Provenance

Re-implemented from the method used by the DİRİ ranking engine (equal default weights, records with a missing index left unranked and counted), written against arrays and DataFrames with explicit benefit/cost directions.

References

  • Hwang, C.-L., & Yoon, K. (1981). Multiple Attribute Decision Making: Methods and Applications. Lecture Notes in Economics and Mathematical Systems 186. Springer, Berlin. doi:10.1007/978-3-642-48318-9