A subclass of PairwiseWeightsBase implementing the AHP (Analytic Hierarchy Process) method [1].
RI values for determination of the consistency are taken from [2].
The AHP class computes weights for pairwise comparisons based on rankings or user-provided
input.
Parameters:
ranking (np.ndarray | list | tuple, optional) – Array representing the ranking of objects. Only one of ranking, scoring,
object_names, matrix, or filename must be provided.
scoring (np.ndarray | list | tuple, optional) – Array representing the scoring of objects.
object_names (list of str, optional) – List of names corresponding to the objects being compared. This triggers
manual pairwise comparison.
filename (str, optional) – Path to a CSV file containing a pairwise comparison matrix.
Examples
>>> frompymcdm.weights.subjectiveimportAHP>>> ahp=AHP(ranking=[1,2,4,3])# Identify weights for four criteria based on ranking>>> weights=ahp()[0.48144852 0.21998235 0.13073309 0.16783605]>>> ahp=AHP(object_names=['Price','Mileage','HP','Year'])# Identify weights based on manual comparisons>>> weights=ahp()>>> print(weights)[0.52407767 0.26268171 0.03742414 0.17581648]>>> print(ahp.get_cr())# To calculate CR use get_cr() method0.5021601824872032
Compares two objects based on their ranking values.
This function takes into account differences between values in the ranking/scoring.
If one criterion A has value 9 and criterion B 1 it means that B is nine times better than A.
Therefore result of the comparison will be A and B will be 1/9.
In case of A (1) and B (9) the result will be 9, because B is nine times worse than A.
The differences are limited to 9, to fit in the AHP dictionary.
Parameters:
i (int) – Index of the first object in the ranking.
j (int) – Index of the second object in the ranking.
Calculate Consistency Ratio (CR) coefficient based on the created pairwise comparison matrix
and return True if calculated CR is lower than cr_threshold parameter (default is 0.1), or False if bigger,
indicating if the created matrix should be considered consistent.
Parameters:
cr_threshold (float, optional) – CR threshold which determines if matrix with given CR is consistent (calculated CR is lower than threshold)
or not (calculated CR is larger than threshold). Default is 0.1.
Raises:
ValueError – If matrix is not existed (model is not identified) or if matrix is too big.
A subclass of PairwiseWeightsBase implementing the RANCOM (RANking COMparison) method [3].
The RANCOM class computes weights for pairwise comparisons based on rankings or user-provided
input.
Parameters:
ranking (np.ndarray | list | tuple, optional) – Array representing the ranking of objects. Only one of ranking, scoring,
object_names, matrix, or filename must be provided.
scoring (np.ndarray | list | tuple, optional) – Array representing the scoring of objects.
object_names (list of str, optional) – List of names corresponding to the objects being compared. This triggers
manual pairwise comparison.
filename (str, optional) – Path to a CSV file containing a pairwise comparison matrix.
Examples
>>> frompymcdm.weights.subjectiveimportRANCOM>>> rancom=RANCOM(ranking=[1,2,4,3])# Identify weights for four criteria based on ranking>>> weights=rancom()[0.4375 0.3125 0.0625 0.1875]>>> rancom=RANCOM(object_names=['Price','Mileage','HP','Year'])# Identify weights based on manual comparisons>>> weights=rancom()[0.4375 0.3125 0.0625 0.1875]
Compares two objects based on their ranking values.
In the ranking, smaller values represent better options. The comparison returns:
- 1 if the first object is ranked better than the second.
- 0 if the second object is ranked better than the first.
- 0.5 if the two objects are equally ranked.
Parameters:
i (int) – Index of the first object in the ranking.
j (int) – Index of the second object in the ranking.
Generates a question string for comparing two objects.
The question prompts the user to compare the importance of two objects and choose one of
the following options:
- 1: The first object is more important than the second.
- 1/2: The two objects are equally important.
- 0: The second object is more important than the first.
Parameters:
a (str) – The name of the first object.
b (str) – The name of the second object.
Returns:
A formatted question string prompting the user to compare the two objects.
A base class for managing pairwise comparison weighting methods using different input formats.
This abstract base class supports the initialization, validation, and processing of
pairwise comparison data using one of several input options: ranking, scoring, object names,
pairwise comparison matrices, or a file. It is designed for extension in derived classes,
which must override its abstract methods.
Parameters:
ranking (np.ndarray | list | tuple, optional) – Array representing the ranking of objects. Only one of ranking, scoring,
object_names, matrix, or filename must be provided.
scoring (np.ndarray | list | tuple, optional) – Array representing the scoring of objects.
object_names (list of str, optional) – List of names corresponding to the objects being compared. This triggers
manual pairwise comparison.
Return weights if already calculated, or calculate them based on matrix (if matrix is present).
If there are no matrix available, it will be calculated based on provided input and then weights will
be calculated and returned.
Constructs a pairwise comparison matrix using a list of objects and a comparison function.
Comparing function is either _compare_pariwise() or _compare_ranking(). This function
will be applied to objects from objects.
Parameters:
objects (list) – A list of objects to compare.
comparison_func (Callable) – A function to perform pairwise comparisons between objects.