Download presentation

Presentation is loading. Please wait.

1
**Fuzzy Logic Driven Agent Behavior**

Prof. Dr. Taoufik Nouri The primary text for the course is Ref.[1]

2
**Fuzzy Logic Goal: Master How the raven is using fuzzy logic.**

Prof. Dr. Lotfi Zadeh father of Fuzzy Logic

3
**Fuzzy Sets Fuzzy Variable IQ Ryan with IQ=115 Є Clever with m = 0.75**

Є Average with m = 0.25 m is membership coefficient Fuzzy Variable: Distance to Target

4
**Fuzzy Set Operators Average AND Clever OR = + Average OR Clever NOT**

NOT Clever

5
Definition A fuzzy set is defined by a membership function. These functions can be any arbitrary shape but are typically triangular or trapezoidal. Notice how they define a gradual transition from regions completely outside the set to regions completely within the set, thereby enabling a value to have partial membership to a set.

6
Hedges

7
Fuzzy Rules Fuzzy rules are comprised of an antecedent and a consequent in the form: IF antecedent THEN consequent = new FuzzyRule(antecedent, consequence) The antecedent represents a condition and the consequent describes the consequence if that condition is satisfied. The difference with fuzzy rules is that unlike conventional rules where the consequent either fires or not, in fuzzy systems the consequent can fire to a matter of degree. Here are some examples of fuzzy rules: IF Target_isFarRight THEN Turn_QuicklyToRight IF VERY(Enemy_BadlyInjured) THEN Behavior_Aggressive IF Target_isFarAway AND Allegiance_isEnemy THEN Shields_OnLowPower IF Ball_isCloseToHole AND Green_isLevel THEN HitBall_Gently AND HitBall_DirectlyAtHole IF (Bend_HairpinLeft OR Bend_HairpinRight) AND Track_SlightlyWet THEN Speed_VerySlow

8
**How Raven Uses the Fuzzy Logic**

Each Raven weapon owns an instance of a fuzzy module, with rules specific to the weapon. All weapons have the method GetDesirability, which updates the fuzzy module and returns a crisp desirability score. The desirability of selecting a particular weapon is dependent on two factors: the distance to the target and the amount of ammo.

9
**Fuzzy Variable by Raven**

10
Fuzzy Module FuzzyVariable& DistToTarget = fm.CreateFLV("DistToTarget"); FzSet Target_Close = DistToTarget.AddLeftShoulderSet("Target_Close", 0, 25, 150); FzSet Target_Medium = DistToTarget.AddTriangularSet("Target_Medium", 25, 150, 300); FzSet Target_Far = DistToTarget.AddRightShoulderSet("Target_Far", 150, 300, 500);

11
**How Raven Uses the Fuzzy Logic**

Weapons & Projectiles: Weapon Blaster Weapon Railgun Weapon Rocket Luncher Weapon Shotgun Fuzzy logic decides which weapon can be used for the next shot based on the distance to the ennemy, the AmmoStatus and the Desirability. The weapon have specific rules

12
**Weapon Blaster void Blaster::InitializeFuzzyModule() {**

FuzzyVariable& DistToTarget = m_FuzzyModule.CreateFLV("DistToTarget"); FzSet& Target_Close = DistToTarget.AddLeftShoulderSet("Target_Close",0,25,150); FzSet& Target_Medium = DistToTarget.AddTriangularSet("Target_Medium",25,150,300); FzSet& Target_Far = DistToTarget.AddRightShoulderSet("Target_Far",150,300,1000); FuzzyVariable& Desirability = m_FuzzyModule.CreateFLV("Desirability"); FzSet& VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100); FzSet& Desirable = Desirability.AddTriangularSet("Desirable", 25, 50, 75); FzSet& Undesirable = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50); m_FuzzyModule.AddRule(Target_Close, Desirable); m_FuzzyModule.AddRule(Target_Medium, FzVery(Undesirable)); m_FuzzyModule.AddRule(Target_Far, FzVery(Undesirable)); }

