You are on page 1of 45

Fuzzy Logic

Dr Alexiei Dingli

What is fuzzy logic?

Definition of fuzzy

Fuzzy not clear, distinct, or precise; blurred

Definition of fuzzy logic

A form of knowledge representation suitable for notions

that cannot be defined precisely, but which depend upon


their contexts.

Formal Definition

Fuzzy logic provides a method to formalize reasoning


when dealing with vague terms. Traditional
computing requires finite precision which is not
always possible in real world scenarios. Not every
decision is either true or false, or as with Boolean
logic either 0 or 1. Fuzzy logic allows for membership
functions, or degrees of truthfulness and falsehoods.
Or as with Boolean logic, not only 0 and 1 but all the
numbers that fall in between.

TRADITIONAL REPRESENTATION
OF LOGIC

bool speed;
get the speed
if ( speed == 0) {
// speed is slow
}
else {
// speed is fast
}

Better (Fuzzy Representation)

For every problem


must represent in
terms of fuzzy sets.

Slowest
[ 0.0 0.25 ]

Slow

What are fuzzy sets?

[ 0.25 0.50 ]

Fast
[ 0.50 0.75 ]

Fastest
[ 0.75 1.00 ]

Representing Fuzzy Sets


float speed;
get the speed
if ((speed >= 0.0)&&(speed < 0.25)) {
// speed is slowest
}
else if ((speed >= 0.25)&&(speed < 0.5))
{
// speed is slow
}
else if ((speed >= 0.5)&&(speed < 0.75))
{
// speed is fast
}
else // speed >= 0.75 && speed < 1.0
{
// speed is fastest
}

ORIGINS OF FUZZY LOGIC

The idea behind fuzzy logic dates back to Plato, who


recognized not only the logic system of true and false, but
also an undetermined area the uncertain.
In the 1960s Lotfi A. Zadeh Ph.D,. University of California,
Berkeley, published an obscure paper on fuzzy sets. His
unconventional theory allowed for approximate information
and uncertainty when generating complex solutions; a
process that previously did not exist.
Fuzzy Logic has been around since the mid 60s but was not
readily excepted until the 80s and 90s. Although now
prevalent throughout much of the world, China, Japan and
Korea were the early adopters

Crisp (Traditional) Variables


Crisp variables represent precise quantities:
x = 3.1415296
A {0,1}

A proposition is either True or False


ABC

King(Richard) Greedy(Richard) Evil(Richard)


Richard is either greedy or he isn't:
Greedy(Richard) {0,1}

Fuzzy Sets

What if Richard is only somewhat greedy?


Fuzzy Sets can represent the degree to which a quality is possessed.
Fuzzy Sets (Simple Fuzzy Variables) have values in the range of [0,1]
Greedy(Richard) = 0.7
Question: How evil is Richard?

Fuzzy Linguistic Variables

Fuzzy Linguistic Variables are used to represent qualities


spanning a particular spectrum

Temp: {Freezing, Cool, Warm, Hot}


Membership Function

Question: What is the temperature?


Answer: It is warm.
Question: How warm is it?

Membership Functions
Temp: {Freezing, Cool, Warm, Hot}
Degree of Truth or "Membership"
1

Freezing

Cool

Warm

Hot

30

50

70

90

0
10

Temp. (F)

110

Membership Functions
How cool is 36 ?

Freezing

Cool

Warm

Hot

30

50

70

90

0
10

Temp. (F)

110

Membership Functions
How cool is 36 F ?
It is 30% Cool and 70% Freezing
Freezing

Cool

Warm

Hot

50

70

90

0.7
0.3
0
10

30

Temp. (F)

110

Fuzzy Logic

How do we use fuzzy membership functions in


predicate logic?
Fuzzy logic Connectives:
Fuzzy Conjunction,
Fuzzy Disjunction,
Operate on degrees of membership in fuzzy sets

Fuzzy Disjunction

AB = max(A, B)
AB = C "Quality C is the disjunction of Quality A and B"
B

A
1

1
0.75

0.375

(AB = C) (C = 0.75)

Fuzzy Conjunction

AB = min(A, B)
AB = C "Quality C is the conjunction of Quality A and B"
B

A
1

1
0.75

0.375

(AB = C) (C = 0.375)

Example: Fuzzy Conjunction

Calculate AB given that A is .4 and B is 20


B

A
1

.1 .2 .3 .4 .5 .6 .7 .8 .9

1 5 10 15 20 25 30 35 40

Example: Fuzzy Conjunction

Calculate AB given that A is .4 and B is 20


B

A
1

.1 .2 .3 .4 .5 .6 .7 .8 .9

1 5 10 15 20 25 30 35 40

Determine degrees of membership:

Example: Fuzzy Conjunction

Calculate AB given that A is .4 and B is 20


B

A
1

0.7

.1 .2 .3 .4 .5 .6 .7 .8 .9

1 5 10 15 20 25 30 35 40

Determine degrees of membership:


A = 0.7

Example: Fuzzy Conjunction

Calculate AB given that A is .4 and B is 20


B

A
1

0.9
0.7

.1 .2 .3 .4 .5 .6 .7 .8 .9

1 5 10 15 20 25 30 35 40

Determine degrees of membership:


A = 0.7 B = 0.9

Example: Fuzzy Conjunction

Calculate AB given that A is .4 and B is 20


B

A
1

0.9
0.7

.1 .2 .3 .4 .5 .6 .7 .8 .9

1 5 10 15 20 25 30 35 40

Determine degrees of membership:


A = 0.7 B = 0.9
Apply Fuzzy AND
AB = min(A, B) = 0.7

Fuzzy Control

