Top Banner
CSCE 420-500 Introduction to AI Fuzzy Logic 1 Fuzzy Logic Today’s class: No notes, but the following are useful resources: http://www.seattlerobotics.org/Encoder/mar98/fuz/flindex.html http://www.cs.cmu.edu/Groups/AI/html/faqs/ai/fuzzy/part1/faq.html http://plato.stanford.edu/entries/logic-fuzzy/ Objectives: Broaden FOL treatment in R&N. Given a description of a set of behaviors and their fuzzy input and output sets, combine the behaviors using the centroid of area and centroid of largest area methods. Be able to evaluate fuzzy rules with conjunctions, disjunctions, and negations
27

Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

May 20, 2018

Download

Documents

dinhquynh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

CSCE 420-500 Introduction to AI Fuzzy Logic 1

Fuzzy Logic •  Today’s class:

No notes, but the following are useful resources: http://www.seattlerobotics.org/Encoder/mar98/fuz/flindex.html

http://www.cs.cmu.edu/Groups/AI/html/faqs/ai/fuzzy/part1/faq.html

http://plato.stanford.edu/entries/logic-fuzzy/

•  Objectives: –  Broaden FOL treatment in R&N. –  Given a description of a set of behaviors and their fuzzy input

and output sets, combine the behaviors using the centroid of area and centroid of largest area methods.

–  Be able to evaluate fuzzy rules with conjunctions, disjunctions, and negations

Page 2: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Lofti Zadeh

CSCE 420 Introduction to AI 2

Page 3: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Fuzzy Logic •  What if the precise value of the vector output

wasn’t important? –  The opposite of “precise” is “fuzzy”

•  Turn HARD_RIGHT instead of -90 deg

•  Go FAST instead of 0.8*Vmax

•  This may be more natural, more linguistic

How do we generate and combine outputs like HARD_RIGHT and SOFT_LEFT?

CSCE 420 Introduction to AI 3

Page 4: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

General Procedure •  Generate fuzzy outputs (Fuzzification)

–  Usually have perception operations that yields a “crisp” number that is then converted to a fuzzy input (fuzzified)

•  Apply fuzzy rules (Fuzzy Rules) –  The control logic has rules to convert the the fuzzy input

into a fuzzy output

•  Combine fuzzy outputs (Defuzzification) –  When multiple components produce fuzzy outputs, they

have to be converted to a single “crisp” number

CSCE 420 Introduction to AI 4

Page 5: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Motivating Example: Swerving Robot

•  “Swerve” is a runaway behavior that doesn’t let the robot turn more than 90 degrees from current direction – Vdir: [0,90] – Closer the robot, the harder the turn to

the right •  Robot velocity is same (for simplicity)

CSCE 420 Introduction to AI 5

Page 6: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Linguistic-based rules •  Swerve 1 (from sensor 1)

–  If an obstacle is close, take a HARD RIGHT

•  Swerve 2 (from sensor 2) –  If an obstacle is far, take a SOFT RIGHT

CSCE 420 Introduction to AI 6

Page 7: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Fuzzy Sets: Domain

CSCE 420 Introduction to AI 7

0

1

0 10 Crisp domain: PROXIMITY

Distance from robot

Deg

ree

of m

embe

rshi

p CLOSE

CLOSE is a fuzzy set over the domain

Page 8: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Fuzzy Sets: Multiple Sets

CSCE 420 Introduction to AI 8

0

1

0 10 Crisp domain: PROXIMITY

Distance from robot

CLOSE

Notes: •  Fuzzy sets often overlap -- that’s seen as a Good Thing

•  Set can have different shapes (lines, trapezoids, sigmoids)

FAR

Deg

ree

of m

embe

rshi

p

Page 9: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Membership Functions

CSCE 420 Introduction to AI 9

0

1

0 10 Crisp domain: PROXIMITY

Distance from robot

CLOSE

If robot is 3 meters from obstacle, it has a membership in CLOSE of 0.7 and a membership in FAR of 0.3

MCLOSE(3)=0.7 MFAR(3)=0.3

FAR

3

Deg

ree

of m

embe

rshi

p

Page 10: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Back to Swerve

CSCE 420 Introduction to AI 10

•  Perceptual schema is a tuple –  membership function for the fuzzy variable PROXIMITY

•  MCLOSE(x), MFAR(X)

PS MS PROXIMITY

Page 11: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Fuzzy Rules

CSCE 420 Introduction to AI 11

Motor Schema might be expressed as rule(s):

If PROXIMITY is CLOSE TURN is HARD_RIGHT

Fuzzy rule

If PROXIMITY is FAR TURN is SOFT_RIGHT Fuzzy rule

Page 12: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Fuzzy Output Variable

CSCE 420 Introduction to AI 12

0

1

0 90 Crisp domain: TURN Distance for robot to

turn to the right

Deg

ree

of m

embe

rshi

p SOFT_RIGHT HARD_RIGHT

Page 13: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Strength

CSCE 420 Introduction to AI 13

Motor Schema might be expressed as rule(s):

If PROXIMITY is CLOSE TURN is HARD_RIGHT

If PROXIMITY is FAR TURN is SOFT_RIGHT

MCLOSE(3)=0.7

MFAR(3)=0.3

MHARD_RIGHT=0.7

MSOFT_RIGHT=0.3

Page 14: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Resulting Membership

CSCE 420 Introduction to AI 14

0

1

0 90 Crisp domain: TURN Distance for robot to

turn to the right

