You are on page 1of 24

CS-481:Artificial Intelligence

Lecture 19
Fuzzy Logic System: The tipping problem

By: Dr. Saima Hassan


Asst. Professor, Institute of Computing
KUST
Discussion Agenda

• Topic: Fuzzy Logic System

• Introduction
• Example: The tipping problem
Fuzzy Logic
 A computational paradigm that is based on how humans think

Fuzzy Logic looks at the world in imprecise terms, in much the same way
that our brain takes in information (e.g. temperature is hot, speed is slow),
then responds with precise actions.
The human brain can reason with uncertainties, vagueness, and judgments.
Computers can only manipulate precise valuations. Fuzzy logic is an attempt
to combine the two techniques.
FL is in fact, a precise problem-solving methodology.
Fuzzy Logic
 A technique that facilitates the control of a complicated system without
knowledge of its mathematical description.

Fuzzy logic differs from classical logic in that statements are no longer black
or white, true or false, on or off. In traditional logic an object takes on a
value of either zero or one. In fuzzy logic, a statement can assume any real
value between 0 and 1, representing the degree to which an element belongs
to a given set.
History of Fuzzy Logic

Professor Lotfi A. Zadeh


https://www.cs.berkeley.edu/~zadeh/

In 1965, Lotfi A. Zadeh of the University of California at Berkeley published


"Fuzzy Sets," which laid out the mathematics of fuzzy set theory and, by
extension, fuzzy logic. Zadeh had observed that conventional computer logic
couldn't manipulate data that represented subjective or vague ideas, so he created
fuzzy logic to allow computers to determine the distinctions among data with
shades of gray, similar to the process of human reasoning.
History of Fuzzy Logic
20 years later after its conception
Interest in fuzzy systems was sparked by Seiji Yasunobu and Soji Miyamoto of
Hitachi, who in 1985 provided simulations that demonstrated the superiority of
fuzzy control systems for the Sendai railway. Their ideas were adopted, and fuzzy
systems were used to control accelerating and braking when the line opened in
1987.

Introduction of FL in the Engineering world (1990’s)

Fuzzy Logic is one of the most talked-about technologies to hit the embedded
control field in recent years. It has already transformed many product markets in
Japan and Korea, and has begun to attract a widespread following In the United
States. Industry watchers predict that fuzzy technology is on its way to becoming a
multibillion-dollar business.
Sample Applications
For washing machines, Fuzzy Logic control is almost becoming a
standard feature

Fuzzy logic washing machines are gaining popularity. These machines


offer the advantages
of performance, productivity, simplicity, productivity, and less cost.

fuzzy logic controls the washing process, water intake, water


temperature, wash time, rinse performance, and spin speed.

https://www.samsung.com/in/support/home-appliances/what-is-fuzzy-logic-in-a-washing-machine/
Basic Tipping Problem
To illustrate the value of fuzzy logic, examine both linear(non-
fuzzy) and fuzzy approaches to the following problem:

What is the right amount to tip your waitperson?

The Basic Tipping Problem:

Given a number between 0 and 10 that represents the quality of


service at a restaurant what should the tip be?
Basic Tipping Problem: Non Fuzzy approach
Let suppose an average tip for a meal is 15%, though the actual amount can
vary depending on the quality of the service provided.
Begin with the simplest possible relationship. Suppose that the tip always equals
15% of the total bill.

What about quality of service?


Basic Tipping Problem: Non Fuzzy approach
Since service is rated on a scale from 0 through 10, you can increase the
tip linearly from 5% if the service is bad to 25% if the service is excellent.
Now the relation looks like the following plot:.

Tip = linearly proportional to service from 5% to 25%


tip = 0.20/10*service+0.05

What about quality of the food?


Building System with the
MATLAB Fuzzy Logic Toolbox
The MATLAB fuzzy logic toolbox facilitates the development of
fuzzy-logic systems using:
 graphical user interface (GUI) tools Graphical User Interface (GUI) Tools

 command line functionality


Fuzzy GUI tools
 The FIS Editor handles the high-level issues for the system:
 How many input and output variables?
 What are their names?
 The Membership Function Editor is used to define the shapes of all
the membership functions associated with each variable.
 The Rule Editor is for editing the list of rules that defines the
behaviour of the system.
 The Rule Viewer and the Surface Viewer are used for looking at, as
opposed to editing, the FIS. They are strictly read-only tools.
 The Rule Viewer is a MATLAB based display of the fuzzy inference diagram
shown at the end of the last section. Used as a diagnostic, it can show (for
example) which rules are active, or how individual membership function shapes
are influencing the results.
 The Surface Viewer is used to display the dependency of one of the outputs on
any one or two of the inputs.
Basic Tipping Problem: Fuzzy approach

Golden rules for tipping:


1. IF the service is poor OR the food is rancid, THEN
tip is cheap (5%).
2. IF the service is good,
THEN tip is average (15%).
3. IF the service is excellent OR the food is delicious,
THEN tip is generous (25%).
Basic Tipping Problem: Fuzzy Logic Tool Box
 Start the toolbox:
Basic Tipping Problem: Fuzzy Logic Tool Box
FIS Editor
Basic Tipping Problem: Fuzzy Logic Tool Box
 The FIS Editor displays general information about a fuzzy inference
system. There is a simple diagram at the top that shows the names of
each input variable on the left, and those of each output variable on
the right.

 Below the diagram is the name of the system and the type of inference
used. The default, Mamdani-type inference, is what we'll continue to
use for this example.

 Below the name of the fuzzy inference system, on the left side of the
figure, are the pop-up menus that allow you to modify the various
pieces of the inference process.

 On the right side at the bottom of the figure is the area that displays the
name of either an input or output variable, its associated membership
function type, and its range.
Basic Tipping Problem: Fuzzy Logic Tool Box
FIS Editor
Basic Tipping Problem: Fuzzy Logic Tool Box
Membership Function Editor
Basic Tipping Problem: Fuzzy Logic Tool Box
Rule Editor
Basic Tipping Problem: Fuzzy Logic Tool Box
Rule Viewer
Basic Tipping Problem: Fuzzy Logic Tool Box
Surface Viewer
Exercise - Conclusions
• Your system is now “complete” and ready to be tested.

1. Try to save the system to your home directory. When you save a fuzzy system to disk, you're saving an ASCII text
FIS file representation of that system with the file suffix .fis. If you do not save your FIS to your disk, but only
save it to the MATLAB workspace, you will not be able to recover it for use in a new MATLAB session.
2. Use the Rule Viewer to test your system with different inputs.
3. Think again about the input and output fuzzy sets. Try to change the shapes and ranges of each (or some) of the
sets to see how this will affect the output.
4. Try to add a new input financial status to the system, which describes the financial status of the customer: ranging
from 0 for poor, to 10 for rich.
5. Think about the new rules you need to construct and add the new rules to the system (e.g. poor financial status 
cheap tip, rich financial status  generous tip).
6. See how the output is now affected by the new input.
Practice using Python and Matlab

 https://pythonhosted.org/scikit-
fuzzy/auto_examples/plot_tipping_problem_newapi.html
 https://www.mathworks.com/help/fuzzy/building-systems-with-fuzzy-logic-
toolbox-software.html

 https://pythonhosted.org/scikit-
fuzzy/auto_examples/plot_tipping_problem_newapi.html
Thankyou

You might also like