Modules

Results sensitivity assessment

pysensmcda.calculate_preference.calculate_preference(func: callable, results: list | ndarray | tuple, method: callable, call_kwargs: dict, only_preference: bool = True, method_type: int | None = None) ndarray | tuple[source]

Wrapper for calculating preference depending on the sensitivity analysis function.

Parameters:

func: callable

Function for pysensmcda library that was used to acquire results.

results: depending on func

Results of the function which should be given as func.

method: callable

Method that should be used to calculate preferences.

call_kwargs: dict

Parameters that should be passed to method in order to calculate preferences. Used internally:

matrix for decision matrix weights for criteria weights

only_preference: bool, optional, default=True

If True only preferences are returned in ndarray. If False list of tuples that resembles results is returned, where preferences are in the last column.

method_type: int or None, optional, default=None

If set, rankings are returned. Supported values: -1 for ascending ranking; 1 for descending ranking

Returns:

ndarray or list[tuple]

If only_preference=True, array of preferences calculated for different matrices / weights depending on the type of sensitivity analysis is returned. Else the preferences are appended to results as last column. If method_type is set, the rankings are appended to column after preferences.

Examples:

Example 1: Alternative sensitivity analysis - return only preferences

>>> from pymcdm.methods import TOPSIS
>>>
>>> topsis = TOPSIS()
>>>
>>> matrix = np.array([
>>> [4, 1, 6],
>>> [2, 6, 3],
>>> [9, 5, 7],
>>> ])
>>> discrete_values = np.array([
>>>     [[5, 6], [2, 4], [5, 8]],
>>>     [[3, 5.5], [4], [3.5, 4.5]],
>>>     [[7, 8], [6], [8, 9]],
>>> ], dtype='object')
>>> indexes = np.array([[0, 2], 1], dtype='object')
>>> results = discrete_modification(matrix, discrete_values, indexes)
>>> kwargs = {
>>>     'matrix': matrix,,
>>>     'weights': np.ones(matrix.shape[0])/matrix.shape[0],
>>>     'types': np.ones(matrix.shape[0])
>>> }
>>>
>>> calculate_preference(discrete_modification, results, topsis, kwargs)

Example 2: Criteria sensitivity analysis - return preferences and rankings

>>> from pysensmcda.criteria import percentage_modification
>>>
>>> weights = np.array([0.3, 0.3, 0.4])
>>> percentage = 5
>>> results = percentage_modification(weights, percentage)
>>>
>>> kwargs = {
>>>     'matrix': np.random.random((10, 3)),
>>>     'weights': weights,
>>>     'types': np.ones(3)
>>> }
>>>
>>> calculate_preference(percentage_modification, results, topsis, kwargs, method_type=1)

Example 3: Criteria sensitivity analysis - return rankings and aggregated results

>>> from pysensmcda.criteria import percentage_modification
>>>
>>> weights = np.array([0.3, 0.3, 0.4])
>>> percentage = 5
>>> results = percentage_modification(weights, percentage)
>>>
>>> kwargs = {
>>>     'matrix': np.random.random((10, 3)),
>>>     'weights': weights,
>>>     'types': np.ones(3)
>>> }
>>>
>>> calculate_preference(percentage_modification, results, topsis, kwargs, only_preference=False, method_type=1)

Utils

pysensmcda.utils.memory_guard(func)[source]

Validator

class pysensmcda.validator.Validator[source]

Bases: object

static are_indexes_valid(indexes, size, var_name='indexes', custom_message=None)[source]
static is_array_2D_3D(var, ref_var, var_name, ref_var_name, custom_message=None)[source]
static is_callable(var, var_name, custom_message=None)[source]
static is_dimension_valid(var, size, var_name, custom_message=None)[source]
static is_in_list(var, var_list, var_name, custom_message=None)[source]
static is_in_range(var, min_val, max_val, var_name, custom_message=None)[source]
static is_key_in_dict(keys, dict, var_name, custom_message=None)[source]
static is_positive_value(var, var_name, bound=0, custom_message=None)[source]
static is_shape_equal(size1, size2, var_name_1='', var_name_2='', custom_message=None)[source]
static is_sum_valid(var, sum, var_name='weights', precision=3, custom_message=None)[source]
static is_type_in_dict_valid(key, dict, type, var_name, custom_message=None)[source]
static is_type_valid(var, type, var_name, custom_message=None)[source]