Deg

ree

of m

embe

rshi

p SOFT_RIGHT HARD_RIGHT

MSOFT_RIGHT=0.3

Page 15: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Resulting Membership

CSCE 420 Introduction to AI 15

0

1

0 90 Crisp domain: TURN Distance for robot to

turn to the right

Deg

ree

of m

embe

rshi

p SOFT_RIGHT HARD_RIGHT

MSOFT_RIGHT=0.3 MHARD_RIGHT=0.7

Page 16: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Defuzzification •  Now we have an output that is a fuzzy variable,

but we need to convert it to a crisp value to actually send the motor commands.

•  Several alternatives: –  Take Centroid (along Crisp axis) of Blended Area –  Take Centroid of Largest Area –  Weighted Means in area of overlap

CSCE 420 Introduction to AI 16

Page 17: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Defuzzification: Blended Centroid

CSCE 420 Introduction to AI 17

0

1

0 90 Crisp domain: TURN Distance for robot to

turn to the right

Deg

ree

of m

embe

rshi

p SOFT_RIGHT HARD_RIGHT

C =MA (X)X∫MA (X)∫

C ≈174.63.2

= 54.6

Page 18: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

There can be some problems…

CSCE 420 Introduction to AI 18

0

1

-90 0 90

And where would the centroid be?

Consider Centroid of Largest Area (CLA)

Consider the output of an avoid…

Page 19: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Defuzzification: Largest Centroid

CSCE 420 Introduction to AI 19

0

1

0 90 Crisp domain: TURN Distance for robot to

turn to the right

Deg

ree

of m

embe

rshi

p SOFT_RIGHT HARD_RIGHT

C =MA (X)X∫MA (X)∫

C ≈ 61.7

Page 20: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Defuzzification: Weighted Means

CSCE 420 Introduction to AI 20

0

1

0 90 Crisp domain: TURN Distance for robot to

turn to the right

Deg

ree

of m

embe

rshi

p SOFT_RIGHT HARD_RIGHT

C = 0.3(18) + 0.7(72) = 55.8

18 72

0.3

0.7

Page 21: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Back to Swerve

CSCE 420 Introduction to AI 21

•  And so we get an answer!

PS MS

PROXIMITY

Vdir=54.6

Vmagr=1

Dist=3m

SOFT_RIGHT=0.3

HARD_RIGHT=0.7

Page 22: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Back to Swerve

CSCE 420 Introduction to AI 22

•  And so we get an answer!

PS MS

PROXIMITY

Vdir=54.6

Vmagr=1

Dist=3m

SOFT_RIGHT=0.3

HARD_RIGHT=0.7

Fuzzify Apply Rules Defuzzify

Page 23: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Conjunction, Disjunction, Negation and Hedges

If PROXIMITY is CLOSE AND OPEN is RIGHTSIDE TURN is HARD_RIGHT

If PROXIMITY is CLOSE AND OPEN is LEFTSIDE TURN is HARD_LEFT

If PROXIMITY is FAR AND OPEN is RIGHTSIDE TURN is SOFT_RIGHT

If PROXIMITY is FAR AND OPEN is LEFTSIDE TURN is SOFT_LEFT

If PROXIMITY is CLOSE AND NOT (OPEN is RIGHTSIDE OR OPEN is LEFTSIDE)

TURN is VERY HARD_RIGHT CSCE 420 Introduction to AI 23

Page 24: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Evaluation •  A AND B is minimum(A, B)

–  PROXIMITY is CLOSE= 0.7 –  OPEN IS RIGHTSIDE= 0.3 –  If PROXIMITY is CLOSE AND OPEN is RIGHTSIDE= 0.3

•  A OR B is maximum(A, B) –  PROXIMITY is CLOSE= 0.7 –  OPEN IS RIGHTSIDE= 0.3 –  If PROXIMITY is CLOSE OR OPEN is RIGHTSIDE= 0.7

•  NOT A is 1-A –  OPEN is RIGHTSIDE=0.2 –  NOT OPEN is RIGHTSIDE=1-0.2=0.8

(1.0 is full membership for our examples) CSCE 420 Introduction to AI 24

Page 25: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Example If PROXIMITY is CLOSE AND NOT (OPEN is

RIGHTSIDE OR OPEN is LEFTSIDE)

Where OPEN is RIGHTSIDE=0.1 OPEN is LEFTSIDE=0.15 PROXIMITY is CLOSE=0.95

CSCE 420 Introduction to AI 25

Page 26: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Hedges

CSCE 420 Introduction to AI 26

If PROXIMITY is CLOSE AND NOT (OPEN is RIGHTSIDE OR OPEN is LEFTSIDE)

TURN is VERY HARD_RIGHT

OPEN is RIGHTSIDE=0.1 OPEN is LEFTSIDE=0.15 PROXIMITY is CLOSE=0.95

Moves the fuzzy set over 0

1 HARD_RIGHT

Page 27: Fuzzy Logic - Texas A&M Universityrobotics.cs.tamu.edu/dshell/cs625/ai-fuzzy-logic.pdfFuzzy Logic • What if the precise value of the vector output wasn’t important? – The opposite

Summary •  Many packages have fuzzy logic: Java, MATLAB

•  Fuzzy works by –  Fuzzification of crisp values –  Application of rules, each of which has a strength –  Defuzzification output of rules to produce a crisp output

•  Problems include –  Results may not be what was expected –  The number and shape of sets impact behavior

CSCE 420 Introduction to AI 27