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

Higher Institute for Applied Sciences

and Technology

5th Year – Informatics

Introduction to Fuzzy Logic

Dr. Waseem SAFI

1
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

2
Course organisation + References
 Final exam 3 points + Mini Project 2 points +
Practical sessions 2 points
 Documents are Allowed
 References
- Book: “An Introduction to Fuzzy Logic and
Fuzzy Sets”
James J. Buckley, Esfandiar Eslami / Springer 2002

- AI and Fuzzy Logic Courses of :


Cambridge, Stanford, MIT.
3
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules
 De-fuzzification

4
Definition and History of Fuzzy Logic
 The opposite word (antonym) of fuzzy is crisp.
Fuzzy means un-clear or ambiguous, blurred and
Crisp means clear, clean, and sharp.

 Definition of fuzzy logic: “A form of knowledge


representation suitable for notions that cannot be
defined precisely, but which depend upon their
contexts”.

5
Definition and History of Fuzzy Logic
 We’re assuming we know what words like “tall”, “very
tall”, “close”, “very close”, “far”, “very far”… While we
might be able to give a clear definition of “long” it won’t
ever match the real world.

 However, to do this, we need to define and use these


terms. For this, we need Fuzzy Sets and Fuzzy Logic.

6
Definition and History of Fuzzy Logic
 Traditional logic: true vs. false
 Language isn’t usually precise…
How hot is “hot”? 30 degrees? 40 degrees?
 Fuzzy Sets let us say something is 90% “one thing”
and 10% “another”, without being illogical.

7
Definition and History of Fuzzy Logic
 Fuzzy logic approximates human reasoning
 It does a good job of balancing the tradeoff between
precision and significance.

8
Definition and History of Fuzzy Logic
 Fuzzy logic Properties:
 Flexible
 Understandable
 Highly suitable method for uncertain or approximate
reasoning
 views inference as a process of propagating elastic
constraints
 Mostly robust as no precise inputs required

9
Definition and History of Fuzzy Logic
 Fuzzy logic Properties:
 Close to the human approach of reasoning (un-clear
or ambiguous, blurred ).
 using linguistic variables (words) more than
precise numbers

10
Definition and History of Fuzzy Logic
 Example 1:

 Example 2:

11
Definition and History of Fuzzy Logic
 1923: “Bertie” Russell releases a paper on
Vagueness. How do we define objects that are partly
in two normally mutually exclusive sets?
• 1937: Black defines Vague sets.
• 1965: Zadeh coins the daft name “Fuzzy” for a logic
based on Vague set membership, instantly putting
humourless scientist’s backs up.
• 1972: 1st practical demonstration Mamdani’s steam
engine.
• 1981: 1st commercial applications using fuzzy logic to
control systems.
• 1994: Japan exported $35 billion worth of fuzzy
products

12
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

13
Definition of fuzzy sets
 Classical set theory:
• a refresher on the classical sets
• 5, 10, 7, 6, 9 is a set of integers.
• 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
is the set of integers between 0 and 10.
• ‘a‘ , ‘b'; ‘c', 'a' is a set of characters.
• "Site", "of", is a set of words.

Concept of belonging:
• the fact that an element is part of a set or not.
• Membership 7 ∈ {6; 7; 9} and non-membership 5 ∉
{2, 6, 7 9}.

14
Definition of fuzzy sets
• We give things a degree of membership between 0
and 1 in several sets (subsets).
• We then label these sets using human terms.

15
Definition of fuzzy sets
• Fuzzy logic is based on the theory of fuzzy sets
(generalization of the classical set theory )

• Theory of fuzzy sets is a generalization of the classical


set theory

• Classical logic is also known as Boolean logic or binary

16
Definition of fuzzy sets

• We give our variables membership functions, and


express the variables as nouns (“length”,
“temperature”) or adjectives (“long”, “hot”).

• We can then build up linguistic equations (“IF length is


long, AND temperature is hot, THEN openWindow”).

17
Definition of fuzzy sets
 X: universe (Set) of discourse (classical set in classical
logic). Fuzzy Set A is defined by
A={μ(x) | x ⋀ x in X}
 where μ(x) is a membership function.
