unit 5_1
unit 5_1
AND
EXPERT SYSTEMS (CSE209)
Introduction
Building Expert System using Fuzzy Logic
• Introduction to fuzzy logic
• Fuzzification
• Techniques of Fuzzification
• Defuzzification
• Techniques of Defuzzification
• Rule designing and inferencing, Fuzzy
• Inference System: Mamdani Fuzzy Model and Examples, Larsen Fuzzy
Model, Tsukamoto Fuzzy Model and TSK Fuzzy Model
2
What is Fuzzy Logic?
The 'Fuzzy' word means the things that are not clear or are vague.
Sometimes, we cannot decide in real life that the given problem or
statement is either true or false. At that time, this concept provides
many values between the true and false and gives the flexibility to
find the best solution to that problem.
Characteristics of Fuzzy Logic
1.This concept is flexible and we can easily understand and implement it.
2.It is used for helping the minimization of the logics created by the human.
3.It is the best method for finding the solution of those problems which are suitable for
approximate or uncertain reasoning.
4.It always offers two values, which denote the two possible solutions for a problem and
statement.
5.It allows users to build or create the functions which are non-linear of arbitrary
complexity.
6. In fuzzy logic, everything is a matter of degree.
7.In the Fuzzy logic, any system which is logical can be easily fuzzified.
In the architecture of the Fuzzy Logic system, each component plays an important role.
The architecture consists of the different four components which are given below.
1.Rule Base
2.Fuzzification
3.Inference Engine
4.Defuzzification
1. Rule Base
Rule Base is a component used for storing the set of rules and the If-Then conditions
given by the experts are used for controlling the decision-making systems. There are so
many updates that come in the Fuzzy theory recently, which offers effective methods
for designing and tuning of fuzzy controllers. These updates or developments decreases
the number of fuzzy set of rules.
2. Fuzzification
Fuzzification is a module or component for transforming the system inputs, i.e., it
converts the crisp number into fuzzy steps. The crisp numbers are those inputs which
are measured by the sensors and then fuzzification passed them into the control
systems for further processing. This component divides the input signals into following
five states in any Fuzzy Logic system:
•Large Positive (LP)
•Medium Positive (MP)
•Small (S)
•Medium Negative (MN)
•Large negative (LN)
3. Inference Engine
This component is a main component in any Fuzzy Logic system (FLS), because all the
information is processed in the Inference Engine. It allows users to find the matching degree
between the current fuzzy input and the rules. After the matching degree, this system
determines which rule is to be added according to the given input field. When all rules are
fired, then they are combined for developing the control actions.
4. Defuzzification
Defuzzification is a module or component, which takes the fuzzy set inputs generated by
the Inference Engine, and then transforms them into a crisp value. It is the last step in
the process of a fuzzy logic system. The crisp value is a type of value which is acceptable by
the user. Various techniques are present to do this, but the user has to select the best one
for reducing the errors.
The membership function is a function which represents the graph of fuzzy sets,
and allows users to quantify the linguistic term. It is a graph which is used for
mapping each element of x to the value between 0 and 1.
For the Fuzzy set B, the membership function for X is defined as: μB:X → [0,1]. In
this function X, each element of set B is mapped to the value between 0 and 1.
This is called a degree of membership or membership value.
Fuzzy set operations with example
Techniques of Fuzzification
1.Singleton Fuzzification: Assigns a degree of membership that is 1 for a specific value
and 0 otherwise.
2.Gaussian Fuzzification: Uses a Gaussian curve to map input values to a membership
degree.
3.Trapezoidal and Triangular Fuzzification: Uses trapezoidal or triangular shapes to
define membership functions, providing a linear increase and decrease in the
membership degree.
NOTE: Follow the below Code to implement all fuzzy operations using
python for hands on practice in class
import numpy as np
import skfuzzy as fuzz
import matplotlib.pyplot as plt
# Plotting set A
plt.subplot(2, 2, 1)
plt.plot(x, A, label='Set A', color='blue')
plt.title('Fuzzy Set A')
plt.xlabel('x')
plt.ylabel('Membership Degree')
# Plotting set B
plt.subplot(2, 2, 2)
plt.plot(x, B, label='Set B', color='red')
plt.title('Fuzzy Set B')
plt.xlabel('x')
plt.ylabel('Membership Degree')
plt.subplot(2, 2, 3)
plt.plot(x, A_not, label='NOT A', color='green')
plt.title('Fuzzy NOT A')
plt.xlabel('x')
plt.ylabel('Membership Degree')
import numpy as np
import skfuzzy as fuzz
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 6))
2. Tip to a waiter: Design a fuzzy logic-based system to determine the appropriate tip to be given to a
waiter based on two key inputs: Food Quality and Service Quality. Both inputs are subjective and can
vary between poor, average, and excellent. The system should use fuzzy rules to compute a tip percentage,
taking into account the varying degrees of food and service satisfaction. The aim is to provide a more nuanced
and fair tip calculation, reflecting the overall dining experience rather than relying on rigid tipping percentages.
import numpy as np
import matplotlib.pyplot as plt
import skfuzzy as fuzz
import numpy as np
import skfuzzy as fuzz
# Calculate the degree of membership for the crisp value in each fuzzy set
membership_poor = fuzz.interp_membership(x, poor_service, crisp_value)
membership_average = fuzz.interp_membership(x, average_service, crisp_value)
membership_excellent = fuzz.interp_membership(x, excellent_service, crisp_value)
# Print the degree of membership for the crisp value in each fuzzy set