13
**Weapon Railgun void RailGun::InitializeFuzzyModule() {**

FuzzyVariable& DistanceToTarget = m_FuzzyModule.CreateFLV("DistanceToTarget"); FzSet& Target_Close = DistanceToTarget.AddLeftShoulderSet("Target_Close", 0, 25, 150); FzSet& Target_Medium = DistanceToTarget.AddTriangularSet("Target_Medium", 25, 150, 300); FzSet& Target_Far = DistanceToTarget.AddRightShoulderSet("Target_Far", 150, 300, 1000); FuzzyVariable& Desirability = m_FuzzyModule.CreateFLV("Desirability"); FzSet& VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100); FzSet& Desirable = Desirability.AddTriangularSet("Desirable", 25, 50, 75); FzSet& Undesirable = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50); FuzzyVariable& AmmoStatus = m_FuzzyModule.CreateFLV("AmmoStatus"); FzSet& Ammo_Loads = AmmoStatus.AddRightShoulderSet("Ammo_Loads", 15, 30, 100); FzSet& Ammo_Okay = AmmoStatus.AddTriangularSet("Ammo_Okay", 0, 15, 30); FzSet& Ammo_Low = AmmoStatus.AddTriangularSet("Ammo_Low", 0, 0, 15); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Loads), FzFairly(Desirable)); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Okay), FzFairly(Desirable)); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Low), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Loads), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Okay), Desirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Low), Desirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Loads), FzVery(VeryDesirable)); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Okay), FzVery(VeryDesirable)); m_FuzzyModule.AddRule(FzAND(Target_Far, FzFairly(Ammo_Low)), VeryDesirable); }

14
**RocketLauncher void RocketLauncher::InitializeFuzzyModule() {**

FuzzyVariable& DistToTarget = m_FuzzyModule.CreateFLV("DistToTarget"); FzSet& Target_Close = DistToTarget.AddLeftShoulderSet("Target_Close",0,25,150); FzSet& Target_Medium = DistToTarget.AddTriangularSet("Target_Medium",25,150,300); FzSet& Target_Far = DistToTarget.AddRightShoulderSet("Target_Far",150,300,1000); FuzzyVariable& Desirability = m_FuzzyModule.CreateFLV("Desirability"); FzSet& VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100); FzSet& Desirable = Desirability.AddTriangularSet("Desirable", 25, 50, 75); FzSet& Undesirable = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50); FuzzyVariable& AmmoStatus = m_FuzzyModule.CreateFLV("AmmoStatus"); FzSet& Ammo_Loads = AmmoStatus.AddRightShoulderSet("Ammo_Loads", 10, 30, 100); FzSet& Ammo_Okay = AmmoStatus.AddTriangularSet("Ammo_Okay", 0, 10, 30); FzSet& Ammo_Low = AmmoStatus.AddTriangularSet("Ammo_Low", 0, 0, 10); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Loads), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Okay), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Low), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Loads), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Okay), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Low), Desirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Loads), Desirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Okay), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Low), Undesirable); }

15
**ShotGun void ShotGun::InitializeFuzzyModule() {**

FuzzyVariable& DistanceToTarget = m_FuzzyModule.CreateFLV("DistanceToTarget"); FzSet& Target_Close = DistanceToTarget.AddLeftShoulderSet("Target_Close", 0, 25, 150); FzSet& Target_Medium = DistanceToTarget.AddTriangularSet("Target_Medium", 25, 150, 300); FzSet& Target_Far = DistanceToTarget.AddRightShoulderSet("Target_Far", 150, 300, 1000); FuzzyVariable& Desirability = m_FuzzyModule.CreateFLV("Desirability"); FzSet& VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100); FzSet& Desirable = Desirability.AddTriangularSet("Desirable", 25, 50, 75); FzSet& Undesirable = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50); FuzzyVariable& AmmoStatus = m_FuzzyModule.CreateFLV("AmmoStatus"); FzSet& Ammo_Loads = AmmoStatus.AddRightShoulderSet("Ammo_Loads", 30, 60, 100); FzSet& Ammo_Okay = AmmoStatus.AddTriangularSet("Ammo_Okay", 0, 30, 60); FzSet& Ammo_Low = AmmoStatus.AddTriangularSet("Ammo_Low", 0, 0, 30); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Loads), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Okay), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Close, Ammo_Low), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Loads), VeryDesirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Okay), Desirable); m_FuzzyModule.AddRule(FzAND(Target_Medium, Ammo_Low), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Loads), Desirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Okay), Undesirable); m_FuzzyModule.AddRule(FzAND(Target_Far, Ammo_Low), Undesirable); }

16
**Worked Example Rule 1. IF Target_Far AND Ammo_Loads THEN Desirable**

Rule 2. IF Target_Far AND Ammo_Okay THEN Undesirable Rule 3. IF Target_Far AND Ammo_Low THEN Undesirable Rule 4. IF Target_Medium AND Ammo_Loads THEN VeryDesirable Rule 5. IF Target_Medium AND Ammo_Okay THEN VeryDesirable Rule 6. IF Target_Medium AND Ammo_Low THEN Desirable Rule 7. IF Target_Close AND Ammo_Loads THEN Undesirable Rule 8. IF Target_Close AND Ammo_Okay THEN Undesirable Rule 9. IF Target_Close AND Ammo_Low THEN Undesirable