Let X be a set and A a fuzzy subset of X.
A(x) is called the membership degree of x in A.

–For conventional set, the range of μ(x) is {T, F}


–For fuzzy sets, the range of μ(x) is [0,1].
 Examples of fuzzy sets:
- young people, old people, kind people
- temperature : hot, just good, a little bit cold
18
Definition of fuzzy sets
 X: universe of discourse
X={Fabrice, Emmanuel , Gael, Govind, Pierre}

 Fuzzy sets A=“young persons” and B=“Tall


persons” are defined by
–A = 0.4/Fabrice +0.6/Emmanuel +0.8/ Gael +1.0/ Govind +0.9/ Pierre
–B = 0.3/Fabrice +0.5/Emmanuel +0.9/ Gael +0.6/ Govind +0.9/ Pierre

19
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

20
Membership functions
 Membership function of a fuzzy set A:
μA: X  [0,1]
 If the universe of discourse X={x1,x2,...,xN}, A is
described as follows:
A = μA(x1)/x1 + μA(x2)/x2+...+ μA(xN)/xN

21
Membership functions

22
Membership functions
• The height of A h(A) is the upper bound of the domain
of its membership function.
h(A) = sup{μA(x) | x ∈ X }. (Superior )
• Normalized Set: A is normalized if and only if h(A) = 1.
In practice, it is extremely rare to work on non-
normalized fuzzy sets.
• The support of A is the set supp(A):
supp(A) = {x ∈ X | μA(x) > 0}.
• kernel of A is the set of elements of X belonging
entirely to A. kernel(A) = {x ∈ X | μA(x) = 1}.
• An α-cut of A is the classical subset of elements with a
membership degree greater than or equal to α:
α-cut(A) = {x ∈ X | μA(x)≥ α}.
23
Membership functions

24
Membership functions
• Types of membership functions:

 Triangular membership function

 Trapezoidal membership function

 Gaussian membership function

 Sigmoidal membership function

25
Membership functions
 1- Triangular membership function

26
Membership functions
 2- Trapezoidal membership function

27
Membership functions
 Two special cases of Trapezoidal membership:
function

28
Membership functions
 Two special cases of Trapezoidal membership
function

29
Membership functions
 3- Gaussian membership function

30
Membership functions
 4- Sigmoidal membership function

31
Membership functions
 A linguistic variable carries with it the concept of fuzzy
set qualifiers, called hedges.
 Hedges are terms that modify the shape of fuzzy sets.
They include adverbs such as
very,
somewhat,
quite,
more,
less,
slightly,
indeed,
Extremly

32
Membership functions
 Example of Hedges:

33
Membership functions
 Hedges and Mathematical Expressions:
A little [μA(x) ]1.3

Slightly [μA(x) ]1.7

Very [μA(x) ]2

Extremely [μA(x) ]3

Very very [μA(x) ]4

Less [μA(x) ]0.5

SomeWhat [μA(x) ]0.5


Indeed 2*[μA(x) ]2 if 0<= μA(x) <= 0.5
1-2*[1-μA(x) ]2 if 0.5<μA(x)<=1

34
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

35
Operations of fuzzy sets

36
Operations of fuzzy sets
Examples:

37
Operations of fuzzy sets
More Examples:
 The universe of discourse:

X={Fabrice, Emmanuel , Gael, Govind, Pierre}

 Fuzzy sets A=“young persons” and B=“Tall


persons” are defined by
–A = 0.4/Fabrice +0.6/Emmanuel +0.8/ Gael +1.0/ Govind +0.9/ Pierre
–B = 0.3/Fabrice +0.5/Emmanuel +0.9/ Gael +0.6/ Govind +0.9/ Pierre

 The OR and AND of A and B are as follows:


–A∪B=0.4/Fabrice +0.6/Emmanuel +0.9/ Gael +1.0/ Govind +0.9/ Pierre
–A∩B =0.3/Fabrice +0.5/Emmanuel+0.8/ Gael +0.6/ Govind +0.9/ Pierre

38
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