Fuzzy Control combines the use of fuzzy linguistic


variables with fuzzy logic
Example: Speed Control
How fast am I going to drive today?
It depends on the weather

Disjunction of Conjunctions

Inputs: Temperature
Temp: {Freezing, Cool, Warm, Hot}
1

Freezing

Cool

Warm

Hot

30

50

70

90

0
10

Temp. (F)

110

Inputs: Temperature, Cloud Cover


Temp: {Freezing, Cool, Warm, Hot}
1

Freezing

Cool

Warm

Hot

30

50

70

90

0
10

110

Temp. (F)

Cover: {Sunny, Partly, Overcast}


Partly Cloudy

Sunny

Overcast

0
0

20

40

60

Cloud Cover (%)

80

100

Output: Speed

Speed: {Slow, Fast}

Fast

Slow

0
0

25

50

75

Speed (mph)

100

Rules

If it's Sunny and Warm, drive Fast


Sunny(Cover)Warm(Temp) Fast(Speed)
If it's Cloudy and Cool, drive Slow
Cloudy(Cover)Cool(Temp) Slow(Speed)
Driving Speed is the combination of output of these
rules...

Example Speed Calculation

How fast will I go if it is


65 F
25 % Cloud Cover ?

Fuzzification:
Calculate Input Membership Levels
65 F Cool = 0.4, Warm= 0.7
1

Freezing

Cool

Warm

Hot

30

50

70

90

0
10

110

Temp. (F)

25% Cover Sunny = 0.8, Cloudy = 0.2


Partly Cloudy

Sunny

Overcast

0
0

20

40

60

Cloud Cover (%)

80

100

...Calculating...

If it's Sunny and Warm, drive Fast


Sunny(Cover)Warm(Temp)Fast(Speed)

0.8 0.7 = 0.7


Fast = 0.7
If it's Cloudy and Cool, drive Slow
Cloudy(Cover)Cool(Temp)Slow(Speed)

0.2 0.4 = 0.2


Slow = 0.2

Defuzzification:
Constructing the Output

Speed is 20% Slow and 70% Fast


1

Fast

Slow

0
0

25

50

75

100

Speed (mph)

Find centroids: Location where membership is 100%

2/9/2004

Fuzzy Logic

30

Defuzzification:
Constructing the Output

Speed is 20% Slow and 70% Fast


1

Fast

Slow

0
0

25

50

75

100

Speed (mph)

Find centroids: Location where membership is 100%


100% Slow = 25
100% Fast = 75

Defuzzification:
Constructing the Output

Speed is 20% Slow and 70% Fast


1

Fast

Slow

0
0

25

50

75

100

Speed (mph)

Speed = weighted mean = (20*25+...

Defuzzification:
Constructing the Output

Speed is 20% Slow and 70% Fast


1

Fast

Slow

0
0

25

50

75

100

Speed (mph)

Speed = weighted mean


= (20*25+70*75)/(20 + 70)
= 63.8 mph
2/9/2004

Fuzzy Logic

33

Notes: Follow-up Points

Fuzzy Logic Control allows for the smooth interpolation


between variable centroids with relatively few rules
This does not work with crisp (traditional Boolean) logic
Provides a natural way to model some types of human
expertise in a computer program

FUZZY LOGIC IN CONTROL SYSTEMS

Fuzzy Logic provides a more efficient and resourceful


way to solve Control Systems.

Some Examples

Temperature Controller

Anti Lock Break System ( ABS )

TEMPERATURE CONTROLLER

The problem

A temperature control system has four settings

Cold, Cool, Warm, and Hot

Humidity can be defined by:

Change the speed of a heater fan, based on the room


temperature and humidity

Low, Medium, and High

Using this we can define


the fuzzy set

ANTI LOCK BREAK SYSTEM ( ABS )

Nonlinear and dynamic in nature


Inputs for Intel Fuzzy ABS are derived from

Brake
4 WD
Feedback
Wheel speed
Ignition

Outputs
Pulsewidth
Error lamp

Structure of Controller

Fuzzification
Scales and maps input variables to fuzzy sets
Inference Mechanism
Approximate reasoning
Deduces the control action
Defuzzification
Convert fuzzy output values to control signals

Rule Base

Air Temperature

Fan Speed

Set cold {50, 0, 0}


Set cool {65, 55, 45}
Set just right {70, 65, 60}
Set warm {85, 75, 65}
Set hot {, 90, 80}

Set stop {0, 0, 0}


Set slow {50, 30, 10}
Set medium {60, 50, 40}
Set fast {90, 70, 50}
Set blast {, 100, 80}

Rules

Air Conditioning Controller Example:


IF Cold then Stop
If Cool then Slow
If OK then Medium
If Warm then Fast
IF Hot then Blast

Fuzzy Air Conditioner


0
100
90
80

s
Bla

If Hot
then
Blast

Fa
s

If Warm
then
Fast

70
60
50
40

If Just Right
then
Medium

Med
ium

IF Cool
then
Slow

Sl

ow

30
if Cold
then Stop

20

o
St

10

t
Ho

ar
W

Jus
Rig t
ht

ld

Co

Co
ol

0
45

50

55

60

65

70

75

80

85

90

Mapping Inputs to Outputs

Notes: Drawbacks to Fuzzy logic

Requires tuning of membership functions

Fuzzy Logic control may not scale well to large or


complex problems
Deals with imprecision, and vagueness, but not
uncertainty

CONCLUSION

Fuzzy logic provides an alternative way to represent

linguistic and subjective attributes of the real world in


computing.

It is able to be applied to control systems and other


applications in order to improve the efficiency and

simplicity of the design process.

Questions?

You might also like