Usage
Installation
To use evo-spotis, first install it using the pip command, as demonstrated below.
pip install evo-spotis
Usage examples
The SPOTIS method
The SPOTIS method is used to calculate the preference of evaluated alternatives. The SPOTIS method requires providing the decision matrix
matrix, vector with criteria weights weights, and vector with criteria types types and minimum and maximum bounds of alternatives performance
values for particular criteria. The SPOTIS method returns a vector with preference values pref. To generate the SPOTIS ranking of alternatives,
pref has to be sorted in ascending order. The ranking is generated by rank_preferences, providing pref as argument and setting parameter
reverse as False because we need to sort preferences ascendingly.
import numpy as np
from evo_spotis.mcda_methods import SPOTIS
from evo_spotis.additions import rank_preferences
# provide decision matrix in array numpy.darray
matrix = np.array([[15000, 4.3, 99, 42, 737],
[15290, 5.0, 116, 42, 892],
[15350, 5.0, 114, 45, 952],
[15490, 5.3, 123, 45, 1120]])
# provide criteria weights in array numpy.darray. All weights must sum to 1.
weights = np.array([0.2941, 0.2353, 0.2353, 0.0588, 0.1765])
# provide criteria types in array numpy.darray. Profit criteria are represented by 1 and cost criteria by -1.
types = np.array([-1, -1, -1, 1, 1])
# Determine minimum bounds of performance values for each criterion in decision matrix
bounds_min = np.array([14000, 3, 80, 35, 650])
# Determine maximum bounds of performance values for each criterion in decision matrix
bounds_max = np.array([16000, 8, 140, 60, 1300])
# Stack minimum and maximum bounds vertically using vstack. You will get a matrix that has two rows and a number of columns equal to the number of criteria
bounds = np.vstack((bounds_min, bounds_max))
# Create the SPOTIS method object
spotis = SPOTIS()
# Calculate the SPOTIS preference values of alternatives
pref = spotis(matrix, weights, types, bounds)
# Generate ranking of alternatives by sorting alternatives ascendingly according to the SPOTIS algorithm (reverse = False means sorting in ascending order) according to preference values
rank = rank_preferences(pref, reverse = False)
print('Preference values: ', np.round(pref, 4))
print('Ranking: ', rank)
Output
Preference values: [0.478 0.5781 0.5557 0.5801]
Ranking: [1 3 2 4]
Stochastic algorithm
The Differential Evolution algorithm DE_algorithm for criteria weights prediction
import numpy as np
from evo_spotis.stochastic_algorithms import DE_algorithm
# Create object of the DE_algorithm
de_algorithm = DE_algorithm()
# run DE algorithm providing decision matrix with training dataset `X_train`, target variable of training dataset `y_train` (ranking), criteria types `types` and `bounds` for the SPOTIS method
# de_algorithm returns `BestSolution` representing predicted criteria weights and the best `BestFitness` and mean `MeanFitness` goal (fitness) fucntion values
BestSolution, BestFitness, MeanFitness = de_algorithm(X_train, y_train, types, bounds)
Correlation coefficents
Spearman correlation coefficient
This method is used to calculate correlation between two different rankings. It requires two vectors R and Q with rankings of the same size. It returns value
of correlation.
import numpy as np
from evo_spotis import correlations as corrs
# Provide two vectors with rankings obtained with different MCDA methods
R = np.array([1, 2, 3, 4, 5])
Q = np.array([1, 3, 2, 4, 5])
# Calculate the correlation using `spearman` coefficient
coeff = corrs.spearman(R, Q)
print('Spearman coeff: ', np.round(coeff, 4))
Output
Spearman coeff: 0.9
Weighted Spearman correlation coefficient
This method is used to calculate correlation between two different rankings. It requires two vectors R and Q with rankings of the same size. It returns value
of correlation.
import numpy as np
from evo_spotis import correlations as corrs
# Provide two vectors with rankings obtained with different MCDA methods
R = np.array([1, 2, 3, 4, 5])
Q = np.array([1, 3, 2, 4, 5])
# Calculate the correlation using `weighted_spearman` coefficient
coeff = corrs.weighted_spearman(R, Q)
print('Weighted Spearman coeff: ', np.round(coeff, 4))
Output
Weighted Spearman coeff: 0.8833
Pearson correlation coefficient
This method is used to calculate correlation between two different rankings. It requires two vectors R and Q with rankings of the same size. It returns value
of correlation.
import numpy as np
from evo_spotis import correlations as corrs
# Provide two vectors with rankings obtained with different MCDA methods
R = np.array([1, 2, 3, 4, 5])
Q = np.array([1, 3, 2, 4, 5])
# Calculate the correlation using `pearson_coeff` coefficient
coeff = corrs.pearson_coeff(R, Q)
print('Pearson coeff: ', np.round(coeff, 4))
Output
Pearson coeff: 0.9
Objective method for criteria weights determination
Entropy weighting method
This method is used to calculate criteria weights based on alternatives perfromance values provided in decision matrix. This method requires
providing two-dimensional decision matrix matrix with perfromance values of alternatives in rows considering criteria in columns. It returns
vector with criteria weights. All values in vector weights must sum to 1.
import numpy as np
from evo_spotis import weighting_methods as mcda_weights
matrix = np.array([[30, 30, 38, 29],
[19, 54, 86, 29],
[19, 15, 85, 28.9],
[68, 70, 60, 29]])
weights = mcda_weights.entropy_weighting(matrix)
print('Entropy weights: ', np.round(weights, 4))
Output
Entropy weights: [0.463 0.3992 0.1378 0. ]
Methods for decision matrix normalization
Here is an example of vector normalization usage. Other normalizations provided in module normalizations, namely minmax_normalization, max_normalization,
sum_normalization, linear_normalization, multimoora_normalization are used in analogous way.
Vector normalization
This method is used to normalize decision matrix matrix. It requires providing decision matrix matrix with performance values of alternatives in rows
considering criteria in columns and vector with criteria types types. This method returns normalized matrix.
import numpy as np
from evo_spotis import normalizations as norms
matrix = np.array([[8, 7, 2, 1],
[5, 3, 7, 5],
[7, 5, 6, 4],
[9, 9, 7, 3],
[11, 10, 3, 7],
[6, 9, 5, 4]])
types = np.array([1, 1, 1, 1])
norm_matrix = norms.vector_normalization(matrix, types)
print('Normalized matrix: ', np.round(norm_matrix, 4))
Output
Normalized matrix: [[0.4126 0.3769 0.1525 0.0928]
[0.2579 0.1615 0.5337 0.4642]
[0.361 0.2692 0.4575 0.3714]
[0.4641 0.4845 0.5337 0.2785]
[0.5673 0.5384 0.2287 0.6499]
[0.3094 0.4845 0.3812 0.3714]]