39
Linguistic variables
• Idea: to define fuzzy systems in natural language.
 Let V be a variable (quality of service, tip amount),
 X the range of values of the variable,
 TV a finite or infinite set of fuzzy sets (Linguistic values,
Linguistic sets, Linguistic labels).
A linguistic variable corresponds to the triplet (V, X, TV ).

40
Linguistic variables

41
Linguistic variables

42
Linguistic variables

43
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

44
Fuzzy Rules (Reasoning)
 In classical logic:
If p then q : p true then q true
 In fuzzy logic:
Fuzzy reasoning (approximate reasoning) is based on fuzzy rules.
 Fuzzy rules are expressed in natural language using linguistic
variables.
Premise / Antecedent  Consequent
 If x ∈ A and y ∈ B then z ∈ C, with A, B and C fuzzy sets.
 If (the quality of the food is delicious)
then (tip is high)

45
Fuzzy Rules (Reasoning)
• Example: If (the quality of the food is delicious)
then (tip is high)
The variable 'tip' belongs to the fuzzy set 'high' to a degree that
depends on the degree of validity of the premise (i.e. the
membership degree of the variable 'food quality' to the fuzzy set
'delicious '.)

• The more propositions in premise are checked, the more the


suggested output actions must be applied.

• To determine the degree of truth of the proposition fuzzy 'tip will


be high', we must define the fuzzy implication.

46
Fuzzy Rules (Reasoning)
 Number of Attributes: N
 Number of Rules: K
 The Kth fuzzy Rule:

Where Bk, Fkj: j= 1,2,3,4,5,6…N are linguistic


values.

47
Fuzzy Rules (Reasoning)
2- Fuzzy rules applied to
Fuzzy defuzzfication.: get new sets of members.

1- Inputs converted to 3- These sets are then


degrees of converted back to real
membership of fuzzy numbers.
sets.

48
Fuzzy Rules (Reasoning)
• Fuzzy implication (inference): the
fuzzy system
designer must choose among the wide choice of
fuzzy implications
• Most commonly used are:
Mamdani: min (fa(x); fb(x))
Sugeno : f(x,y)

49
Fuzzy Rules (Reasoning)
• Example: Mamdani Fuzzy implication (min (fa(x); fb(x)) ) :
fuzzy rule: 'If (the food quality is delicious), then (tip is high)‘

50
Fuzzy Rules (Reasoning)
• Example: Mamdani Fuzzy implication (min (fa(x); fb(x)) ) :
• All the rules of a fuzzy system is called the decision matrix.

If the service is bad or the food is awful then the tip is low

If the service is good then the tip is average

If the service is excellent or the food is then the tip is high


delicious

51
Fuzzy Rules (Reasoning)
• Example: Mamdani Fuzzy implication (min (fa(x); fb(x)) ) :
• If (the service is excellent or the food is delicious)
then the tip is high

52
Fuzzy Rules (Reasoning)
• Example: Mamdani Fuzzy implication (min (fa(x); fb(x)) ) :
If the service is bad or the food is awful then the tip is low
If the service is good then the tip is average
If the service is excellent or the food is delicious then the tip is high

commutative

Aggregation

Commutative

53
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication
 IF x is A And y is B THEN z is f(x,y)
 x, y are linguistic variables,
 A, B are fuzzy sets, on universe of discourse X, Y
 F(x,y) is a mathematical function

 F(x,y) is often polynomial

 Zero order Sugeno Model


IF x is A And y is B THEN z is k

54
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication

55
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication

56
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication

57
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication

58
Fuzzy Rules (Reasoning)
• More Examples: Sugeno Fuzzy implication

59
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication

60
Fuzzy Rules (Reasoning)
• Example: Sugeno Fuzzy implication

61
Contents of Lecture
 Course organisation + References
 Definition and History of fuzzy logic
 Definition of fuzzy sets
 Membership functions
 Operations of fuzzy sets
 Linguistic variables
 Fuzzy rules (Reasoning)
 De-fuzzification

62
Fuzzy Rules
2- Fuzzy rules applied to
Fuzzy defuzzfication.: get new sets of members.

1- Inputs converted to 3- These sets are then


degrees of converted back to real
membership of fuzzy numbers.
sets.

