pymcdm_reidentify.methods package

pymcdm_reidentify.methods.sesp

class pymcdm_reidentify.methods.sesp.SESP(method, base, types, weights=None)

Bases: StochasticIdentification

Stochastic Expected Solution Point (SESP) approach.

SESP is an approach for the re-identification of MCDA/MCDM models based on a reference point called the Expected Solution Point. This approach was presented alongside the SPOTIS method in [1].

References

Examples

>>> import numpy as np
>>> from mealpy.swarm_based.PSO import OriginalPSO
>>> from pymcdm.methods import SPOTIS
>>> from pymcdm_reidentify.methods import SESP
>>> matrix = np.random.random((1000, 2))
>>> types = np.array([-1, 1])
>>> weights = np.array([0.5, 0.5])
>>> bounds = np.array([[0, 1],
...                    [0, 1]])
>>> esp = np.array([0.5, 0.5]) # Unknown expert expected solution point
>>> spotis = SPOTIS(bounds, esp)
>>> preference = spotis(matrix, weights, types)
>>> rank = spotis.rank(preference)
>>> stoch = OriginalPSO(epoch=1000, pop_size=100)
>>> model = SESP(stoch.solve, SPOTIS(bounds), types)
>>> model.fit(matrix, rank, log_to=None)
__call__(*args, **kwargs)

Method that returns the identified Expected Solution Point (ESP).

Returns:

The identified ESP.

Return type:

ndarray

__init__(method, base, types, weights=None)

Create SESP method object.

Parameters:
  • method (callable) – A function used for optimization to find the best ESP. It should include ‘bounds’, which denote the search boundaries for the point; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the ESP selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of criteria in the decision-making problem.

  • base (object) – An object representing the MCDA/MCDM method for which the ESP will be found. It should have an ‘esp’ attribute and be callable for evaluating alternatives (in this case, the training set). The callable should function similarly to the ‘SPOTIS’ method from the ‘pymcdm’ library.

  • types (ndarray) – Array defining the criteria types: 1 if the criterion is profit and -1 if the criterion is cost for each criterion in the matrix.

  • weights (ndarray, optional) – Criteria weights. The sum of the weights should be 1 (e.g., sum(weights) == 1). If not provided, the weights are assigned equally in ‘fit’ method.

fit(x_train, y_train, **kwargs_method)

Method for training to find the best Expected Solution Point (ESP) that matches the given ranking.

Parameters:
  • x_train (ndarray) – Decision matrix used for training (searching for) the best ESP. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Ranking of the alternatives contained in ‘x_train’.

  • **kwargs_method – Dictionary of parameter settings for the optimization method ‘self.method’.

fitness(solutions, correlation=<function weighted_spearman>)

Fitness method for finding the Expected Solution Point (ESP).

Parameters:
  • solutions (ndarray) – Matrix representing the ESPs.

  • correlation (callable, optional) – A correlation coefficient function used to compare rankings during the search for the optimal ESP. The default is rw.

Returns:

The correlation value between the reference ranking and the ranking obtained from the base method with the identified ESP.

Return type:

float

pymcdm_reidentify.methods.sfn

class pymcdm_reidentify.methods.sfn.SFN(method, base, weights=None)

Bases: StochasticIdentification

Abstract class for Stochastic Fuzzy Normalization (SFN).

SFN is an approach for the re-identification of MCDA/MCDM models using fuzzy numbers. The main concept involves finding values within the fuzzy numbers, known as cores, while keeping the boundary values of the fuzzy numbers constant.

__call__(*args, **kwargs)

Method that returns a list of fuzzy numbers used for normalizing the decision matrix.

Returns:

A list of fuzzy numbers represented as functions.

Return type:

list[callable]

__init__(method, base, weights=None)

Abstract initialization for SFN class.

Parameters:
  • method (callable) – A function used for optimization to find the best cores. It should include ‘bounds’, which denote the search boundaries for the cores; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the fuzzy normalization selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of criteria in the decision-making problem.

  • base (object) – An object representing the MCDA/MCDM method for which the cores will be found. It should have a ‘normalization’ attribute and be callable for evaluating alternatives (in this case, the training set).

  • weights (ndarray, optional) – Criteria weights. The sum of the weights should be 1 (e.g., sum(weights) == 1). If not provided, the weights are assigned equally in the ‘fit’ method.

