Fuzzy Logic - cs.umanitoba.ca · –Fuzz Inference Mechanism –Fuzzy Knowledge Base...

Post on 25-Feb-2021

8 views 0 download

Transcript of Fuzzy Logic - cs.umanitoba.ca · –Fuzz Inference Mechanism –Fuzzy Knowledge Base...

Fuzzy Logic

Dr. Chi-Tai, Cheng

Outline

• What is Fuzzy Logic?

• History and applications of Fuzzy Logic

• Fuzzy Control– Fuzzification– Fuzz Inference Mechanism– Fuzzy Knowledge Base

– Defuzzification

• Hand calculation of Fuzzy Control

• Paper of Fuzzy Control

What is Fuzzy Logic?

• Traditional logic system: (Crisp set)– Item does or doesn’t belong to a group

(1, 0)• Human• Sports

Not Human

Human Hockey Basketball

What is Fuzzy Logic?

• Fuzzy logic system:– Degree of a set [1, 0]

• Cold/Hot• Rich/Poor• Teenager/

What is Fuzzy Logic?

Traditional logic system

Characteristic function

1

0

1

0

Fuzzy logic systemMembership function

What is Fuzzy Logic?

• Example: • Input: Angle of Shoot, Distance of

Shoot• Output: Chance of Success

Small Normal Big

Close Normal Good Chance

Good Chance

Normal No Chance Normal Good Chance

Far No Chance No Chance Normal

History and applications of Fuzzy Control

• Fuzzy logic was first proposed by Lotfi A. Zadeh of the University of California at Berkeley in a 1965 paper.

• Mid-1980, “ inverted pendulum” experiment.

History and applications of Fuzzy Control

History and applications of Fuzzy Control

ZE PS PBNB

NS

History and applications of Fuzzy Control

• When can we use Fuzzy Control?

History and applications of Fuzzy Control

• Fuzzy and Probability

History and applications of Fuzzy Control

• For continuous values [0, 1]• For big and complicate problem• For no explicit define math problem• For human language - linguistic

variables

Jacky’s Assignment

Fuzzy set

