# Mamdani Fuzzy Inference Method – Example

Mamdani fuzzy inference method we discussed in the previous article, is elaborated here with detailed examples.

Consider the following robot navigation example:

**Example: **

Consider that,

D: The distance from the robot to an object

Î¸: The angle of motion of an object with respect to the robot.

Î´: Deviation with respect to D and Î¸

We assume the range of values of D is [0.1, …. 2.2] in meter and Î¸ is [-90, … , 0, … 90]

Find the deviation of the robot from its position for distance **D = 1.04 **m and angle **Î¸ = 30 ^{o}**

**Solution:**

**Database:**

The database (DB) of the FLC is shown below:

**Distance:**:

- VN : Very Near
- NR : Near
- FR : Far
- VFR : Very Far

**Angle **(angular direction (Î¸) and deviation (Î´)):

- LT : Left
- AL : Ahead Left
- A: Ahead
- AR : Ahead Right
- RT : Right

A graphical representation of the fuzzy membership function is shown here for both inputs (distance and direction) and one output (deviation).

**Rule base:**

The rule base is typically defined by the expert of the domain. For a given instance, we are considering following the rule base.

**Fuzzy linguistic rule : **If *x is D *and *y is Î¸* then *z is Î´*

This rule base has 20 IF-THEN rules:

**Rule 1:**If (D is VN ) and (Î¸ is LT) Then (Î´ is A)**Rule 2:**If (D is VN ) and (Î¸ is AL) Then (Î´ is AR)- .
- .
- .
**Rule 20:**If (D is VF ) and (Î¸ is RT) Then (Î´ is A)

**Fuzzification of inputs:**

Given, **D = 1.04 **m and angle **Î¸ = 30 ^{o}**

For this input, we are to decide the deviation Î´ of the robot as output. First, we need to compute the fuzzy values of crisp inputs using the following fuzzification method.

As we can see in the above diagram, distance D = 1.04 is a member of two fuzzy sets called NR and FR.

Similarly, Angle Î¸ = 30^{0} is a member of two fuzzy sets called A and AR.

So we need to compute the membership value (i.e. fuzzified value) of both inputs in their corresponding fuzzy sets.

Let us find the membership value for D = 1.04 m in NR and FR fuzzy sets. We can easily find the membership value of any crisp input using a similar triangle rule, as shown below:

Similarly, Îŧ_{NR} = 0.6571, Îŧ_{FR} = 0.3429, Îŧ_{A} = 0.3333, Îŧ_{AR} = 0.6667

**Fired Rules:**

Out of 20 rules in the rule base, only four rules will fire.

With a given set of fuzzy variables, we have four different combinations of rules:

- If Distance is NR AND Angle is A Then Deviation is RT
- If Distance is NR AND Angle is AR Then Deviation is A
- If Distance is FR AND Angle is A Then Deviation is AR
- If Distance is FR AND Angle is AR Then Deviation is A

Fired rules are highlighted in the following rule base – which is the intersection of fuzzy sets of D and Î¸:

**Computing strength of fired rules:**

As we know, Îŧ_{NR} = 0.6571, Îŧ_{FR} = 0.3429, Îŧ_{A} = 0.3333, Îŧ_{AR} = 0.6667. Strength (Îą values) of the fired rules:

Îą_{1} = minâĄ(Îŧ_{NR} ,Îŧ_{A} ) = minâĄ(0.6571, 0.3333) = 0.3333

Îą_{2} = minâĄ(Îŧ_{NR} ,Îŧ_{AR} ) = minâĄ(0.6571, 0.6667) = 0.6571

Îą_{1} = minâĄ(Îŧ_{FR} ,Îŧ_{A} ) = minâĄ(0.3429, 0.3333) = 0.3333

Îą_{1} = minâĄ(Îŧ_{FR} ,Îŧ_{AR} ) = minâĄ(0.3429, 0.6667) = 0.3429

The strength of fired rules and their corresponding membership in output for each fuzzy rule is shown in the following figure.

**Aggregation of fuzzy output functions:**

To compute the final crisp value of deviation (Î´) using Mamdani fuzzy inference method, we shall aggregate all fuzzy output functions on the same axis, as we did in defuzzification methods.

We will apply various defuzzification methods to this aggregated output function to find the final crisp value.

## Watch on YouTube: Mamdani Fuzzy Inference Method

**Defuzzification:**

The equation to compute of some standard shapes is shown below:

Area: (ab) / 2

Center: 2a/3

Area: ab

Center: (a_{1} + a_{2}) / 2

Area: 1/2 (a + b) Ã h

Center: (b_{1} + b_{2}) / 2

**Center of Sums Method:**

Defuzzification using Center of Sums (CoS) method can be derived as follow:

**Center of Gravity Method:**

Defuzzification using the Center of Gravity (CoG) method can be derived as follow:

The area and center of each region are depicted in the following figure:

**Middle of Maxima Method:**

Defuzzification using the Maxima method can be derived as follow:

Middle of maxima returns the middle of the area having the highest membership value

For this, x^{â} = 0

Hi, thanks for writing a good article. I have a question about defuzzification step by using Center of Sum (CoS). From the formula that you wrote above, the centroid of trapezoidal shape of rule 1 is equal to 71. When I recheck your data, I got 67.5. Did I do it wrong? Please correct me if I wrong. Thanks.

Thanks for your words. Can you please email me your complete solution at [email protected] plz? That will help me to cross verify the solution i designed.

The entire video playlist is also available on Fuzzy logic: Click for Playlist