63
Defuzzification
Fuzzy defuzzification.:
 The final process of a fuzzy system to set the output (the
final decision).
 Fuzzy to Crisp conversion.
 There are many methods of defuzzfication :
 Mean Of Maxima (MeOM) Maxima
 First Of Maxima
 Last Of Maxima
Methods
 Center Of Gravity (COG) - Centroid Of Area
 Weighted Average method
 Alpha-cut (lambda-cut) method
64
Defuzzification
Fuzzy defuzzification (Mean Of Maxima MeOM):
 MeOM defuzzification's output is the average of the abscissas of the
maxima of the fuzzy set resulting from the aggregation of the implication
results.

65
Defuzzification
Fuzzy defuzzification (Mean Of Maxima MeOM):
 Example

66
Defuzzification
Fuzzy defuzzification (First Of Maxima):

67
Defuzzification
Fuzzy defuzzification (Last Of Maxima):

68
Defuzzification
Fuzzy defuzzification (Center Of Gravity COG - centroid):
 COG defuzzification's output corresponding to the abscissa of the
center of gravity of the surface of the membership function
characterizing the fuzzy set resulting from the aggregation of the
implication results..

69
Defuzzification
Fuzzy defuzzification (Center Of Gravity COG - centroid):
 The area and the center of gravity or centroid of each sub-area is
calculated and then the summation of all these sub-areas is taken to
find the defuzzified value for a discrete fuzzy set.

70
Defuzzification
Fuzzy defuzzification (Center Of Gravity COG - centroid):
 The area and the center of gravity or centroid of each sub-area is
calculated and then the summation of all these sub-areas is taken to
find the defuzzified value for a discrete fuzzy set.

N indicates the number of sub-areas,


Ai and xi : the area and centroid of area, respectively, of ith sub-
area.

71
Defuzzification
Fuzzy defuzzfication (Center Of Gravity COG - centroid):

72
Defuzzification
Fuzzy defuzzfication (Center Of Gravity COG - centroid):

The total area of the sub-area 1 is ½ * 2 * 0.5 = 0.5


The total area of the sub-area 2 is (7-3) * 0.5 = 4 * 0.5 = 2
The total area of the sub-area 3 is ½ * (7.5-7) * 0.2 = 0.5 * 0.5 *0.2 =.05
The total area of the sub-area 4 is 0.5* 0.3 = .15
The total area of the sub-area 5 is 0.5* 0.3 = .15
The total area of the sub-area 6 is ½ *1* 0.3 = .15

73
Defuzzification
Fuzzy defuzzfication (Center Of Gravity COG - centroid):

Centroid of sub-area1 will be (1+3+3)/3 = 7/3 =2.333


Centroid of sub-area2 will be (7+3)/2 = 10/2 = 5
Centroid of sub-area3 will be (7+7+7.5)/3 = 21.5/3 =7.166
Centroid of sub-area4 will be (7+7.5)/2 =14.5/2=7.25
Centroid of sub-are5 will be (7.5+8)/2 =15.5/2 = 7.75
Centroid of sub-area6 will be (8+8+9)/3 = 25/3 = 8.333

74
Defuzzification
Fuzzy defuzzfication (Center Of Gravity COG - centroid):

75
Defuzzification
Fuzzy defuzzfication (Center Of Gravity COG - centroid):

76
Defuzzification
Fuzzy defuzzfication (Weighted Average Method):
 produces results very close to the COA method.
 less computationally intensive
 Each membership function is weighted by its maximum
membership value.

xi indicates the sample element,


n represents the number of elements in the sample.

77
Defuzzification
Fuzzy defuzzfication (Weighted Average Method):
.

78
Defuzzification
• Example: Sugeno Fuzzy implication with Weighted Average Method

79
Defuzzification
• Example: Sugeno Fuzzy implication with Weighted Average Method

80
Defuzzification
• Example: Sugeno Fuzzy implication with Weighted Average Method

81
Defuzzification
Fuzzy defuzzfication (alpha-cut method):

 α-cut(A) = {x ∈ X | μA(x)≥ α}.

82
Defuzzification
Fuzzy defuzzfication (alpha-cut method):

 α-cut properties:

83

You might also like