17
Worked Example Let's say the target is at a distance of 200 pixels and the amount of ammo remaining is 8 rockets. Rule 1 IF Target_Far AND Ammo_Loads THEN Desirable The degree of membership of the value 200 to the set Target_Far is The degree of membership of the value 8 in the set Ammo_Loads is 0. The AND operator results in the minimum of these values so the inferred conclusion for Rule 1 is Desirable =0. In other words, the rule doesn't fire.

18
**Worked Example Rule 2 IF Target_Far AND Ammo_Okay THEN Undesirable**

For the second rule the degree of membership of the value 200 to the set Target_Far is The degree of membership of the value 8 in the set Ammo_Okay is The inferred conclusion for Rule 2 therefore is Undesirable = 0.33.

19
**Worked Example Rule 3 IF Target_Far AND Ammo_Low THEN Undesirable**

Appling the same values to the third rule, the degree of membership of the value 200 to the set Target_Far is The degree of membership of the value 8 in the set Ammo_Low is 0.2. The inferred conclusion for Rule 3 therefore is Undesirable = 0.2.

20
Worked Example We can continue inferencing the rules. Here is summurized result in fuzzy associative matrix, or FAM The FAM for the weapon selection rule base given the input values target distance = 200 and ammo status = 8. The shaded cells highlight rules that have fired. Note that VeryDesirable has fired once to a degree of 0.67. Desirable has fired once to a degree of 0.2, and Undesirable has fired twice with the degrees 0.2 and 0.33. One way to think of these values is as confidence levels.

21
**Worked Example: Combining the conclusions**

The next step is to combine the inferred results into a single fuzzy manifold

22
**Defuzzification: Mean of Maximum (MOM)**

The mean of maximum — MOM for short — method of defuzzification calculates the average of those output values that have the highest confidence degrees. Figure shows how this technique can be used to determine a crisp value from the output distribution for Desirability calculated earlier. The mean of maximum method results in a desirability score of 83. One problem with this method is it doesn't take into account those sets in the output that do not have confidences equal to the highest (like those shown in the figure in gray), which can bias the resultant crisp value to one end of the domain.

23
**Defuzzification: Centroid**

The centroid method is the most accurate but is also the most complex to calculate. It works by determining the center of mass of the output sets. If you imagine each member set of the output set cut out of card stock and then glued together to form the shape of the fuzzy manifold, the center of mass is the position where the resultant shape would balance if placed on a ruler.

24
**Defuzzification: Centroid**

The centroid of a fuzzy manifold is calculated by slicing up the manifold into s sample points and calculating the sum of the contribution of the DOM at each sample point to the total, divided by the sum of the DOMs of the samples. Value Undesirable Desirable VeryDesirable Sum 10 0.33 20 30 0.2 0.53 40 50 60 0.4 0.6 70 0.67 0.87 80 90 100

25
**Defuzzification: Average of Maxima (MaxAv)**

The maximum or representative value of a fuzzy set is the value where membership in that set is 1. For triangular sets this is the simply the value at the midpoint; for sets containing plateaus — such as right shoulder, left shoulder, and trapezoidal sets — this value is the average of the values at the beginning and end of the plateau. The average of maxima (MaxAv for short) defuzzification method scales the representative value of each consequent by its confidence and takes the average, like so:

26
We started with crisp values (distance to target = 200, ammo status = 8) to fuzzy sets, to inference, and back to a crisp value representing the desirability of using the rocket launcher (83, 62, or depending on the defuzzification method). If this process is repeated for each weapon type a bot is carrying, it's a simple matter to select the one with the highest desirability score to be the weapon the bot should use given its current situation.

27
Fuzzy Module Class

28
Conclusion You should now have an understanding of the theory behind fuzzy logic and it's application.

29
Exercice Draw the fuzzy variables of the Rocket Launcher, apply the fuzzy rules and make the inference. How would you read the following rules: m_FuzzyModule.AddRule(Target_Close, Desirable); m_FuzzyModule.AddRule(Target_Medium, FzVery(Undesirable)); m_FuzzyModule.AddRule(Target_Far, FzVery(Undesirable));

Similar presentations

OK

1 Fuzzy Logic Artificial Intelligence for Games Scott Goodwin School of Computer Science See Buckland, Chapter 10.

1 Fuzzy Logic Artificial Intelligence for Games Scott Goodwin School of Computer Science See Buckland, Chapter 10.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on autonomous car Ppt on nutrition in plants of class 7th Ppt on water resources engineering Free ppt on effective communication skills Ppt on classical economics books Ppt on area related to circles for class 10 free download Ppt on unity in diversity logo Ppt on laws of liquid pressure Ppt on buddhism and jainism architecture Ppt on teamviewer free