Presentation on theme: "Fuzzy Logic Driven Agent Behavior"— Presentation transcript:
1Fuzzy Logic Driven Agent Behavior Prof. Dr. Taoufik NouriThe primary text for the course isRef.
2Fuzzy Logic Goal: Master How the raven is using fuzzy logic. Prof. Dr. Lotfi Zadeh father of Fuzzy Logic
3Fuzzy Sets Fuzzy Variable IQ Ryan with IQ=115 Є Clever with m = 0.75 Є Average with m = 0.25m is membership coefficientFuzzy Variable: Distance to Target
4Fuzzy Set Operators Average AND Clever OR = + Average OR Clever NOT NOT Clever
5DefinitionA 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.
7Fuzzy RulesFuzzy 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_QuicklyToRightIF VERY(Enemy_BadlyInjured) THEN Behavior_AggressiveIF Target_isFarAway AND Allegiance_isEnemy THEN Shields_OnLowPowerIF Ball_isCloseToHole AND Green_isLevel THEN HitBall_Gently AND HitBall_DirectlyAtHoleIF (Bend_HairpinLeft OR Bend_HairpinRight) AND Track_SlightlyWet THEN Speed_VerySlow
8How 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.
11How Raven Uses the Fuzzy Logic Weapons & Projectiles:Weapon BlasterWeapon RailgunWeapon Rocket LuncherWeapon ShotgunFuzzy 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
16Worked Example Rule 1. IF Target_Far AND Ammo_Loads THEN Desirable Rule 2. IF Target_Far AND Ammo_Okay THEN UndesirableRule 3. IF Target_Far AND Ammo_Low THEN UndesirableRule 4. IF Target_Medium AND Ammo_Loads THEN VeryDesirableRule 5. IF Target_Medium AND Ammo_Okay THEN VeryDesirableRule 6. IF Target_Medium AND Ammo_Low THEN DesirableRule 7. IF Target_Close AND Ammo_Loads THEN UndesirableRule 8. IF Target_Close AND Ammo_Okay THEN UndesirableRule 9. IF Target_Close AND Ammo_Low THEN Undesirable
17Worked ExampleLet's say the target is at a distance of 200 pixels and the amount of ammo remaining is 8 rockets.Rule 1IF Target_Far AND Ammo_Loads THEN DesirableThe 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.
18Worked 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.
19Worked 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.
20Worked ExampleWe can continue inferencing the rules. Here is summurized result in fuzzy associative matrix, or FAMThe 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.
21Worked Example: Combining the conclusions The next step is to combine the inferred results into a single fuzzy manifold
22Defuzzification: 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.
23Defuzzification: 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.
24Defuzzification: 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.ValueUndesirableDesirableVeryDesirableSum100.3320300.20.534050600.40.6700.670.878090100
25Defuzzification: 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:
26We 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.
28ConclusionYou should now have an understanding of the theory behind fuzzy logic and it's application.
29ExerciceDraw 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));