### Import Libraries and Setup Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Imports necessary libraries and sets up environment configurations for numerical operations and plotting. ```python import numpy as np from tabulate import tabulate import matplotlib.pyplot as plt from pyifdm import methods from pyifdm.graphs import * from pyifdm.IFS import IFS from pyifdm.methods import ifs from pyifdm import weights as ifs_weights from pyifdm import correlations as corrs from pyifdm.helpers import rank, generate_ifs_matrix import warnings warnings.filterwarnings('ignore') np.set_printoptions(suppress=True, precision=3) ``` -------------------------------- ### Install pytest and Run Tests Source: https://github.com/jwieckowski/pyifdm/blob/main/README.md Install the pytest library and run tests for the pyifdm modules. Ensure you have pytest installed to verify the package's performance. ```bash pip install pytest pytest tests ``` -------------------------------- ### Install pyifdm Package Source: https://github.com/jwieckowski/pyifdm/blob/main/README.md Use pip to install the pyifdm package. This is the standard method for installing Python packages. ```bash pip install pyifdm ``` -------------------------------- ### Initialize Intuitionistic Fuzzy MCDA methods Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/illustrative_examples.ipynb Creates a dictionary mapping method names to their corresponding initialized objects from the PyIFDM library. This setup is useful for iterating through available methods. ```python if_methods = { 'IF-ARAS': methods.ifARAS(), 'IF-CODAS': methods.ifCODAS(), 'IF-COPRAS': methods.ifCOPRAS(), 'IF-EDAS': methods.ifEDAS(), 'IF-MABAC': methods.ifMABAC(), 'IF-MAIRCA': methods.ifMAIRCA(), 'IF-MOORA': methods.ifMOORA(), 'IF-TOPSIS': methods.ifTOPSIS(), 'IF-VIKOR': methods.ifVIKOR() } method_names = if_methods.keys() ``` -------------------------------- ### Initialize Decision Matrix and Weights Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/illustrative_examples.ipynb Sets up the decision matrix, crisp weights, and decision types for a multi-attribute group decision-making problem. ```python matrix = np.array([ [[0.4745, 0.5255], [0.4752, 0.5248], [0.2981, 0.7019], [0.4374, 0.5627]], [[0.5346, 0.4654], [0.5532, 0.4468], [0.63, 0.37], [0.5901, 0.4099]], [[0.4324, 0.5676], [0.403, 0.597], [0.4298, 0.5702], [0.4361, 0.5639]], [[0.5235, 0.4765], [0.4808, 0.5192], [0.5667, 0.4333], [0.2913, 0.7087]], [[0.4168, 0.5832], [0.4923, 0.5077], [0.4732, 0.5268], [0.4477, 0.5523]] ]) crisp_weights = np.array([0.1410, 0.2263, 0.3234, 0.3093]) types = np.array([1, -1, 1, 1]) ``` -------------------------------- ### Configure IF-CODAS with Different Distance Metrics Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates initializing the IF-CODAS method with various pairs of distance metrics. The choice of distance metrics can influence the calculation of alternative preferences. ```python codas = { 'Pair 1': methods.ifCODAS(distance_1=ifs.distance.euclidean_distance, distance_2=ifs.distance.hamming_distance), 'Pair 2': methods.ifCODAS(distance_1=ifs.distance.normalized_euclidean_distance, distance_2=ifs.distance.normalized_hamming_distance), 'Pair 3': methods.ifCODAS(distance_1=ifs.distance.wang_xin_distance_1, distance_2=ifs.distance.wang_xin_distance_2), } ``` -------------------------------- ### rank Source: https://context7.com/jwieckowski/pyifdm/llms.txt Converts a vector of preference scores into ordinal ranks. Ranks are assigned in descending order by default (highest score gets rank 1), with ties handled gracefully. Ascending order is also supported. ```APIDOC ## rank ### Description Converts a vector of preference scores into ordinal ranks (descending by default, so highest score = rank 1). Handles tied values gracefully. ### Parameters - **scores** (numpy.ndarray) - A 1D NumPy array of preference scores. - **descending** (bool, optional) - If True, ranks in descending order (default). If False, ranks in ascending order. ### Returns - **numpy.ndarray** - A 1D NumPy array containing the ranks corresponding to the input scores. ### Usage ```python from pyifdm.helpers import rank import numpy as np scores = np.array([0.276, 0.259, 0.523, 0.995, 0.322]) r = rank(scores) print(f"Preferences: {scores}") print(f"Ranking: {r}") # Ranking: [4. 5. 2. 1. 3.] # Ascending ranking (lower score = rank 1, used internally by VIKOR) r_asc = rank(scores, descending=False) print(f"Ascending: {r_asc}") # Ascending: [2. 1. 4. 5. 3.] ``` ``` -------------------------------- ### Initialize and Use IFS Class Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/pyifdm.IFS.md Demonstrates the initialization of IFS objects and the usage of basic set operations like intersection, union, and complement, as well as OWA aggregation. Uncertainty is automatically calculated if not provided. ```python # Example Usage: ifs1 = IFS(0.6, 0.2) ifs2 = IFS(0.8, 0.1) intersection_result = ifs1 & ifs2 union_result = ifs1 | ifs2 complement_result = ~ifs1 owa_weights = [0.3, 0.4, 0.3] owa_result = ifs1.owa_aggregation(owa_weights) ``` -------------------------------- ### Calculate Criteria Weights with Different Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates how to calculate criteria weights using various entropy-based methods provided by the library. Ensure the 'matrix' variable is defined before use. ```python weights_methods = { 'Burillo Entropy': ifs_weights.burillo_entropy_weights, 'Equal': ifs_weights.equal_weights, 'Entropy': ifs_weights.entropy_weights, 'Liu Entropy': ifs_weights.liu_entropy_weights, 'Szmidt Entropy': ifs_weights.szmidt_entropy_weights, 'Thakur Entropy': ifs_weights.thakur_entropy_weights, 'Ye Entropy': ifs_weights.ye_entropy_weights, } for name, method in weights_methods.items(): w = method(matrix) print(f'{name} {w} ') ``` -------------------------------- ### Apply Multiple MCDA Methods with a Unified Interface Source: https://context7.com/jwieckowski/pyifdm/llms.txt Demonstrates how to instantiate and apply various MCDA methods (ARAS, MABAC, MAIRCA, MARCOS, MOORA, OCRA, WSM, WPM) using a consistent interface. Requires numpy for matrix operations. ```python from pyifdm.methods import ( ifARAS, ifMABAC, ifMAIRCA, ifMARCOS, ifMOORA, ifOCRA, ifWSM, ifWPM ) import numpy as np matrix = np.array([ [[0.5, 0.3], [0.4, 0.4], [0.6, 0.2], [0.3, 0.5]], [[0.7, 0.2], [0.5, 0.3], [0.4, 0.5], [0.6, 0.3]], [[0.4, 0.4], [0.6, 0.2], [0.5, 0.4], [0.5, 0.4]], [[0.6, 0.3], [0.3, 0.6], [0.7, 0.2], [0.4, 0.5]], [[0.5, 0.4], [0.5, 0.4], [0.5, 0.3], [0.5, 0.3]], ]) weights = np.array([0.25, 0.25, 0.25, 0.25]) types = np.array([1, -1, 1, 1]) results = {} for name, cls in [ ('ARAS', ifARAS()), ('MABAC', ifMABAC()), ('MAIRCA', ifMAIRCA()), ('MARCOS', ifMARCOS()), ('MOORA', ifMOORA()), ('OCRA', ifOCRA()), ('WSM', ifWSM()), ('WPM', ifWPM()), ]: try: pref = cls(matrix, weights, types) results[name] = cls.rank() print(f"{name:8s} ranking: {results[name]}") except Exception as e: print(f"{name:8s} error: {e}") ``` -------------------------------- ### Apply and Rank IF-DM Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/illustrative_examples.ipynb Demonstrates how to apply and rank multiple IF-DM methods (IF-MARCOS, IF-OCRA, IF-WASPAS, IF-WPM, IF-WSM) to a given decision matrix, weights, and types. Requires the 'tabulate' library for output formatting. ```python matrix = np.array([ [[0.4745, 0.5255], [0.4752, 0.5248], [0.2981, 0.7019], [0.4374, 0.5627]], [[0.5346, 0.4654], [0.5532, 0.4468], [0.63, 0.37], [0.5901, 0.4099]], [[0.4324, 0.5676], [0.403, 0.597], [0.4298, 0.5702], [0.4361, 0.5639]], [[0.5235, 0.4765], [0.4808, 0.5192], [0.5667, 0.4333], [0.2913, 0.7087]], [[0.4168, 0.5832], [0.4923, 0.5077], [0.4732, 0.5268], [0.4477, 0.5523]] ]) crisp_weights = np.array([0.1410, 0.2263, 0.3234, 0.3093]) types = np.array([1, -1, 1, 1]) if_methods = { 'IF-MARCOS': methods.ifMARCOS(), 'IF-OCRA': methods.ifOCRA(), 'IF-WASPAS': methods.ifWASPAS(), 'IF-WPM': methods.ifWPM(), 'IF-WSM': methods.ifWSM(), } results = {} for name, function in if_methods.items(): function(matrix, crisp_weights, types) results[name] = function.rank() print(tabulate([[name, ranks] for name, ranks in results.items()], headers=['Method'] + [f'A{i+1}' for i in range(matrix.shape[0])])) ``` -------------------------------- ### Configure IF-MAIRCA with Different Distances Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates how to instantiate the IF-MAIRCA method with various distance measures. This allows for exploring the impact of different distance calculations on the results. ```python mairca = { 'Euclidean' : methods.ifMAIRCA(distance=ifs.distance.euclidean_distance), 'Grzegorzewski': methods.ifMAIRCA(distance=ifs.distance.grzegorzewski_distance), 'Hamming': methods.ifMAIRCA(distance=ifs.distance.hamming_distance), 'Luo distance': methods.ifMAIRCA(distance=ifs.distance.luo_distance), 'Normalized Euclidean': methods.ifMAIRCA(distance=ifs.distance.normalized_euclidean_distance), 'Normalized Hamming': methods.ifMAIRCA(distance=ifs.distance.normalized_hamming_distance), 'Wang Xin 1': methods.ifMAIRCA(distance=ifs.distance.wang_xin_distance_1), 'Wang Xin 2': methods.ifMAIRCA(distance=ifs.distance.wang_xin_distance_2), 'Yang Chiclana': methods.ifMAIRCA(distance=ifs.distance.yang_chiclana_distance), } ``` -------------------------------- ### Apply ifTOPSIS Method Source: https://context7.com/jwieckowski/pyifdm/llms.txt Demonstrates the Intuitionistic Fuzzy Technique for Order of Prioritization by Similarity to Ideal Solution (ifTOPSIS). Allows customization of distance and normalization methods. ```python from pyifdm.methods import ifTOPSIS from pyifdm.methods.ifs.distance import hamming_distance, euclidean_distance from pyifdm.methods.ifs.normalization import swap_normalization from pyifdm.helpers import rank import numpy as np matrix = np.array([ [[0.4745, 0.5255], [0.4752, 0.5248], [0.2981, 0.7019], [0.4374, 0.5627]], [[0.5346, 0.4654], [0.5532, 0.4468], [0.6300, 0.3700], [0.5901, 0.4099]], [[0.4324, 0.5676], [0.4030, 0.5970], [0.4298, 0.5702], [0.4361, 0.5639]], [[0.5235, 0.4765], [0.4808, 0.5192], [0.5667, 0.4333], [0.2913, 0.7087]], [[0.4168, 0.5832], [0.4923, 0.5077], [0.4732, 0.5268], [0.4477, 0.5523]] ]) weights = np.array([0.2, 0.3, 0.15, 0.35]) types = np.array([1, 1, 1, -1]) # must have mixed types for TOPSIS # Default: normalized_euclidean_distance, no normalization topsis = ifTOPSIS() pref = topsis(matrix, weights, types) print(f"IF-TOPSIS preferences: {np.round(pref, 4)}") print(f"IF-TOPSIS ranking: {topsis.rank()}") # Custom distance + normalization topsis_custom = ifTOPSIS(distance=hamming_distance, normalization=swap_normalization) pref_custom = topsis_custom(matrix, weights, types) print(f"Custom preferences: {np.round(pref_custom, 4)}") print(f"Custom ranking: {topsis_custom.rank()}") ``` -------------------------------- ### Initialize IFDM Data Structures Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/illustrative_examples.ipynb Prepare the input matrices and weights for IFDM methods. Ensure data types are appropriate for calculations. ```python matrix = np.array([ [[0.234, 0.685], [1.0, 0], [0.188, 0.741], [ 0.201, 0.669], [0.085, 0.823], [0.26, 0.592]], [[0.18, 0.754], [0.241, 0.649], [0.097, 0.846], [1.0, 0], [0.15, 0.8], [1.0, 0]], [[0.254, 0.599], [0.197, 0.722], [0.187, 0.737], [ 0.131, 0.791], [0.26, 0.642], [0.256, 0.595]], [[0.26, 0.592], [0.304, 0.582], [0.142, 0.797], [ 0.04, 0.896], [0.171, 0.732], [0.142, 0.797]], [[0.085, 0.823], [0.26, 0.642], [0.171, 0.732], [1.0, 0], [1.0, 0], [0.04, 0.896]] ]) fuzzy_weights = np.array([[0.23, 0.709], [0.425, 0.418], [0.31, 0.546], [ 0.464, 0.355], [0.383, 0.493], [0.204, 0.732]]) types = np.array([1, -1, 1, -1, 1, 1]) ``` -------------------------------- ### Custom EDAS Configuration Source: https://context7.com/jwieckowski/pyifdm/llms.txt Demonstrates how to configure and use the EDAS method with custom normalization and scoring functions. ```python edas2 = ifEDAS(normalization=ecer_normalization, score=chen_score_1) pref2 = edas2(matrix, weights, types) print(f"Custom EDAS preferences: {np.round(pref2, 4)}") ``` -------------------------------- ### Initialize TOPSIS Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/examples.ipynb Defines a dictionary mapping method names to their respective ifTOPSIS implementations with different distance metrics. Use this to select a specific distance calculation for the TOPSIS method. ```python topsis = { 'Normalized Euclidean': methods.ifTOPSIS(distance=ifs.distance.normalized_euclidean_distance), 'Wang Xin 1': methods.ifTOPSIS(distance=ifs.distance.wang_xin_distance_1), 'Wang Xin 2': methods.ifTOPSIS(distance=ifs.distance.wang_xin_distance_2), 'Yang Chiclana': methods.ifTOPSIS(distance=ifs.distance.yang_chiclana_distance), } ``` -------------------------------- ### ifTOPSIS Class Initialization Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/pyifdm.methods.topsis.md Initializes the Intuitionistic Fuzzy TOPSIS method object. Allows customization of distance and normalization functions. ```APIDOC ## class pyifdm.methods.if_topsis.ifTOPSIS ### Description Creates Intuitionistic Fuzzy TOPSIS method object with normalization and distance functions. ### Parameters * **distance** (*callable*, default=normalized_euclidean_distance) - Function used to calculate distance between two IFS * **normalization** (*callable*, default=None) - Function used to normalize the decision matrix ``` -------------------------------- ### Configure IF-ARAS with Different Normalizations Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates initializing the IF-ARAS method with various normalization techniques. Each normalization method can impact the final results. ```python aras = { 'Ecer normalization': methods.ifARAS(normalization=ifs.normalization.ecer_normalization), 'Minmax normalization': methods.ifARAS(normalization=ifs.normalization.minmax_normalization), 'Supriya normalization': methods.ifARAS(normalization=ifs.normalization.supriya_normalization), 'Swap normalization': methods.ifARAS(normalization=ifs.normalization.swap_normalization), } ``` -------------------------------- ### Initialize IF-VIKOR Methods with Different Distances Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Initializes IF-VIKOR objects with various distance metrics. This allows for comparing the VIKOR method's performance using different distance calculations. ```python vikor = { 'Euclidean' : methods.ifVIKOR(distance=ifs.distance.euclidean_distance), 'Grzegorzewski': methods.ifVIKOR(distance=ifs.distance.grzegorzewski_distance), 'Hamming': methods.ifVIKOR(distance=ifs.distance.hamming_distance), 'Luo distance': methods.ifVIKOR(distance=ifs.distance.luo_distance), 'Normalized Euclidean': methods.ifVIKOR(distance=ifs.distance.normalized_euclidean_distance), 'Normalized Hamming': methods.ifVIKOR(distance=ifs.distance.normalized_hamming_distance), 'Wang Xin 1': methods.ifVIKOR(distance=ifs.distance.wang_xin_distance_1), 'Wang Xin 2': methods.ifVIKOR(distance=ifs.distance.wang_xin_distance_2), 'Yang Chiclana': methods.ifVIKOR(distance=ifs.distance.yang_chiclana_distance), } ``` -------------------------------- ### Initialize IF-TOPSIS Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Initializes different distance metrics for the IF-TOPSIS method. Use this to select a specific distance calculation for the TOPSIS algorithm. ```python topsis = { 'Normalized Euclidean': methods.ifTOPSIS(distance=ifs.distance.normalized_euclidean_distance), 'Wang Xin 1': methods.ifTOPSIS(distance=ifs.distance.wang_xin_distance_1), 'Wang Xin 2': methods.ifTOPSIS(distance=ifs.distance.wang_xin_distance_2), 'Yang Chiclana': methods.ifTOPSIS(distance=ifs.distance.yang_chiclana_distance), } ``` -------------------------------- ### Initialize IF-WSM Method Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Initializes the IF-WSM (Weighted Sum Model) method. This is a basic step before applying the WSM logic to a decision problem. ```python if_wsm = methods.ifWSM() ``` -------------------------------- ### Apply and Display IF-WPM Results Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/examples.ipynb Applies the IF-WPM (Weighted Product Model) method to the data and prints the calculated preferences and the resulting ranking. This method uses default normalization and score settings. ```python if_wpm = methods.ifWPM() print(f'Preferences: {if_wpm(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_wpm.rank()}') ``` -------------------------------- ### Calculate and Display IF-WPM Results Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Computes and displays the preference scores and rankings using the IF-WPM method. This demonstrates the output of the Weighted Product Model in a fuzzy context. ```python if_wpm = methods.ifWPM() print(f'Preferences: {if_wpm(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_wpm.rank()}') ``` -------------------------------- ### Initialize IF-MARCOS Method Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Initializes the IF-MARCOS method. This is the first step before applying it to a decision-making problem. ```python if_marcos = methods.ifMARCOS() ``` -------------------------------- ### Calculate Objective Weights using Various Entropy Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/examples.ipynb Demonstrates calculating objective weights from a decision matrix using multiple entropy-based methods. Ensure the matrix is properly formatted as a NumPy array. ```python matrix = np.array([ [[0.4874, 0.3382], [0.3130, 0.5747], [0.5342, 0.3512], [0.5187, 0.3641]], [[0.7184, 0.2087], [0.2840, 0.6350], [0.6906, 0.2309], [0.6696, 0.2628]], [[0.5039, 0.4103], [0.2863, 0.5766], [0.4662, 0.4452], [0.5123, 0.3796]], [[0.5575, 0.3284], [0.3331, 0.5524], [0.5265, 0.3718], [0.5219, 0.3727]], [[0.4975, 0.4319], [0.3695, 0.5372], [0.4479, 0.4860], [0.6371, 0.1889]] ]) weights_methods = { 'Burillo Entropy': ifs_weights.burillo_entropy_weights, 'Equal': ifs_weights.equal_weights, 'Entropy': ifs_weights.entropy_weights, 'Liu Entropy': ifs_weights.liu_entropy_weights, 'Szmidt Entropy': ifs_weights.szmidt_entropy_weights, 'Thakur Entropy': ifs_weights.thakur_entropy_weights, 'Ye Entropy': ifs_weights.ye_entropy_weights, } for name, method in weights_methods.items(): w = method(matrix) print(f'{name} {w} ') ``` -------------------------------- ### Configure IF-MABAC with Different Distances Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates how to instantiate the IF-MABAC method with various distance measures. This allows for exploring the impact of different distance calculations on the results. ```python mabac = { 'Euclidean' : methods.ifMABAC(distance=ifs.distance.euclidean_distance), 'Grzegorzewski': methods.ifMABAC(distance=ifs.distance.grzegorzewski_distance), 'Hamming': methods.ifMABAC(distance=ifs.distance.hamming_distance), 'Luo distance': methods.ifMABAC(distance=ifs.distance.luo_distance), 'Normalized Euclidean': methods.ifMABAC(distance=ifs.distance.normalized_euclidean_distance), 'Normalized Hamming': methods.ifMABAC(distance=ifs.distance.normalized_hamming_distance), 'Wang Xin 1': methods.ifMABAC(distance=ifs.distance.wang_xin_distance_1), 'Wang Xin 2': methods.ifMABAC(distance=ifs.distance.wang_xin_distance_2), 'Yang Chiclana': methods.ifMABAC(distance=ifs.distance.yang_chiclana_distance), } ``` -------------------------------- ### IF-EDAS with Different Normalization Functions Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates using IF-EDAS with various normalization functions. This allows for exploring different ways to scale the data before applying the method. ```python edas = { 'Ecer normalization': methods.ifEDAS(normalization=ifs.normalization.ecer_normalization), 'Minmax normalization': methods.ifEDAS(normalization=ifs.normalization.minmax_normalization), 'Supriya normalization': methods.ifEDAS(normalization=ifs.normalization.supriya_normalization), 'Swap normalization': methods.ifEDAS(normalization=ifs.normalization.swap_normalization), } ``` ```python results = {} for name, function in edas.items(): results[name] = function(matrix, crisp_weights, types) ``` ```python print(tabulate([[name, *np.round(pref, 2)] for name, pref in results.items()], headers=['Method'] + [f'A{i+1}' for i in range(matrix.shape[0])])) ``` -------------------------------- ### Generate Intuitionistic Fuzzy Decision Matrix Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates how to create a decision matrix using real data or by generating random data with specified dimensions. ```python # real data matrix matrix = np.array([ [[0.4745, 0.5255], [0.4752, 0.5248], [0.2981, 0.7019], [0.4374, 0.5627]], [[0.5346, 0.4654], [0.5532, 0.4468], [0.6300, 0.3700], [0.5901, 0.4099]], [[0.4324, 0.5676], [0.4030, 0.5970], [0.4298, 0.5702], [0.4361, 0.5639]], [[0.5235, 0.4765], [0.4808, 0.5192], [0.5667, 0.4333], [0.2913, 0.7087]], [[0.4168, 0.5832], [0.4923, 0.5077], [0.4732, 0.5268], [0.4477, 0.5523]] ]) # randomly generated matrix # 5 alternatives # 4 criteria random_matrix = generate_ifs_matrix(5, 4) print(random_matrix) ``` -------------------------------- ### Initialize and Use IF-CODAS Method Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Initializes the IF-CODAS method and calculates preferences and rankings. This method is used for decision-making and requires a decision matrix, weights, and criteria types. ```python if_codas = methods.ifCODAS() print(f'Preferences: {if_codas(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_codas.rank()}') ``` -------------------------------- ### Apply Intuitionistic Fuzzy EDAS Method Source: https://github.com/jwieckowski/pyifdm/blob/main/README.md This snippet shows how to initialize and apply the IF-EDAS method with a given decision matrix, weights, and criteria types. Ensure all necessary libraries are imported. ```python from pyifdm.methods import ifEDAS from pyifdm.helpers import rank import numpy as np if __name__ == '__main__': matrix = np.array([ [[0.4745, 0.5255], [0.4752, 0.5248], [0.2981, 0.7019], [0.4374, 0.5627]], [[0.5346, 0.4654], [0.5532, 0.4468], [0.6300, 0.3700], [0.5901, 0.4099]], [[0.4324, 0.5676], [0.4030, 0.5970], [0.4298, 0.5702], [0.4361, 0.5639]], [[0.5235, 0.4765], [0.4808, 0.5192], [0.5667, 0.4333], [0.2913, 0.7087]], [[0.4168, 0.5832], [0.4923, 0.5077], [0.4732, 0.5268], [0.4477, 0.5523]] ]) weights = np.array([0.2, 0.3, 0.15, 0.35]) types = np.array([1, -1, 1, 1]) if_edas = ifEDAS() pref = if_edas(matrix, weights, types) print(f'IF-EDAS preferences: {pref}') print(f'IF-EDAS ranking: {rank(pref)}') ``` -------------------------------- ### Apply IF-MAIRCA Method Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Applies the IF-MAIRCA method to a decision matrix with fuzzy weights and types. Shows how to obtain preferences and ranking. ```python if_mairca = methods.ifMAIRCA() print(f'Preferences: {if_mairca(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_mairca.rank()}') ``` -------------------------------- ### Initialize and Use IF-ARAS Method Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Initializes the IF-ARAS method and performs an evaluation using crisp and fuzzy weights. The method requires a decision matrix, weights, and criteria types. ```python if_aras = methods.ifARAS() ``` ```python print(f'Crisp weights: {if_aras(matrix, crisp_weights, types)}') print(f'Fuzzy weights: {if_aras(matrix, fuzzy_weights, types)}') ``` -------------------------------- ### IF-MARCOS Method Calculation Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Calculates preferences and rankings using the IF-MARCOS method with crisp weights. Ensure crisp_weights are provided. ```python print(f'Preferences: {if_marcos(matrix, crisp_weights, types)}') print(f'Ranking: {if_marcos.rank()}') ``` -------------------------------- ### IFS Comparison and Utility Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/pyifdm.IFS.md Methods for comparing IFS objects and utility functions. ```APIDOC ## IFS.__eq__(other) ### Description Check if two IFS are equal. Parameters: - other (IFS): The IFS to compare with. Returns: bool: True if the IFS are equal, False otherwise. ``` ```APIDOC ## IFS.__repr__() ### Description Return a string representation of the IFS. Returns: str: A string representation of the IFS. ``` ```APIDOC ## IFS.__str__() ### Description Return a human-readable string representation of the IFS. Returns: str: A string representation of the IFS. ``` ```APIDOC ## IFS.dominance(other) ### Description Check if one IFS dominates another. Parameters: - other (IFS): The IFS to compare with. Returns: bool: True if the current IFS dominates the other, False otherwise. ``` ```APIDOC ## IFS.similarity_jaccard(other) ### Description Compute the Jaccard similarity coefficient between two IFS. Parameters: - other (IFS): The IFS to compare with. Returns: float: Jaccard similarity coefficient. ``` -------------------------------- ### IF-COPRAS with Different Score Functions Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates using IF-COPRAS with various predefined score functions. This allows for exploring different ways to aggregate fuzzy preferences. ```python copras = { 'Chen score 1': methods.ifCOPRAS(score=ifs.score.chen_score_1), 'Chen score 2': methods.ifCOPRAS(score=ifs.score.chen_score_2), 'Kharal score 1': methods.ifCOPRAS(score=ifs.score.kharal_score_1), 'Kharal score 2': methods.ifCOPRAS(score=ifs.score.kharal_score_2), 'Liu Wang score': methods.ifCOPRAS(score=ifs.score.liu_wang_score), 'Supriya score': methods.ifCOPRAS(score=ifs.score.supriya_score), 'Thakur score': methods.ifCOPRAS(score=ifs.score.thakur_score), 'Wan Dong score 1': methods.ifCOPRAS(score=ifs.score.wan_dong_score_1), 'Wan Dong score 2': methods.ifCOPRAS(score=ifs.score.wan_dong_score_2), 'Wei score': methods.ifCOPRAS(score=ifs.score.wei_score), 'Zhang Xu score 1': methods.ifCOPRAS(score=ifs.score.zhang_xu_score_1), 'Zhang Xu score 2': methods.ifCOPRAS(score=ifs.score.zhang_xu_score_2), } ``` ```python results = {} for name, function in copras.items(): results[name] = function(matrix, fuzzy_weights, types) ``` ```python print(tabulate([[name, *np.round(pref, 2)] for name, pref in results.items()], headers=['Method'] + [f'A{i+1}' for i in range(matrix.shape[0])])) ``` -------------------------------- ### IF-TOPSIS with Various Distance Metrics Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Configures IF-TOPSIS with different distance metrics for calculating preferences and rankings. Available metrics include Euclidean, Grzegorzewski, Hamming, Luo, and Normalized Hamming. ```python topsis = { 'Euclidean' : methods.ifTOPSIS(distance=ifs.distance.euclidean_distance), 'Grzegorzewski': methods.ifTOPSIS(distance=ifs.distance.grzegorzewski_distance), 'Hamming': methods.ifTOPSIS(distance=ifs.distance.hamming_distance), 'Luo distance': methods.ifTOPSIS(distance=ifs.distance.luo_distance), 'Normalized Hamming': methods.ifTOPSIS(distance=ifs.distance.normalized_hamming_distance), } ``` -------------------------------- ### Intuitionistic Fuzzy Set (IFS) Operations Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Demonstrates basic mathematical operations, aggregation, and similarity metrics for Intuitionistic Fuzzy Sets using the IFS class. Requires the IFS class to be defined. ```python # Example Usage: ifs1 = IFS(0.6, 0.2) ifs2 = IFS(0.8, 0.1) # Addition addition_result = ifs1 + ifs2 print("Addition result:", addition_result) # Subtraction subtraction_result = ifs1 - ifs2 print("Subtraction result:", subtraction_result) # Multiplication multiplication_result = ifs1 * ifs2 print("Multiplication result:", multiplication_result) # Division division_result = ifs1 / ifs2 print("Division result:", division_result) # Power power_result = ifs1 ** 2 print("Power result:", power_result) # Intersection intersection_result = ifs1 & ifs2 print("Intersection result:", intersection_result) # Union union_result = ifs1 | ifs2 print("Union result:", union_result) # Complement complement_result = ~ifs1 print("Complement result:", complement_result) # Ordered Weighted Averaging (OWA) Aggregation owa_weights = [0.3, 0.4, 0.3] owa_result = ifs1.owa_aggregation(owa_weights) print("OWA Aggregation result:", owa_result) # Dominance is_dominating = ifs1.dominance(ifs2) print("Is Dominating:", is_dominating) # Jaccard Similarity jaccard_similarity = ifs1.similarity_jaccard(ifs2) print("Jaccard Similarity:", jaccard_similarity) # Fuzzy Relation fuzzy_relation_matrix = ifs1.fuzzy_relation(ifs2) print("Fuzzy Relation Matrix:") print(fuzzy_relation_matrix) ``` -------------------------------- ### IF-COPRAS Method Application Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Applies the IF-COPRAS method with default settings to calculate preferences and rankings. Ensure fuzzy weights and types are defined. ```python if_copras = methods.ifCOPRAS() print(f'Preferences: {if_copras(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_copras.rank()}') ``` -------------------------------- ### ifWPM Class Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/pyifdm.methods.wpm.md The `ifWPM` class provides functionality to calculate preferences and rankings using the Intuitionistic Fuzzy Weighted Product Model. It can be initialized with custom score and normalization functions. ```APIDOC ## Class: pyifdm.methods.if_wpm.ifWPM ### Description Calculates the alternatives preferences and rankings using the Intuitionistic Fuzzy Weighted Product Model. ### Methods #### __call__(matrix, weights, types) Calculates the alternatives preferences. * **Parameters:** * **matrix** (*ndarray*) – Decision matrix / alternatives data. Alternatives are in rows and Criteria are in columns. * **weights** (*ndarray*) – Vector of criteria weights in a crisp or Intuitionistic Fuzzy form. * **types** (*ndarray*) – Types of criteria, 1 profit, -1 cost. Criteria types cannot be all profit or all cost. * **Returns:** Preference calculated for alternatives. Greater values are placed higher in ranking. * **Return type:** ndarray #### __init__(score=, normalization=None) Creates Intuitionistic Fuzzy WPM method object with normalization and score functions. * **Parameters:** * **score** (*callable*, default=chen_score_1) – Function used to calculate score between two IFS. * **normalization** (*callable*, default=None) – Function used to normalize the decision matrix. #### rank() Calculates the alternatives ranking based on the obtained preferences. * **Returns:** Ranking of alternatives. * **Return type:** ndarray ``` -------------------------------- ### Display Ranking Results with Tabulate Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/illustrative_examples.ipynb Print the calculated rankings for each IFDM method in a tabular format using the 'tabulate' library. ```python print(tabulate(np.array(results).T, headers=list(if_methods.keys()))) ``` -------------------------------- ### Additional MCDA Methods Source: https://context7.com/jwieckowski/pyifdm/llms.txt This section covers several additional MCDA methods including ifMABAC, ifMAIRCA, ifMARCOS, ifMOORA, ifOCRA, ifARAS, ifWSM, and ifWPM. These methods share a common interface: instantiate with optional parameters, call with a matrix, weights, and types, and retrieve the ranking using the .rank() method. ```APIDOC ## ifMABACifMAIRCA, ifMARCOS, ifMOORA, ifOCRA, ifARAS, ifWSM, ifWPM — Additional MCDA methods All remaining MCDA methods follow the same callable interface: instantiate with optional normalization/score/distance parameters, call with `(matrix, weights, types)`, retrieve ranking with `.rank()`. ```python from pyifdm.methods import ( ifARAS, ifMABAC, ifMAIRCA, ifMARCOS, ifMOORA, ifOCRA, ifWSM, ifWPM ) import numpy as np matrix = np.array([ [[0.5, 0.3], [0.4, 0.4], [0.6, 0.2], [0.3, 0.5]], [[0.7, 0.2], [0.5, 0.3], [0.4, 0.5], [0.6, 0.3]], [[0.4, 0.4], [0.6, 0.2], [0.5, 0.4], [0.5, 0.4]], [[0.6, 0.3], [0.3, 0.6], [0.7, 0.2], [0.4, 0.5]], [[0.5, 0.4], [0.5, 0.4], [0.5, 0.3], [0.5, 0.3]], ]) weights = np.array([0.25, 0.25, 0.25, 0.25]) types = np.array([1, -1, 1, 1]) results = {} for name, cls in [ ('ARAS', ifARAS()), ('MABAC', ifMABAC()), ('MAIRCA', ifMAIRCA()), ('MARCOS', ifMARCOS()), ('MOORA', ifMOORA()), ('OCRA', ifOCRA()), ('WSM', ifWSM()), ('WPM', ifWPM()), ]: try: pref = cls(matrix, weights, types) results[name] = cls.rank() print(f"{name:8s} ranking: {results[name]}") except Exception as e: print(f"{name:8s} error: {e}") ``` ``` -------------------------------- ### IFS Class Initialization Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/pyifdm.IFS.md Initializes an Intuitionistic Fuzzy Set (IFS) with membership, non-membership, and optional uncertainty values. ```APIDOC ## IFS(membership, non_membership, uncertainty=None) ### Description Initializes an Intuitionistic Fuzzy Set (IFS). Parameters: - membership (float): The degree to which an element belongs to the set. - non_membership (float): The degree to which an element does not belong to the set. - uncertainty (float, optional): The degree of uncertainty in the membership assignment. > If not provided, it is calculated as 1 - membership - non_membership. ``` -------------------------------- ### Apply IF-MABAC Method Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Applies the IF-MABAC method to a decision matrix with fuzzy weights and types. Shows how to obtain preferences and ranking. ```python if_mabac = methods.ifMABAC() print(f'Preferences: {if_mabac(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_mabac.rank()}') ``` -------------------------------- ### Display IF-VIKOR Preference Results Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Prints the preference scores (S vector) calculated by IF-VIKOR for each method and alternative. This table helps in comparing the primary assessment of alternatives. ```python print(tabulate([[name, *np.round(pref[0], 2)] for name, pref in results.items()], headers=['Method'] + [f'A{i+1}' for i in range(matrix.shape[0])])) ``` -------------------------------- ### Apply Various IF-VIKOR Methods Source: https://github.com/jwieckowski/pyifdm/blob/main/examples/examples.ipynb Applies each initialized IF-VIKOR object (with different distance metrics) to the dataset and stores the results. This is used to compare the impact of distance measures on VIKOR outcomes. ```python results = {} for name, function in vikor.items(): results[name] = function(matrix, fuzzy_weights, types) ``` -------------------------------- ### IF-EDAS Method Application Source: https://github.com/jwieckowski/pyifdm/blob/main/docs/example/examples.ipynb Applies the IF-EDAS method with default settings to calculate preferences and rankings. Ensure fuzzy weights and types are defined. ```python if_edas = methods.ifEDAS() print(f'Preferences: {if_edas(matrix, fuzzy_weights, types)}') print(f'Ranking: {if_edas.rank()}') ```