fit(x_train, y_train, **kwargs_method)

Method for training to find the best core for fuzzy normalization that matches the given ranking.

Parameters:
  • x_train (ndarray) – Decision matrix used for training to find the best core for fuzzy normalization. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Ranking of the alternatives contained in ‘x_train’.

  • **kwargs_method – Dictionary of parameter settings for the optimization method ‘self.method’.

fitness(solutions, correlation=<function weighted_spearman>)

Fitness method for finding the cores for fuzzy normalization.

Parameters:
  • solutions (ndarray) – Matrix representing the cores for fuzzy numbers.

  • correlation (callable, optional) – A correlation coefficient function used to compare rankings during the search for the optimal cores. The default is rw.

Returns:

The correlation value between the reference ranking and the ranking obtained from the base method with fuzzy normalization based on the identified cores.

Return type:

float

abstract get_fuzzy_numbers(cores)

Abstract method to be implemented in subclasses to convert cores to fuzzy numbers.

pymcdm_reidentify.methods.sitcom

class pymcdm_reidentify.methods.sitcom.SITCOM(method, cvalues)

Bases: StochasticIdentification

Stochastic IdenTification Of Models (SITCOM) approach.

SITCOM is an approach based on determining the preferences of characteristic objects using the COMET method through stochastic optimization methods. The main advantage of this approach is the ability to re-identify the COMET model without re-engaging the decision-making expert [2], [3].

References

Examples

>>> import numpy as np
>>> from mealpy.swarm_based.PSO import OriginalPSO
>>> from pymcdm.methods import COMET, TOPSIS
>>> from pymcdm.methods.comet_tools import MethodExpert
>>> from pymcdm_reidentify.methods import SITCOM
>>> matrix = np.random.random((1000, 2))
>>> types = np.array([-1, 1])
>>> weights = np.array([0.5, 0.5])
>>> cvalues = COMET.make_cvalues(matrix, 2)
>>> comet = COMET(cvalues, MethodExpert(TOPSIS(), weights, types))
>>> preference = comet(matrix)
>>> rank = comet.rank(preference)
>>> stoch = OriginalPSO(epoch=1000, pop_size=100)
>>> model = SITCOM(stoch.solve, cvalues)
>>> model.fit(matrix, rank, log_to=None)
__call__(*args, **kwargs)

Method that returns the identified preferences of characteristics objects.

Returns:

The preferences of characteristics objects.

Return type:

ndarray

__init__(method, cvalues)

Create SITCOM object.

Parameters:
  • method (callable) – A function used for optimization to find the best preferences of characteristic objects. It should include ‘bounds’, which denote the search boundaries for the preferences; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the preferences of characteristics objects selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of characteristic objects in the decision-making problem.

  • cvalues (list[list]) – A list of characteristic values based on which characteristic objects are created for the SITCOM model. Each criterion should have at least two characteristic values, which should be provided in a nested list.

fit(x_train, y_train, **kwargs_method)

Trains the model to find the best preferences for characteristic objects in the COMET model, matching the given ranking.

Parameters:
  • x_train (ndarray) – Decision matrix used for training to find the best preferences for characteristic objects. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Ranking of the alternatives contained in ‘x_train’.

  • **kwargs_method – Dictionary of parameter settings for the optimization method ‘self.method’.

fitness(solutions, correlation=<function weighted_spearman>)

Fitness method for finding the preferences of characteristic objects in the COMET model.

Parameters:
  • solutions (ndarray) – Matrix representing the preferences of characteristic objects.

  • correlation (callable, optional) – A correlation coefficient function used to compare rankings during the search for the optimal preferences of characteristic objects. The default is rw.

Returns:

The correlation value between the reference ranking and the ranking obtained from the COMET method with the identified preferences of characteristic objects.

Return type:

float

pymcdm_reidentify.methods.sitw