AA offunction pmemebershi ],1 ,0[X: →µ

setfuzzy ,}X|))( ,{( ∈= xxxA Aµ

membership of degree ],1 ,0[)( ∈xAµ1

0

Teenager :A

13 1911 21

Fuzzy set

• Support set

• Core

• Crossover point

• Height 0

13 1911 21

}X ,0)(|{Supp ∈∀>= xxxA Aµ

}X ,1)(|{Core ∈∀== xxxA Aµ

5.0)( =xµ

)(max)(HeightX

xA Ax

µ∈

=

1Teenager :A

α-cut sets

• α-cut sets1] [0,, ,set Universal:X ∈= α F(X)A

}X ,)(|{ ∈∀≥= xxxA A αµα

0

1

<∉≥∈

=))(( 0

))(( 1)(

αµαµ

χα

αα xAxif

xAxifx

A

AA

0.5 =α

Membership function

• Discrete membership function• Continuous membership function

– Triangular shape– Trapezoid– S function– Z function– Pi function– Bell shape

Discrete membership function

Triangular shape

≤≤≤

≤≤≤

=−−−−

xbfor

bxafor

axafor

axfor

xabxb

aaax

A

1

1

1

1

0

0

)(

1

1

1

1

µ

0

1

a1 a b1

Trapezoid

≤≤≤≤≤≤≤

=

−−

−−

xbfor

bxbfor

bxafor

axafor

axfor

x

bbxb

aaax

A

1

1

1

1

0

1

0

)(

1

1

1

1

µ

0

1

a1 a b b1

S function

• monotonical increasing

≤≤≤−≤≤

=−−

−−

xfor

xfor

xfor

xfor

xSx

x

γγββα

α

γβααγγ

αγα

1

)(21

)(2

0

),,;(2

2

Z function

≤≤≤≤≤−

=−−

−−

xfor

xfor

xfor

xfor

xZx

x

γγββα

α

γβααγγ

αγα

0

)(2

)(21

1

),,;(2

2

Pi function

≥++−≤−−

=Πγβγγγγγγβγ

γβ β

β

xforxS

xforxSx

) , , ;(1

) , , ;(),;(

2

2

Bell shape

bA

acx

x 2

1

1)(

−+=µ

c

1

Relation

• Binary relational matrix• Example: Standard weight

60 70 80 90

150 1 0 0 0

160 0 1 0 0

170 0 0 1 0

180 0 0 0 1

60 70 80 90

150 1 0.6 0.2 0

160 0.6 1 0.6 0.2

170 0.2 0.6 1 0.6

180 0 0.2 0.6 1

Traditional logic Fuzzy logic

Traditional Logic Operate

• Brothers & Classmates

Brother Classmates

}David Carl, Bill, Albert,{=A}Grand ,Foster ,Eason{=B

Eason

Foster

Grand

Albert

0 1 0

Bill 0 0 1

Carl 0 0 0

David

1 0 0

Eason

Foster

Grand

Albert

0 1 1

Bill 0 1 0

Carl 1 0 1

David

1 1 0

Traditional Logic Operate - Union

• Relationship for who are brothers OR classmates (Union) => max(A, B)

Eason

Foster

Grand

Albert 0 1 0Bill 0 0 1Carl 0 0 0David 1 0 0

Eason

Foster

Grand

Albert

0 1 1Bill 0 1 0Carl 1 0 1David 1 1 0

∪ =Eason Foster Grand

Albert 0 1 1

Bill 0 1 1

Carl 1 0 1

David 1 1 0

Traditional Logic Operate - Intersection

• Relationship for who are brothers AND classmates (Intersection) => min(A, B)

Eason

Foster

Grand

Albert 0 1 0Bill 0 0 1Carl 0 0 0David 1 0 0

Eason

Foster

Grand

Albert

0 1 1Bill 0 1 0Carl 1 0 1David 1 1 0

∩ =Eason Foster Grand

Albert 0 1 0

Bill 0 0 0

Carl 0 0 0

David 1 0 0

Fuzzy Logic Operate

• B Higher & Heavier than A

Higher Heavier

}David Carl, Bill, Albert,{=A

}Grand ,Foster ,Eason{=B

Eason

Foster

Grand

Albert

0.8 0 0.9

Bill 1 0.8 1

Carl 0.1 0 0.7

David

0.7 0 0.8

Eason

Foster

Grand

Albert

0.4 0.9 0.3

Bill 0 0.4 0

Carl 0.9 0.5 0.8

David

0.6 0.7 0.5

Fuzzy Logic Operate - Union

• Relationship for B are higher OR heavier (Union) => max(A, B)

Eason

Foster

Grand

Albert 0.8

0 0.9

Bill 1 0.8

1

Carl 0.1

0 0.7

David 0.7

0 0.8

Eason

Foster

Grand

Albert 0.

40.9

0.3

Bill 0 0.4

0

Carl 0.9

0.5

0.8

David 0.

60.7

0.5

∪ =Eason Foster Grand

Albert 0.8 0.9 0.9

Bill 1 0.8 1

Carl 0.9 0.5 0.8

David 0.7 0.7 0.8

Fuzzy Logic Operate - Intersection

• Relationship for B are higher AND heavier (Union) => min(A, B)

Eason

Foster

Grand

Albert 0.8

0 0.9

Bill 1 0.8

1

Carl 0.1

0 0.7

David 0.7

0 0.8

Eason

Foster

Grand

Albert 0.

40.9

0.3

Bill 0 0.4

0

Carl 0.9

0.5

0.8

David 0.

60.7

0.5

=Eason Foster Grand

Albert 0.4 0 0.3

Bill 0 0.4 0

Carl 0.1 0 0.7

David 0.6 0 0.5

Composition operationComposition operation

• ExampleJerry} Ister, {Harry,=A

Mickey} Luffy, {Kalman,=B

}Lab {Hockey,C =

Harry

Ister Jerry

Kalman

0.8 0 0.3

Luffy 0.6 0.9 0.9

Mickey

0 0.2 1

Hockey

Lab

Harry 0.9 0

Ister 0.2 0.4

Jerry 0.7 0.9

Composition operationComposition operation

• Where will we meet Kalman, Luffy and Mickey tomorrow?

Harry

Ister Jerry

Kalman

0.8 0 0.3

Luffy 0.6 0.9 0.9

Mickey

0 0.2 1

Hockey

Lab

Harry 0.9 0

Ister 0.2 0.4

Jerry 0.7 0.9

Hockey

Lab

Kalman

0.8 0.3

Luffy 0.7 0.9

Mickey 0.7 0.9

Fuzzy Control

Fuzzy Inference Mechanism

Fuzzification Defuzzification

Fuzzy Knowledge Base

Controlled system

Crisp

Process Output Actual Control

CrispFuzzyTerms

FuzzyTerms

Fuzzy Control

• Fuzzification• Fuzzy Knowledge Base• Fuzzy Inference Mechanism• Defuzzification

Fuzzification

• Fuzzification transforms crisp values into grades of membership for linguistic terms of fuzzy sets.– Example: Shooting Success Rate : input

1->Angle

Fuzzy Knowledge Base

• Use linguistic variables to build the IF-THEN rules in Fuzzy Knowledge Base.

• Example: Shooting Success Rate Knowledge

Base

Distance

Close Normal Far

Angle

Small NormalNo

Chance

NoChanc

e

Normal

GoodChance

NormalNorma

l

BigGood

ChanceGood

Chance

GoodChanc

e

Fuzzy Inference Mechanism

• Combines the fuzzy terms obtained from the fuzzification with the rule base and data base

• Min-Max2222121

21212111

1

Bis THEN Y A is X AND A is X IF:R Bis THEN Y A is X AND A is X IF:R

1X

1X 2X

2X

Y

Y

Y

111 A is x

121 A is x

212 A is x

222 A is x

1 Bis y

2 Bis y*B

Defuzzification – Crisp Value

• Weighted Average Defuzzification

∑∑ ⋅

=

ii

ii

i

w

wmu*

Defuzzification – Fuzzy Set

• Center of Gravity DefuzzificationDiscrete Continuous

∑∑ ⋅

=

ii

iii

x

xxu

)(

)(*

µ

µ

∫∫ ⋅

=

x

x

dxx

xdxx

u)(

)(

µx

x*

µ

Defuzzification

0.80.50.4

1 2 3 Output

1

94.14.08.05.0

4.038.025.01 =++

×+×+×

Defuzzification

0.80.50.4

1 2 3 Output

1

94.14.08.05.0

4.038.025.01 =++

×+×+×

Center of Gravity Defuzzification

∑∑

∑∑∑∑

∑∑∑∑

⋅=

=⋅

=−⋅

=⋅−⋅

=⋅−

=⋅

)(

)(

)()(

0)()(

0)()(

0)()(

0)(CoG)-(

x

xxCoG

xCoGxx

xCoGxx

xCoGxx

xCoGx

xx

µµ

µµ

µµ

µµ

µ

µ

Example

KnowledgeBase

Distance

Close Normal Far

Angle

Small NormalNo

Chance

NoChanc

e

Normal

GoodChance

NormalNorma

l

BigGood

ChanceGood

Chance

GoodChanc

e

NormalGoodChanc

e

NoChanc

e

0.5 10

Input 1: Shooting Angle

Input 2: Shooting Distance

Output:Shooting Success Rate

• Use Shooting Angle and Shooting Distance to calculate the Shooting Success Rate for Ice Hockey

Example

Input 1: Shooting Angle

• Input 1: Shooting Angle

Example

Input 2: Shooting Distance

• Input 2: Shooting Distance

Example

• Knowledge Base

KnowledgeBase

Distance

Close Normal Far

Angle

Small Normal NoChance

NoChanc

e

Normal

GoodChance Normal Norma

l

Big GoodChance

GoodChance

GoodChanc

e

Knowledge Base

If Angle is Small and Distance is Close then output = NormalIf Angle is Small and Distance is Normal then output = No ChanceIf Angle is Small and Distance is Far then output = No ChanceIf Angle is Normaland Distance is Close then output = Good ChanceIf Angle is Normal and Distance is Normal then output = NormalIf Angle is Normal and Distance is Far then output = NormalIf Angle is Big and Distance is Close then output = Good ChanceIf Angle is Big and Distance is Normal then output = Good ChanceIf Angle is Big and Distance is Far then output = Good Chance

Example

• Angle = 20, Distance = 90. Output is ?

• Angle = 20, Distance = 81. Output is ?

– (Use Weighted Average Defuzzification)

Angle = 20, Distance = 90

If Angle is Small and Distance is Close then output = NormalIf Angle is Small and Distance is Normal then output = No ChanceIf Angle is Small and Distance is Far then output = No ChanceIf Angle is Normaland Distance is Close then output = Good ChanceIf Angle is Normal and Distance is Normal then output = NormalIf Angle is Normal and Distance is Far then output = NormalIf Angle is Big and Distance is Close then output = Good ChanceIf Angle is Big and Distance is Normal then output = Good ChanceIf Angle is Big and Distance is Far then output = Good Chance

Angle = 20, Distance = 90

Angle “20” is 20% degrees of Small Set and 80% degrees of Normal Set

Distance “90” is 100% degrees of Normal Set

Angle = 20, Distance = 90

4.08.02.0

5.08.002.0 =+

×+×=output

Angle = 20, Distance = 81

458.01.09.01.02.0

11.05.09.05.01.002.0 =+++

×+×+×+×=output

Quiz

• Angle = 15, Distance = 99

A Fuzzy Logic Controller for Car-like Mobile Robots

• Input:– curvature, position error and orientation

error

• Output:– speed and direction

Input - Curvature

Input - Position error

Input - Orientation error

Output - Speed

Output - Direction

Rules

• straightLine & zeroDisp & zeroAngle– Fast & straight

• straightLine & zeroDisp & posHighAngle– Medium speed & sharpLeft

• leftCircle & posLowDisp &negLowAngle– Medium speed & lowLeft

Reference

• http://www4.cs.umanitoba.ca/~jacky/Teaching/Courses/COMP_4180-IntelligentMobileRobotics/current/index.php• Ching-Chang Wong, 2010 Fuzzy Control class, TKU, Taiwan.• http://en.wikipedia.org/wiki/Fuzzy_control_system