gate-561 1 reactive behavior modeling fuzzy logic (gate-561) dr.Çağatay ÜndeĞer instructor...

34
1 GATE-561 Reactive Behavior Modeling Fuzzy Logic (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer Engineering & General Manager SimBT Inc. e-mail : [email protected] Game Technologies Program – Middle East Technical University – Fall 2009

Upload: kristian-carroll

Post on 18-Dec-2015

222 views

Category:

Documents


2 download

TRANSCRIPT

1GATE-561

Reactive Behavior ModelingFuzzy Logic(GATE-561)

Dr.Çağatay ÜNDEĞER

InstructorMiddle East Technical University, GameTechnologies

Bilkent University, Computer Engineering

&

General ManagerSimBT Inc.

e-mail : [email protected]

Game Technologies Program – Middle East Technical University – Fall 2009

2GATE-561

Outline• Introduction to Reactive Behaviors• Fuzzy Logic

3GATE-561

Reactive Behaviors

• A simple decision is taken immediately depending on the developing situation

• For instance,– Lying down when someone is shooting at

you– Breaking when the car in front of you

breaks

4GATE-561

Reactive Behaviors

• Reactive agents:– Simple reflex agents– Reflex agents with internal state

5GATE-561

Simple Reflect Agents

• In each step:– Gets a set of percepts (current state)

Learn “what the world I sense now is like”

– Performs rule matching on current state – Takes decision without memorizing the past

Answer “what action I should do now” by using condition-action rules

– Performs the selected action/sChange the environment

6GATE-561

Reflect Agents with Int. State

• In each step:– Gets a set of percepts (current state)

Learn “what the world I sense now is like”

– Integrates past state to current state to get an enriched current state (internal state)

Keep track of the world and estimate “what the world is like now”

– Performs rule matching on current state – Takes decision

Answer “what action I should do now” by using condition-action rules

– Performs the selected action/sChange the environment

7GATE-561

Reactive Behavior Modeling

Inputs:Internal / CurrentState Variables

p1 a1

p2 a2

p3 a3 Outputs:Decisions /

ActionsAn ordinary table

A complex reactive algorithm

Decision Process

8GATE-561

Fuzzy Logic

• A form of multi-valued logic – Derived from fuzzy set theory – To deal with reasoning that is approximate

rather than precise.

• Since it takes some inputs and gives some immediate outputs– It can be used to model reactive behaviors.

9GATE-561

Traditional Logic vs Fuzzy Logic

• Traditional logic:– Manipulates “crisp sets”.– A crisp set is a set for which a given

element either belongs to the set or it doesn’t.

– Therefore the degree of truth of a statement is either 0 or 1.

• Fuzzy logic:– Has membership values between 0 and 1.

10GATE-561

Traditional Logic vs Fuzzy Logic

• A crisp set:– Does not give us “How much” something is

in a set,– Works fine for black-and-white scenarios,

which are not very common in real world.

11GATE-561

Traditional Logic vs Fuzzy Logic

• Assume that we make a set of all tall people.• If we decide that 1.8 meters is tall,

– We will have a function that • Returns 1,

–If a person is above 1.8 meters and• Returns 0,

–Otherwise.• Saying that “a people with 1.79 meters height

is not tall” will surely be silly.

12GATE-561

Representation in Fuzzy Logic

• In fuzzy logic,– We will represent “how tall a person is” with

a continuous function.

1

1.8 m1.65 m

Tall

Height

13GATE-561

Representation in Fuzzy Logic

• In fuzzy logic,– We will represent “a person that is about

1.65 m tall” with a continuous function.

1

1.65 m1.6 m

About 1.65 m tall

Height1.7 m

14GATE-561

Fuzzy Logic Operations

• We can use operations in fuzzy logic:– AND, OR, NOT

• Defined as the minimum, maximum, and complement;

• Called the Zadeh operators. • So for the fuzzy variables x and y:

– NOT x = (1 - truth(x))– x AND y = minimum(truth(x), truth(y))– x OR y = maximum(truth(x), truth(y))

15GATE-561

Fuzzy Logic Operations

• AND Operation

1

1.8 m1.65 m

Tall

Height

1.7 m1. 6 m

About 1.65 m tall

AND

16GATE-561

Fuzzy Logic Operations

• OR Operation

1

1.8 m1.65 m

Tall

Height

1.7 m1. 6 m

About 1.65 m tall

OR

17GATE-561

Fuzzy Logic Operations

• NOT Operation

1

1.8 m1.65 m

Tall

Height

1.7 m1. 6 m

NOT Tall

18GATE-561

Fuzzy Control

• Rules are usually expressed in the form:– IF variable IS property THEN action

• A simple temperature regulator that uses a fan might look like this:– IF temperature IS very cold THEN stop fan– IF temperature IS cold THEN turn down fan– IF temperature IS normal THEN maintain level– IF temperature IS hot THEN speed up fan

19GATE-561

Defuzzification

• There is no "ELSE“• All of the rules are evaluated,

– Since the temperature might be "cold" and "normal" at the same time to different degrees.

• All matching rules are considered together weighted with their trueness – Using a defuzzification method.

20GATE-561

Car Driving Sample

• We want to:– Model a road traffic– Have cars:

• Follow each other on a lane,• Speed up or slow down realistically.

21GATE-561

Car Driving Sample

• We have two linguistic variables:– Distance between this car and the one in

front of this.– Distance deviation between this car and

the one in front of this.• If space is growing

–Have positive distance deviation• If space is shrinking

–Have negative distance deviation• Otherwise

–Have zero distance deviation

22GATE-561

Some of the Rules

• If distance deviation is zero and distance is about 2 cars length,– Maintain current speed

• If distance deviation is negative and distance is less than 2 cars length,– Slow down

• If distance deviation is positive and distance is greater than 2 cars length,– Speed up

23GATE-561

Complete Rule Table

Distance

Distance Deviation

Shrinking Fast

Shrinking Stable Growing Growing Fast

Very small Brake hard Brake hard Slow down Slow down Maintain speed

Small Brake hard Slow down Slow down Maintain speed

Speed up

Normal (2 cars length)

Slow down Slow down Maintain speed

Speed up Speed up

Large Slow down Maintain speed

Speed up Speed up Floor it

Very large Maintain speed

Speed up Speed up Floor it Floor it

24GATE-561

Definition of Distance

Distance Fuzzy set

Very small Less than 1 car length

Small About 1 car length

Normal About 2 cars length

Large About 3 cars length

Very large More than 3 cars length

25GATE-561

Definition of DistanceDistance Fuzzy set

Very small Less than 1 car length

Small About 1 car length

Normal About 2 cars length

Large About 3 cars length

Very large More than 3 cars length

1

2xl1xl

Normal

distance3xl

Small LargeVery Small

Very Large

0

26GATE-561

Definition of Distance Deviation

Distance Deviation Fuzzy set

Shrinking fast High negative

Shrinking Less than zero

Stable About zero

Growing Greater than zero

Growing fast High positive

27GATE-561

Definition of Distance Deviation

Distance Deviation Fuzzy set

Shrinking fast High negative (half of car’s speed less)

Shrinking Less than zero

Stable About zero

Growing Greater than zero

Growing fast High positive (half of car’s speed more)

1

0-1/2xs

Stable

distancedeviation1/2xs

Shrinking GrowingShrinking

FastGrowing

Fast

0

28GATE-561

Definition of Action

Action Fuzzy set

Brake hard Speed = Speed/2

Slow down Speed = Speed*2/3

Maintain speed Do nothing

Speed up Speed = Speed*4/3

Floor it Speed = Speed*2

29GATE-561

Definition of ActionAction Fuzzy set

Brake hard Speed = Speed/2

Slow down Speed = Speed*2/3

Maintain speed Do nothing

Speed up Speed = Speed*4/3

Floor it Speed = Speed*2

1

None1/2xs

MaintainSpeed

Action

2xs

Slow Down

Speed Up

BreakHard Floor it

04/3xs2/3xs

30GATE-561

Sample Values

• Distance = 1.4 m• Distance Deviation = + 0.15 of current speed

31GATE-561

Sample Values On Fuzzy Sets

1

2xl1xl

Normal

distance3xl

Small LargeVery Small

Very Large

1.4xl

0.25

0.12

1

0-0.5xs

Stable

distancedeviation0.5xs

Shrinking GrowingShrinking

FastGrowing

Fast

0.15

0.6

0.1

32GATE-561

Matching Rules

Distance

Distance Deviation

Shrinking Fast

Shrinking Stable Growing Growing Fast

Very small Brake hard Brake hard Slow down Slow down Maintain speed

Small Brake hard Slow down Slow down (0.1)

Maintain speed (0.25)

Speed up

Normal (2 cars length)

Slow down Slow down Maintain speed (0.1)

Speed up

(0.12)

Speed up

Large Slow down Maintain speed

Speed up Speed up Floor it

Very large Maintain speed

Speed up Speed up Floor it Floor it

0.1 0.6

0.12

0.25

degree of trueness = min of both

33GATE-561

Defuzzification of Matching Rules

• There are many available defuzzification methods

• Center of mass calculation on the fuzzy set areas can be used

1

1/2xs

MaintainSpeed

action2xs

Slow Down

Speed Up

BreakHard Floor it

0

%25 = max(0.25, 0.1)%10 %12

Center-of-mass1.1 x speed

34GATE-561

Fuzzy Logic Usage

• Can be used in many applications that requires to emulate a human expert