class pymcdm_reidentify.methods.sitw.SITW(method, base, types)

Bases: StochasticIdentification

Stochastic Identification of Weights (SITW) approach.

The SITW approach involves finding the optimal weights for decision criteria in a given MCDA/MCDM method, so that the resulting rankings of alternatives are as close as possible to a reference ranking. Stochastic optimization methods are used to find these weights [4].

References

Examples

>>> import numpy as np
>>> from mealpy.swarm_based.PSO import OriginalPSO
>>> from pymcdm.methods import TOPSIS
>>> from pymcdm_reidentify.methods import SITW
>>> # Exemplary data
>>> matrix = np.random.random((1000, 2))
>>> types = np.array([-1, 1])
>>> weights = np.random.random((2))
>>> weights = weights / np.sum(weights) # Unknown expert criteria weights
>>> preference = TOPSIS()(matrix, weights, types)
>>> rank = TOPSIS().rank(preference)
>>> stoch = OriginalPSO(epoch=1000, pop_size=100)
>>> model = SITW(stoch.solve, TOPSIS(), types)
>>> model.fit(matrix, rank, log_to=None)
__call__(*args, **kwargs)

Return the optimal weights found during the fitting process.

Returns:

The weights for the decision criteria.

Return type:

ndarray

__init__(method, base, types)

Creates SITW object.

Parameters:
  • method (callable) – A function used for optimization to find the best weights for decision criteria. It should include ‘bounds’, which denote the search boundaries for the weights; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the criteria weights selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of criteria in the decision-making problem.

  • base (object) – An object representing the MCDA/MCDM method for which the criteria weights will be found. This method should be able to process a weight vector where the sum of the weights is equal to 1.

  • types (ndarray) – Array with definitions of criteria types: 1 if a criterion is a profit criterion and -1 if a criterion is a cost criterion for each criterion in the decision matrix.

fit(x_train, y_train, **kwargs_method)

Fit the model to find the optimal weights for the decision criteria.

Parameters:
  • x_train (ndarray) – Decision matrix used for training. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Reference ranking of the alternatives.

  • **kwargs_method (dict) – Dictionary of parameter settings for the optimization method ‘self.method’.

fitness(solutions, correlation=<function weighted_spearman>)

Evaluate the fitness of a solution by comparing the ranking it produces with the reference ranking.

Parameters:
  • solutions (ndarray) – Array of unnormalized weights for the decision criteria. These weights are normalized within the fitness function.

  • correlation (callable, optional) – A correlation coefficient function used to compare rankings. The default is rw.

Returns:

The correlation value between the ranking obtained using the MCDA method with the normalized weights and the reference ranking.

Return type:

float

pymcdm_reidentify.methods.sitwlocal

class pymcdm_reidentify.methods.sitwlocal.SITWLocal(method, base, types)

Bases: StochasticIdentification

Stochastic Identification of Weights based Local weights (SITWLocal) approach.

The SITWLocal approach is designed to identify weights for an MCDA/MCDM model that evaluates characteristic objects using the COMET method. This approach determines local weights for selected alternatives from the COMET approach by finding weights for the MCDA/MCDM model that minimize the mean absolute error (MAE) between the local weights derived from the model and the reference local weights [5].

References

Examples

>>> import numpy as np
>>> from mealpy.swarm_based.PSO import OriginalPSO
>>> from pymcdm.methods import COMET, TOPSIS
>>> from pymcdm.methods.comet_tools import MethodExpert, get_local_weights
>>> from pymcdm_reidentify.methods import SITWLocal
>>> matrix = np.random.random((1000, 2))
>>> types = np.array([-1, 1])
>>> weights = np.array([0.5, 0.5])
>>> model = COMET(COMET.make_cvalues(matrix, 3), MethodExpert(TOPSIS(), weights, types))
>>> y_train = np.array([get_local_weights(model, alt, percent_step=0.01) for alt in matrix])
>>> stoch = OriginalPSO(epoch=1000, pop_size=100)
>>> model = SITWLocal(stoch.solve, TOPSIS(), types)
>>> model.fit(matrix, y_train)
__call__(*args, **kwargs)

