Alternative
Discrete modification
- pysensmcda.alternative.discrete.discrete_modification(matrix: ndarray, discrete_values: ndarray, indexes: None | ndarray = None) list[tuple[int, int | tuple, tuple, ndarray]][source]
Modify a decision matrix based on specified discrete values and indexes combinations representing the columns modified at the time.
Parameters:
- matrixndarray
2D array representing the initial decision matrix.
- discrete_valuesndarray
Discrete values for each value in the decision matrix specifying the allowed changes. If 2D array, each element represents the discrete values that will be put in each column in the matrix. If 3D array, each element represents the discrete values that will be put for each value in the decision matrix separately.
- indexesNone | ndarray, optional, default=None
Indexes of the columns from matrix to be modified. If None, all columns are considered subsequently. If ndarray, it specifies the indexes or combinations of indexes for the columns to be modified.
Returns:
- List[Tuple[int, int | tuple, tuple, ndarray]]
A list of tuples containing information about the modified alternative index, criteria index, discrete change, and the resulting decision matrix.
Examples:
Example 1: Modify decision matrix with discrete values
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> discrete_values = np.array([[2, 3, 4], [1, 5, 6], [3, 4]], dtype='object) >>> results = discrete_modification(matrix, discrete_values) >>> for r in results: ... print(r)
Example 2: Modify matrix with discrete values list and specified indexes
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> discrete_values = np.array([[2, 3, 4], [1, 5, 6], [3, 4]], dtype='object') >>> indexes = np.array([[0, 2], 1], dtype='object') >>> results = discrete_modification(matrix, discrete_values, indexes) >>> for r in results: ... print(r)
Example 3: Modify matrix with 3D discrete values array
>>> 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') >>> results = discrete_modification(matrix, discrete_values) >>> for r in results: ... print(r)
Example 4: Modify matrix with 3D discrete values array and specified indexes
>>> 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) >>> for r in results: ... print(r)
Percentage modification
- pysensmcda.alternative.percentage.percentage_modification(matrix: ndarray, percentages: int | ndarray, direction: None | ndarray = None, indexes: None | ndarray = None, step: int | ndarray = 1) list[tuple[int, int | tuple, tuple, ndarray]][source]
Modify a decision matrix based on specified percentage changes, directions, indexes, and steps of percentage modifications.
Parameters:
- matrixndarray
2D array representing the initial decision matrix.
- percentagesint | ndarray
Percentage changes to be applied to the values in decision matrix. If int, the same percentage change is applied to all values. If ndarray, it specifies the percentage change for each column from matrix individually.
- directionNone | ndarray, optional, default=None
Direction of the modification for each column in the matrix. If None, both increase and decrease directions are considered. If ndarray, it specifies the direction (1 for increase, -1 for decrease) for each criterion individually.
- indexesNone | ndarray, optional, default=None
Indexes of the columns from matrix to be modified. If None, all columns are considered subsequently. If ndarray, it specifies the indexes or combinations of indexes for the columns to be modified.
- stepint | np.ndarray, optional, default=1
Step size for the percentage change. If int, all changes for columns are made with the same step. If ndarray, the modification step is adjusted for each column separately.
Returns:
- List[Tuple[int, int | tuple, tuple, ndarray]]
A list of tuples containing information about the modified alternative index, criteria index, percentage change, and the resulting decision matrix.
Examples:
Example 1: Modify decision matrix with a single percentage change
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> percentages = 5 >>> results = percentage_modification(matrix, percentages) >>> for r in results: ... print(r)
Example 2: Modify matrix with percentages list
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> percentages = np.array([3, 5, 8]) >>> results = percentage_modification(matrix, percentages) >>> for r in results: ... print(r)
Example 3: Modify matrix with percentages list and specific direction for each column
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> percentages = np.array([2, 4, 6]) >>> direction = np.array([-1, 1, -1]) >>> results = percentage_modification(matrix, percentages, direction) >>> for r in results: ... print(r)
Example 4: Modify matrix with percentages list, and specific column indexes
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> percentages = np.array([1, 4, 2]) >>> indexes = np.array([[0, 2], 1], dtype='object') >>> results = percentage_modification(matrix, percentages, indexes) >>> for r in results: ... print(r)
Example 5: Modify matrix with percentages list, and specific modification step
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> percentages = np.array([2, 4, 9]) >>> step = np.array([2, 2, 3]) >>> results = percentage_modification(matrix, percentages, step=step) >>> for r in results: ... print(r)
Range modification
- pysensmcda.alternative.range.range_modification(matrix: ndarray, range_values: ndarray, indexes: None | ndarray = None, step: int | float | ndarray = 1) list[tuple[int, int | tuple, tuple, ndarray]][source]
Modify a decision matrix based on specified range values, indexes representing the combination of columns to be modified, and steps of range modifications.
Parameters:
- matrixndarray
2D array representing the initial decision matrix.
- range_valuesndarray
Range of values for each value in the decision matrix specifying the allowed changes. If 2D array, each element represents the lower and upper bounds of the allowed range for each column in the matrix. If 3D array, each element represents the lower and upper bounds of the allowed range for each value in the decision matrix separately.
- indexesNone | ndarray, optional, default=None
Indexes of the columns from the matrix to be modified. If None, all columns are considered subsequently. If ndarray, it specifies the indexes or combinations of indexes for the columns to be modified.
- stepint | float | np.ndarray, optional, default=1
Step size for the change in given range. If int, all changes for columns are made with the same step. If ndarray, the modification step is adjusted for each column separately.
Returns:
- List[Tuple[int, int | tuple, tuple, ndarray]]
A list of tuples containing information about the modified alternative index, criteria index, range change, and the resulting decision matrix.
Examples:
Example 1: Modify the decision matrix with a 2D range change, same range for row in matrix for a given column
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> range_values = np.array([[6, 8], [2, 4], [4, 6.5]]) >>> results = range_modification(matrix, range_values) >>> for r in results: ... print(r)
Example 2: Modify the decision matrix with a 3D range change array, given range for every element in matrix
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> range_values = np.array([ ... [[3, 5], [1, 3], [4, 6]], ... [[2, 5], [5, 7], [2, 4]], ... [[8, 11], [4, 7], [7, 9]], ... ]) >>> results = range_modification(matrix, range_values) >>> for r in results: ... print(r)
Example 3: Modify the decision matrix with specific column indexes
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> range_values = np.array([[6, 8], [2, 4], [4, 6.5]]) >>> indexes = np.array([[0, 2], 1], dtype='object') >>> results = range_modification(matrix, range_values, indexes) >>> for r in results: ... print(r)
Example 4: Modify the decision matrix with a specified step size
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> range_values = np.array([[6, 8], [2, 4], [4, 6.5]]) >>> step = 0.5 >>> results = range_modification(matrix, range_values, step=step) >>> for r in results: ... print(r)
Example 5: Modify the decision matrix with individual step sizes for each column
>>> matrix = np.array([ ... [4, 1, 6], ... [2, 6, 3], ... [9, 5, 7], ... ]) >>> range_values = np.array([[6, 8], [2, 4], [4, 6.5]]) >>> step = np.array([0.25, 0.4, 0.5]) >>> results = range_modification(matrix, range_values, step=step) >>> for r in results: ... print(r)
Alternative removal
- pysensmcda.alternative.removal.remove_alternatives(matrix: ndarray, indexes: None | int | ndarray = None) list[tuple[int, ndarray]][source]
Remove one or more alternatives from a decision matrix.
Parameters:
- matrixndarray
2D array with a decision matrix containing multiple criteria and alternatives.
- indexesNone | int | ndarray, optional, default=None
Index or array of indexes specifying which alternative to remove. If None, one alternative will be subsequently removed by default.
Returns:
- List[Tuple[int, ndarray]]
A list of tuples containing information about the new decision matrix.
Examples:
Example 1: Remove one alternative (default behavior)
>>> matrix = np.array([ ... [1, 2, 3, 4], ... [1, 2, 3, 4], ... [4, 3, 2, 1], ... [3, 5, 3, 2], ... [4, 2, 5, 5], ... ]) >>> results = remove_alternatives(matrix) >>> for result in results: ... print(result)
Example 2: Remove alternative at a specific index
>>> matrix = np.array([ ... [1, 2, 3, 4], ... [1, 2, 3, 4], ... [4, 3, 2, 1], ... [3, 5, 3, 2], ... [4, 2, 5, 5], ... ]) >>> results = remove_alternatives(matrix, 3) >>> for result in results: ... print(result)
Example 3: Remove alternatives with specified indexes (1D array)
>>> matrix = np.array([ ... [1, 2, 3, 4], ... [1, 2, 3, 4], ... [4, 3, 2, 1], ... [3, 5, 3, 2], ... [4, 2, 5, 5], ... ]) >>> results = remove_alternatives(matrix, np.array([1, 2, 3])) >>> for result in results: ... print(result)
Example 4: Remove alternatives with specified indexes (mixed-type array)
>>> matrix = np.array([ ... [1, 2, 3, 4], ... [1, 2, 3, 4], ... [4, 3, 2, 1], ... [3, 5, 3, 2], ... [4, 2, 5, 5], ... ]) >>> results = remove_alternatives(matrix, np.array([[0, 4], 2, 3], dtype='object')) >>> for result in results: ... print(result)