Advanced AI: Fuzzy TOPSIS
Tags: ai, fuzzytopsis, beginners
Published: 2023-03-07 16:23:43

The Fuzzy TOPSIS (Technique for Order Preference by Similarities to Ideal Solution) is a decision-making approach used to select the best alternative among a set of options by considering multiple criteria simultaneously. It uses fuzzy logic to handle the uncertainty and imprecision of the data and allows for both quantitative and qualitative criteria to be incorporated into the decision-making process. Fuzzy TOPSIS ranks the alternatives based on their similarity to the ideal solution and the distance from the negative ideal solution, ultimately providing a comprehensive ranking of the alternatives. It is commonly used in fields such as engineering in the domains of artificial intelligence, decision-making, and pattern recognition, handling imprecise or uncertain information and modeling human reasoning processes. It is also highly used in the sectors of management, and environmental studies.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yz5yvm789e2tjtedcbcm.png)

As we have seen earlier, Fuzzy TOPSIS is a combination of two concepts which are: Fuzzy set theory and TOPSIS (Technique for Order Preference by Similarities to Ideal Solution).

## Now, What is Fuzzy Set?

> Fuzzy sets, introduced independently by Lotfi A. Zadeh and Dieter Klaua in 1965 is a mathematical concept used in fuzzy logic to represent a set of elements that have degrees of membership or belongingness to the set. 

Unlike classical or crisp sets, which have elements that are either fully in or fully out of the set, fuzzy sets allow for elements to have partial membership in the set based on their degree of similarity to the set's defining characteristics.

In a fuzzy set, the membership function assigns a degree of membership between 0 and 1 to each element of the universe of discourse, indicating the extent to which the element belongs to the fuzzy set. 

### Defination
the fuzzy set Ã in terms of its membership function μÃ(x) and the universe of discourse X is defined as:

`Ã = {x, μÃ(x) | x ⋲ X}`

The notation {x, μÃ(x) | x ⋲ X} represents the set of ordered pairs (x, μÃ(x)) for all x in the universe of discourse X, where μÃ(x) is the degree of membership of x in the fuzzy set Ã. In other words, for each element x in the universe of discourse X, the membership function μÃ(x) assigns a degree of membership between 0 and 1, indicating the degree to which x belongs to the fuzzy set Ã


The specific form of the membership function μÃ(x) would depend on the problem being modeled and the characteristics of the elements in the universe of discourse X. Different types of membership functions, such as triangular, trapezoidal, or Gaussian functions, can be used to represent different types of fuzzy sets. 

### Example code
Here is an example code for implementing Fuzzy TOPSIS algorithm in Python:

```

import numpy as np

def fuzzy_topsis(X, w):
    # Normalize the decision matrix
    X_norm = X / np.sqrt(np.sum(X**2, axis=0))
    
    # Compute the weighted normalized decision matrix
    X_weighted = X_norm * w
    
    # Determine the positive and negative ideal solutions
    X_max = np.max(X_weighted, axis=1)
    X_min = np.min(X_weighted, axis=1)
    
    # Compute the separation measures from the ideal solutions
    S_max = np.sqrt(np.sum((X_weighted - X_max[:, np.newaxis])**2, axis=1))
    S_min = np.sqrt(np.sum((X_weighted - X_min[:, np.newaxis])**2, axis=1))
    
    # Compute the relative closeness to the ideal solutions
    C = S_min / (S_max + S_min)
    
    return C

```