Return the optimal weights found during the fitting process.

Returns:

The weights for the decision criteria.

Return type:

ndarray

__init__(method, base, types)

Creates object of the SITWLocal class.

Parameters:
  • method (callable) – A function used for optimization to find the best weights for decision criteria. It should include ‘bounds’, which denote the search boundaries for the weights; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the criteria weights selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of criteria in the decision-making problem.

  • base (object) – An object representing the MCDA/MCDM method for which the criteria weights will be found. This method should be able to process a weight vector where the sum of the weights is equal to 1.

  • types (ndarray) – Array with definitions of criteria types: 1 if a criterion is a profit criterion and -1 if a criterion is a cost criterion for each criterion in the decision matrix.

fit(x_train, y_train, **kwargs_method)

Fit the model to find the optimal weights for the decision criteria.

Parameters:
  • x_train (ndarray) – Decision matrix used for training. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Preference of the alternatives. Preference values for alternatives must be in the range [0, 1].

  • **kwargs_method (dict) – Dictionary of parameter settings for the optimization method ‘self.method’.

fitness(solutions)

Evaluate the fitness of a solution by comparing the preference it produces with the reference preference.

Parameters:

solutions (ndarray) – Array of unnormalized weights for the decision criteria. These weights are normalized within the fitness function.

Returns:

The mean absolute error (MAE) value between the preference obtained using the Expert MCDA method with the normalized weights in the COMET method and the reference preference.

Return type:

float

pymcdm_reidentify.methods.stfn

class pymcdm_reidentify.methods.stfn.STFN(method, base, fn_bounds, weights=None)

Bases: SFN

Stochastic Triangular Fuzzy Normalization (STFN).

STFN is an approach based on fuzzy normalization using triangular fuzzy numbers. This approach seeks the cores of triangular fuzzy numbers used to normalize the decision matrix so that the MCDA/MCDM method combined with STFN best reflects the reference ranking [6].

References

Examples

>>> import numpy as np
>>> from mealpy.swarm_based.PSO import OriginalPSO
>>> from pymcdm.methods import TOPSIS
>>> from pymcdm_reidentify.methods import STFN
>>> matrix = np.random.random((1000, 2))
>>> types = np.array([-1, 1])
>>> weights = np.array([0.5, 0.5])
>>> bounds = np.array([[0, 1], [0, 1]])
>>> topsis = TOPSIS()
>>> preference = topsis(matrix, weights, types)
>>> rank = topsis.rank(preference)
>>> stoch = OriginalPSO(epoch=1000, pop_size=100)
>>> model = STFN(stoch.solve, TOPSIS(), bounds)
>>> model.fit(matrix, rank, log_to=None)
__init__(method, base, fn_bounds, weights=None)

Create object of STFN class.

Parameters:
  • method (callable) – A function used for optimization to find the best cores. It should include ‘bounds’, which denote the search boundaries for the cores; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the fuzzy normalization selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of criteria in the decision-making problem.

  • base (object) – An object representing the MCDA/MCDM method for which the cores will be found. It should have a ‘normalization’ attribute and be callable for evaluating alternatives (in this case, the training set).

  • fn_bounds (list[list]) – Nested lists containing the boundary values for the triangular fuzzy numbers used for normalization. These boundaries are used to declare the search bounds for the cores.

  • weights (ndarray, optional) – Criteria weights. The sum of the weights should be 1 (e.g., sum(weights) == 1). If not provided, the weights are assigned equally in the ‘fit’ method.

get_fuzzy_numbers(cores)

Method that returns a list of triangular fuzzy numbers used for normalizing the decision matrix.

Parameters:

cores (ndarray) – Matrix representing the cores for triangular fuzzy numbers.

Returns:

A list of triangular fuzzy numbers represented as functions.

Return type:

list[callable]

pymcdm_reidentify.methods.stochastic_identification

class pymcdm_reidentify.methods.stochastic_identification.StochasticIdentification(method)

Bases: ABC

Abstract class for stochastic re-identification methods.

