ahp_weights
mcda.ahp_weights(pairwise_comparison_matrix, raise_on_inconsistency=False)
Analytic Hierarchy Process weights from a pairwise comparison matrix.
AHP is a subjective scheme. Unlike the objective schemes in this module, which read the spread of the score matrix, AHP needs a user-supplied square matrix of pairwise judgments. Entry A[i, j] states how many times more important metric i is than metric j, on Saaty’s 1 to 9 scale. The matrix must be positive and reciprocal, meaning A[j, i] = 1 / A[i, j] and a unit diagonal.
The weights are the principal right eigenvector of the matrix, normalized to sum to 1. The function also returns a consistency ratio that measures how coherent the judgments are. A perfectly consistent matrix gives a ratio of 0. Saaty advises that a ratio above 0.1 means the judgments should be revised.
Algorithm:
- Compute the eigenvalues and right eigenvectors of the matrix.
- Take the eigenvector belonging to the largest real eigenvalue
lambda_max, drop any tiny imaginary part, take the absolute value so the weights are positive, and normalize it to sum to 1. - Compute the consistency index
CI = (lambda_max - n) / (n - 1). - Compute the consistency ratio
CR = CI / RI, whereRIis Saaty’s random index for order n. For n of 1 or 2 the matrix is always consistent and the ratio is defined as 0.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
pairwise_comparison_matrix |
np.ndarray | Shape (n, n), positive and reciprocal, with a unit diagonal. |
required |
raise_on_inconsistency |
bool | If True, raise InconsistentPairwiseMatrixError when the consistency ratio exceeds 0.1. If False (the default), return the ratio so the caller can decide, and emit a warning. |
False |
Returns
| Type | Description |
|---|---|
| tuple of (np.ndarray, float) | The weight vector of shape (n,) summing to 1, and the consistency ratio. |
Raises
| Type | Description |
|---|---|
| ValueError | If the matrix is not square, not strictly positive, or not reciprocal. |
| InconsistentPairwiseMatrixError | If raise_on_inconsistency is True and the consistency ratio exceeds 0.1. |
Notes
Emits a UserWarning if raise_on_inconsistency is False and the consistency ratio exceeds 0.1.
References
Saaty, T. L. The Analytic Hierarchy Process. McGraw-Hill (1980).