Create an object which will rate characteristic objects (CO) using
compromise of several preferences. If the CO is better in most of the
preferences, than it is bigger in the final MEJ.
Parameters:
evaluation_functions (list[Callable]) – List of functions which will evaluate preferences of the
characteristic objets. If you want to use MCDA methods, please
use lambda or partial to provide weights and types to them.
vote_limit (float) – Vote limit decides the limit for the voting. If number of votes
CO_i > CO_j are bigger then vote_limit, then in the final MEJ
matrix CO_i > CO_j, otherwise CO_i < CO_j.
Create an object which will rate characteristic objects using Expected
Solution Points (ESPs) provided by an expert to rate the characteristic
objects.
Parameters:
esps (ndarray) – Numpy 2d matrix which defines chosed Expected Solution Points.
Each row should define one ESP, number of the colums should be
equal to the number of criteria.
bounds (ndarray) – Each row should contain min and max values for each criterion.
Min and max should be different values!
distance_function (Callable or None) – Function which will be used to calculate the distance between
two numpy array a and b. Signature of the function is d(a, b).
If None, ESPExpert._euclides function is used and the Euclides
distance is calculated between vectors.
distance_aggregation (Callable) – Function which is used to aggregate distances to several ESP
for each characteristic object. Default is np.min().
cvalues_psi (float or None) – Float in range (0, 1). This value determines location of the
additional ESP-guided characteristic values. E.g. criteria
domain bounds are [0, 10] and ESP is 3. Then if we chose
psi = 0.2 we will get following characteristic values for
such criterion: [0, 2.4, 3, 4.4, 10] (the psi part of the
distance between bound and ESP is substracted and added).
full_domain_psi (bool) – Determines if additional characteristic values will be
generated using full domain (True) or distance between ESP
and bounds (False). E.g. if full_domain_psi=True, criteria
domain bounds are [0, 10] and ESP is 3. If we chose
psi = 0.2 we will get following characteristic values for
such criterion: [0, 1, 3, 5, 10] (the psi part of the
distance between all domain is substracted and added).
Examples
>>> importnumpyasnp>>> importmatplotlib.pyplotasplt>>> importpymcdmaspm>>> # Define criteria bounds for the decision problem>>> bounds=np.array([[0,1]]*2,dtype=float)>>> # Define the Expected Solution Point (or Points) for this problem>>> esps=np.array([[0.4,0.4]])>>> # Create the expert function using ESPExpert class>>> expert=pm.methods.comet_tools.ESPExpert(esps,... bounds,... cvalues_psi=0.2)>>> # Generate ESP-guided cvalues based on provided ESP and psi>>> cvalues=expert.make_cvalues()>>> # Create and identify COMET model>>> comet=pm.methods.COMET(cvalues,expert)>>> # Create a visualization of the characteriscic values,>>> # ESP and preference function>>> fig,ax=plt.subplots(figsize=(4,3.5),dpi=200)>>> ax,cax=pm.visuals.comet_2d_esp_plot(comet,esps,bounds)>>> plt.tight_layout()>>> plt.show()
Generate the characteristic values array based on provided
ESPs and psi values. Usually using COMET with such cvalues will
provide better results, however it is not mandatory.
Returns:
cvalues – Characteristic values created based on ESPs and psi.
Create an object which will rate characteristic objects using expert function.
Parameters:
expert_function (Callable) – Function with a signature (co_i, co_j) -> float.
If co_i < co_j this function should return 0.0.
If co_i == co_j this function should return 0.5.
If co_i > co_j this function should return 1.0.
Create object of the ManualExpert expert function which allows to
manually identify Matrix of Expert Judgements (MEJ).
Parameters:
criteria_names (list[str]) – Criteria names which would be used during the procedure of the
MEJ identification.
show_MEJ (bool) – If MEJ should be shown after each question answered.
Default is False.
tablefmt (str) – tablefmt argument for the tablulate function. See tabulate
documentation for more info.
Default is ‘simple_grid’.
filename (str or None) – Path to the file in which identified save should be saved.
If None, MEJ will be not saved. If file exists, MEJ will be
loaded from this file. Default is ‘mej.csv’.
Examples
>>> importnumpyasnp>>> frompymcdm.methodsimportCOMET>>> frompymcdm.methods.comet_toolsimportManualExpert>>> cvalues=[... [0,500,1000],... [1,5]... ]>>> expert_function=ManualExpert(... criteria_names=['Price [$]','Profit [grade]'],... show_MEJ=True... )>>> # You will prompted to evaluate all CO>>> comet=COMET(cvalues,expert_function)
Create object of the COMET submodel. This class is mostly for internal
use in the StructuralCOMET class or for creating StructuralCOMET
object.
Parameters:
structure (tuple or int) – Structure of the submodel. Refer to the single criteria by
names (str) or by indexes (int). If structure is more complex
use defined names or nested structures. See example use of
StructuralCOMET for more infomation.
cvalues (list or None) – Cvalues for output of this submodel. Pass None if it is a final
model to be evaluated.
expert_function (Callable or None) – Expert function to evaluate characteristic objects in
the submodel. See COMET documentation for more information.
None is reserved for internal use in StructuralCOMET class.
name (str or None) – Name (alias) of the Submodel. If name is not None Submodel
could be reffered by it in another Submodel in one
StructuralCOMET model.
Create object of the TriadSupportExpert expert function which allows
to manually identify Matrix of Expert Judgements (MEJ), but with the
support of the consistent triads.
Parameters:
criteria_names (list[str]) – Criteria names which would be used during the procedure of the
MEJ identification.
show_MEJ (bool) – If MEJ should be shown after each question answered.
Default is False.
tablefmt (str) – tablefmt argument for the tablulate function. See tabulate
documentation for more info.
Default is ‘simple_grid’.
filename (str or None) – Path to the file in which identified save should be saved.
If None, MEJ will be not saved. If file exists, MEJ will be
loaded from this file. Default is ‘mej.csv’.
Examples
>>> importnumpyasnp>>> frompymcdm.methodsimportCOMET>>> frompymcdm.methods.comet_toolsimportTriadSupportExpert>>> cvalues=[... [0,500,1000],... [1,5]... ]>>> expert_function=TriadSupportExpert(... criteria_names=['Price [$]','Profit [grade]'],... show_MEJ=True... )>>> # You will prompted to evaluate some of the CO and>>> # other CO will be completed using consistent triads.>>> comet=COMET(cvalues,expert_function)
Calculates local weights for alternative alt for each criterion
using the algorithm presented in [1].
References
[1] Więckowski, J., Kizielewicz, B., Paradowski, B., Shekhovtsov, A., & Sałabun, W. (2023). Application of Multi-Criteria Decision Analysis to Identify Global and Local Importance Weights of Decision Criteria. International Journal of Information Technology & Decision Making, 22(06), 1867–1892. https://doi.org/10.1142/S0219622022500948
[2] Shekhovtsov, A. and Sałabun, W. (2024). Comparing Global and Local Weights in Multi-Criteria Decision-Making: A COMET-Based Approach. In Proceedings of the 16th International Conference on Agents and Artificial Intelligence - Volume 3: ICAART; ISBN 978-989-758-680-4; ISSN 2184-433X, SciTePress, pages 470-477. DOI: 10.5220/0012360700003636
Calculate drastic WS distance between the ranking vectors.
Rankings should be presented as indices, i.e. for the ranking
A2 > A1 > A3 the ranking vector should be [2, 1, 3].
Creates a correlation matrix for given vectors from the numpy array.
Parameters:
rankings (ndarray) – Vectors for which the correlation matrix is to be calculated.
method (callable) – Function to calculate the correlation matrix.
columns (bool) – If the column value is set to true then the correlation matrix will be calculated for the columns.
Otherwise the matrix will be calculated for the rows.
Function which implements the procedure similar to leave one out cross
validation. This function calculates N rankings from N decision
matrices created by removing one of N alternatives from original one.
This function returns the array of rankings build in following way:
[original_ranking, w/o A1, w/o A2, …, w/o AN, original_ranking].
This function will insert in the ranking value 0 instead of removed
alternative position. E.g. original ranking is [1, 2, 3, 4], ranking
without A1 will looks like [0, 1, 2, 3].
This function main purpose is to prepare data for rankings_flow
visualization function.
Parameters:
method (MCDA_method) – MCDA method which should be used to calculate rankings.
matrix (ndarray) – Decision matrix / alternatives data.
Alternatives are in rows and Criteria are in columns.
weights (ndarray) – Criteria weights. Sum of the weights should be 1. (e.g. sum(weights) == 1)
types (ndarray) – Array with definitions of criteria types:
1 if criteria is profit and -1 if criteria is cost for each criteria in matrix.
corr_function (Callable) – Correlation function to calculate correlation value between
rankings.
ideal_corr_value (float) – Correlation value for ideal ranking. Default is 1. Use it if
correlation function you use has different value for two same
rankings (e.g. 0).
only_rr (bool) – Include in returned collections only rankings in which
rank reversal occurs. If rank reversal do not occured the list
of two original rankings will be returned. Default is True.
Returns:
rankings (ndarray) – Matrix of rankings obtained when removing different
alternatives. Instead of removed alternatives 0 is placed.
correlations (list) – List of correlation values calculated for rankings in
rankings matrix.
labels (list) – Names of the created rankings. It will looks like [‘None’,
‘w/o A_1’, ‘w/o A_2’, … ‘None’], where ‘w/o A_i’ means that
this ranking was build without alternative A_i.
Normalize each column in matrix, using method`normalization
function according to `criteria_types.
Parameters:
matrix (ndarray) – Decision matrix representation.
The rows are considered as alternatives and the columns are considered as criteria.
method (Callable or Iterable[Callable]) – Function or Functions which should be used to normalize matrix columns.
Functions should match signature foo(x, cost), where x is
a vector which would be normalized and cost is a bool variable
which says if x is a cost or profit criteria. In case of providing
list or tuple of the functions, number of functions should be
the same as number of criteria in matrix (columns) and same as
the lenght of the criteria_types.
criteria_types (None or Iterable) – Describes criteria types.
1 if criteria is profit and -1 if criteria is cost for each criteria in matrix.
If None all criteria are considered as profit
Returns:
Normalized copy of the input matrix.
Return type:
ndarray
Raises:
ValueError – If criteria_types and matrix has different number of criteria.
Ranks begin at 1. Tied elements get average rank (see Examples below).
Ranking starts from smaller values, e.g. the smaller element get
the first position. The reverse argument reverse posisions, e.g.
the largest element get first position.
Parameters:
a (iterable) – The array of values to be ranked.
reverse (bool, optional) – If True, larger elements get first posisions in ranking.
If False, smaller elements get first positions in ranking.