This class serves as a template for creating methods that utilize stochastic optimization to find the best solution for re-identification problems.

__init__(method)

Abstract initialization for StochasticIdentification class.

Parameters:

method (callable) – A function used for optimization to find the best solution.

abstract fit(x_train, y_train, **kwargs_method)

Method for training to find the best solution.

This method should be implemented in subclasses to perform the necessary training to identify the optimal solution using the provided decision matrix and rankings.

Parameters:
  • x_train (ndarray) – Decision matrix used for training. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Ranking/preferences of the alternatives contained in ‘x_train’.

  • **kwargs_method (dict) – Dictionary of parameter settings for the optimization method ‘self.method’.

abstract fitness(solutions)

Fitness method for evaluating the quality of a solution.

This method should be implemented in subclasses to evaluate the fitness of potential solutions provided by the stochastic optimization method.

Parameters:

solutions (ndarray) – Possible solutions provided by the stochastic optimization method.

pymcdm_reidentify.methods.strfn

class pymcdm_reidentify.methods.strfn.STRFN(method, base, fn_bounds, weights=None)

Bases: SFN

Stochastic Trapezoidal Fuzzy Normalization (STRFN).

STRFN is an approach based on fuzzy normalization using trapezoidal fuzzy numbers. This approach seeks the cores of trapezoidal fuzzy numbers used to normalize the decision matrix so that the MCDA/MCDM method combined with STRFN best reflects the reference ranking.

Examples

>>> import numpy as np
>>> from mealpy.swarm_based.PSO import OriginalPSO
>>> from pymcdm.methods import TOPSIS
>>> from pymcdm_reidentify.methods import STRFN
>>> matrix = np.random.random((1000, 2))
>>> types = np.array([-1, 1])
>>> weights = np.array([0.5, 0.5])
>>> bounds = np.array([[0, 1], [0, 1]])
>>> topsis = TOPSIS()
>>> preference = topsis(matrix, weights, types)
>>> rank = topsis.rank(preference)
>>> stoch = OriginalPSO(epoch=1000, pop_size=100)
>>> model = STRFN(stoch.solve, TOPSIS(), bounds)
>>> model.fit(matrix, rank, log_to=None)
__init__(method, base, fn_bounds, weights=None)

Creates object of STRFN class.

Parameters:
  • method (callable) – A function used for optimization to find the best cores. It should include ‘bounds’, which denote the search boundaries for the cores; these boundaries are projected onto a FloatVar object from the MealPy library. The function should also include an argument to set ‘obj_func’, which is used according to the fuzzy normalization selection methodology. Additionally, it should have an argument to set ‘minmax’, which determines whether the function is minimized or maximized. It should also have an argument to set ‘n_dims’, which indicates the number of criteria in the decision-making problem.

  • base (object) – An object representing the MCDA/MCDM method for which the cores will be found. It should have a ‘normalization’ attribute and be callable for evaluating alternatives (in this case, the training set).

  • fn_bounds (list[list]) – Nested lists containing the boundary values for the trapezoidal fuzzy numbers used for normalization. These boundaries are used to declare the search bounds for the cores.

  • weights (ndarray, optional) – Criteria weights. The sum of the weights should be 1 (e.g., sum(weights) == 1). If not provided, the weights are assigned equally in the ‘fit’ method.

fit(x_train, y_train, **kwargs_method)

Method for training to find the best core for fuzzy normalization that matches the given ranking.

Parameters:
  • x_train (ndarray) – Decision matrix used for training to find the best core for fuzzy normalization. Alternatives are in rows and criteria are in columns.

  • y_train (ndarray) – Ranking of the alternatives contained in ‘x_train’.

  • **kwargs_method – Dictionary of parameter settings for the optimization method ‘self.method’.

get_fuzzy_numbers(cores)

Method that returns a list of trapezoidal fuzzy numbers used for normalizing the decision matrix.

Parameters:

cores (ndarray) – Matrix representing the cores for trapezoidal fuzzy numbers.

Returns:

A list of trapezoidal fuzzy numbers represented as functions.

Return type:

list[callable]