Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Sakshi Talele

Rugved shinde
20101A0009
20101A0012 INFT
INFT VII VII
Data Science lab
Data Science Lab

Program No. 03

Problem To study and implement a fuzzy controller for restaurant tip.


Statement
Literature
What is Fuzzy Logic?
Fuzzy Logic (FL) is a method of reasoning that resembles human
reasoning. The approach of FL imitates the way of decision making in
humans that involves all intermediate possibilities between digital
values YES and NO.
The conventional logic block that a computer can understand takes
precise input and produces a definite output as TRUE or FALSE, which
is equivalent to human’s YES or NO.
The inventor of fuzzy logic, Lotfi Zadeh, observed that unlike
computers, the human decision making includes a range of
possibilities between YES and NO, such as −
CERTAINLY
YES
POSSIBLY
YES
CANNOT SAY
POSSIBLY NO
CERTAINLY
NO
The fuzzy logic works on the levels of possibilities of input to achieve
the definite output.

Fuzzy Logic Systems Architecture


It has four main parts as shown −
• Fuzzification Module − It transforms the system inputs,
which are crisp numbers, into fuzzy sets. It splits the input
signal into five steps such as –

LP x is Large Positive
MP x is Medium Positive

S x is Small

MN x is Medium Negative

LN x is Large Negative
• Knowledge Base − It stores IF-THEN rules provided by
experts.
• Inference Engine − It simulates the human reasoning
process by making fuzzy inference on the inputs and IF-
THEN rules.
• Defuzzification Module − It transforms the fuzzy set
obtained by the inference engine into a crisp value.

The membership functions work on fuzzy sets of variables.

Membership Function
Membership functions allow you to quantify linguistic term and
represent a fuzzy set graphically. A membership function for a
fuzzy set A on the universe of discourse X is defined as μA:X → [0,1].
Here, each element of X is mapped to a value between 0 and 1. It is
called membership value or degree of membership. It quantifies the
degree of membership of the element in X to the fuzzy set A.

Algorithm
• Define linguistic Variables and terms (start)
• Construct membership functions for them. (start)
• Construct knowledge base of rules (start)
• Convert crisp data into fuzzy data sets using membership
functions. (fuzzification)
• Evaluate rules in the rule base. (Inference Engine)
• Combine results from each rule. (Inference Engine)
• Convert output data into non-fuzzy values. (defuzzification)
Applications Automotive Systems

• Automatic Gearboxes
• Four-Wheel Steering
• Vehicle environment control
Consumer Electronic Goods

• Hi-Fi Systems
• Photocopiers
• Still and Video Cameras
• Television
For this particular experiment let us consider a restaurant tipping
system:
Let’s create a fuzzy control system which models how you might
choose to tip at a restaurant. When tipping, you consider the
service and food quality, rated between 0 and 10. You use this to
leave a tip of between 0 and 25%.
We would formulate this problem as:
• Antecednets (Inputs)
o service
▪ Universe (ie, crisp value range): How good was the
service of the wait staff, on a scale of 0 to 10?
▪ Fuzzy set (ie, fuzzy value range): poor, acceptable,
amazing
o food quality
▪ Universe: How tasty was the food, on a scale of 0 to
10?
▪ Fuzzy set: bad, decent, great
• Consequents (Outputs)
o tip
▪ Universe: How much should we tip, on a scale of 0%
to 25%
▪ Fuzzy set: low, medium, high
• Rules
o IF the service was good or the food quality was good,
THEN the tip will be high.
o IF the service was average, THEN the tip will be
medium.
o IF the service was poor and the food quality was poor
THEN the tip will be low.
• Usage
o If I tell this controller that I rated:
▪ the service as 9.8, and
▪ the quality as 6.5,
o it would recommend I leave:
▪ a 20.2% tip.

Program Code import numpy as np


import skfuzzy as fuzz
from skfuzzy import control as ctrl

quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')


service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')

quality.automf(3)
quality['poor'].view()
service.automf(3)
service['average'].view()

tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])


tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])
tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])
tip.view()

rule1 = ctrl.Rule(quality['poor'] | service['poor'],


tip['low'])
rule2 = ctrl.Rule(quality['average'] | service['average'],
tip['medium'])
rule3 = ctrl.Rule(service['good'] | quality['good'],
tip['high'])

rule1.view()

tipping_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])


tipping = ctrl.ControlSystemSimulation(tipping_ctrl)
tipping.input['quality'] = 6.5
tipping.input['service'] = 9.8
tipping.compute()

print( tipping.output['tip'])
tip.view(sim=tipping)

Execution Input:
tipping.input['quality'] = 6.5
tipping.input['service'] = 9.8

Output:

You might also like