Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fuzzy Logic Steve Foster.

Similar presentations


Presentation on theme: "Fuzzy Logic Steve Foster."— Presentation transcript:

1 Fuzzy Logic Steve Foster

2 Introduction Today we will be discussing Fuzzy Logic
What is fuzzy logic? The difference between crisp and fuzzy logic Making a decision using fuzzy logic Programming AI using fuzzy logic

3 Fuzzy Logic Historical Origins:
Derived from fuzzy set theory Developed by Prof. Lotfi Zadeh at the University of California, Berkeley in 1965 Fuzzy set theory is in contrast to traditional (“crisp”) set theory Traditional set theory: An object either belongs to a set or not. Fuzzy set theory: An object can “partially belong” to a set Example: To classify people into two sets: Tall and Short In traditional set theory, an arbitrary cut-off is set at, say, 6 feet. Any person taller than 6 feet is in the Tall set. Any person less than or equal to 6 feet is in the Short set. In fuzzy set theory, for example, a person taller than 6’2” is considered to be 100% in the Tall set, a person at 5’11” is considered to have 20% membership in the Tall set etc. Fuzzy logic often mimics real life Can be used to improve the rules used in FSM

4 Fuzzy Set Membership Traditional Set Theory: An object is either a member of a set or not a member of a set Fuzzy Set Theory: An object is either in a set, not in a set, or partially in a set This is denoted by a number from 0.0 to 1.0 Membership number m of Object A in Set S: m = 0.0 means that Object A is not in Set S 0.0 < m < 1.0 means that Object A is partially in Set S, for example m = 0.2 means that Object A is 20% in Set S, a rather weak membership m = 1.0 means that Object A is completely in Set S

5 Membership Functions To determine an object’s membership value in a set, refer to membership functions of the object’s attribute(s) For example, we may define our membership functions for the three sets Short, Medium and Tall Attribute is height An object whose height is 1.55m would be a 0.25 member of Short, a 0.75 member of Medium, and a 0.0 member (i.e. non-member) of Tall Membership 1.0 Short Medium Tall 0.5 0.0 Height (meters) 1.55

6 Crisp Logic Operations
B A and B 1 We consider set operators AND, OR and NOT Remember traditional (crisp) logic: Represent TRUE as 1, FALSE as 0 We then have the truth tables to the right For example, look at the third line in the first table. It says that if Statement A is True, and Statement B is false, then the Statement “A and B” must be fals A B A or B 1 A not A 1

7 Fuzzy Logic Operations
NOT: If Fuzzy Statement A is m true, then the statement “Not A” is (1.0 – m) true (where m is a number between 0.0 and 1.0 inclusive) Equivalent Set Theory operation: If an object A has m membership in Fuzzy Set S, then it must have membership (1.0 – m) in Fuzzy Set Not-S AND: If Fuzzy Statement A is m true, and Fuzzy Statement B is n true, then the Fuzzy Statement “A and B” is k true, where k = min(m,n) (Here, m, n and k are numbers between 0.0 and 1.0 inclusive) OR: If Fuzzy Statement A is m true, and Fuzzy Statement B is n true, then the Fuzzy Statement “A or B” is k true, where k = max(m,n) (Here, m, n and k are numbers between 0.0 and 1.0 inclusive)

8 Rules Crisp rule: Fuzzy rule:
Example: “If Self is Tall and Enemy is Short, then Attack.” The Condition of a Rule: The condition for this rule is: “If Self is Tall and Enemy is Short” To check the condition is easy, just check self for membership in the set Tall, and enemy for membership in the set Short. Suppose that Self is not Tall, then the decision is to not attack. Fuzzy rule: The condition of the rule once again is: “If Self is Tall and Enemy is Short” Suppose that Self is 0.3 Tall, and Enemy is 0.6 Short, then this condition is 0.3 True. So, should we attack?

9 Making a Decision We can simply decide the arbitrary cut-off to be 0.5. If a condition is at least 0.5 true, then perform the action. In the preceding example, the condition is only 0.3 true, so the decision is to not attack Or, we can make a random decision with the probability equal to the value of the condition. In the preceding example, attack with the probability 0.3

10 Making a Decision Most of the time, there are many rules For example:
Rule 1: If Self is Tall and Enemy is Short, then Attack. Rule 2: If Self is Big and Enemy is small, then Attack. Rule 3: If Self’s Power is greater than 10, and Self’s Health is greater than 5, then Attack. In this case, there are a few options to make a decision whether to attack or not. Option 1: Take the majority decision. For the example above: If at least two of the above conditions are at least 0.5, then Attack. Otherwise don’t attack. Option 2: Take the average. For the example above: If condition 1 is 0.6, condition 2 is 0.6, and condition 3 is 0.0, then the average is is less than 0.5, so the decision is not to attack. Option 3: Make a random decision with the probability equal to the average.

11 Using Fuzzy Logic In Games
You can use fuzzy logic in games in a variety of ways For example, you can use fuzzy logic to control bots or other non-player character units You can also use it for assessing threats posed by players It can be used for classification E.g. Classifying a player as poor / average / elite

12 Fuzzy Game Example Suppose we are programming a simple AI system for monsters within a game Things happen in the game world that the monsters must react to E.g. Health After being damaged, should the monster fight or run-away? Change to a defensive stance? With only one variable a simple if-else system would be fine As more variables are introduced the system becomes more and more complex

13 Fuzzy Game Example Using two variables, we may have the following system: DetermineAction() { if (health < 10) if(ammo < 5) return ESCAPE if(ammo >= 5 && ammo < 20) return CAUTIOUS else return NORMAL } else if (health >= 10 && health < 20) if(ammo < 5) return CAUTIOUS if(ammo >= 5 && ammo < 20) return NORMAL else return ATTACK else if(ammo < 5) return NORMAL if(ammo >= 5 && ammo < 20) return ATTACK else return FULL_ATTACK

14 A Fuzzy Game System As more variables are added, the if-else system becomes un-manageable A fuzzy system is much simpler Output needed: Three possible states called Escape, Defence and Attack. Input to system: Ammunition, Health, Enemies in sight Start with Ammunition Three states Low, Medium and High Make a table with the behaviour we want for the monster Low Medium High Ammo Escape Defence Attack

15 A Fuzzy Game System We know that:
Low = Escape Medium = Defence High = Attack So we can map these output functions to each level

16 A Fuzzy Game System We could then added more attributes to the system
By combining the fuzzy output of each attribute we can generate an appropriate action Low Medium High Health Escape Defence Attack Many Some Few Enemies in sight Escape Defence Attack

17 A Fuzzy Game System Some inputs might be more important than others
To handle this you can assign a coefficient for some inputs, so their weight will be more or less than the others Low Medium High Ammo 1.5 Escape Defence Attack


Download ppt "Fuzzy Logic Steve Foster."

Similar presentations


Ads by Google