1 / 33

Fuzzy Logic

Fuzzy Logic. Fuzzy Logic. Lotfi Zadeh (professor at UC Berkeley) wrote his original paper on fuzzy set theory . In various occasions, this is what he said… “Fuzzy logic is a means of presenting problems to computers in a way akin to the way humans solve them”

marinel
Download Presentation

Fuzzy Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fuzzy Logic

  2. Fuzzy Logic • LotfiZadeh (professor at UC Berkeley) wrote his original paper on fuzzy set theory. In various occasions, this is what he said… • “Fuzzy logic is a means of presenting problems to computers in a way akin to the way humans solve them” • “The essence of fuzzy logic is that everything is a matter of degree” • What do these statements really mean?

  3. Fuzzy Logic • Very often, we humans analyze situations and solve problems in a rather imprecise manner • Do not have all the facts • Facts might be uncertain • Maybe we only generalize facts without having the precise data or measurements… • Real-life example: Playing a game of basketball

  4. Everything is a matter of degree? • Is your basketball opponent tall, or average or short? (use of linguistic terms to measure degree) • Is 7 feet tall? Is 6 feet 10 inches tall? Are they both considered tall? (overlapping degrees) • Problem with traditional Boolean logic • You are forced to define a point above which we will consider the guy to be tall or just average, e.g. > 7 ft • Fuzzy Logic  allows gray areas or degrees of being considered “tall”

  5. The degree of truth • So…you can think of fuzzy logic as classifying something as being TRUE, but to varying degrees • Real-life control applications (air-conditioning, household appliances): • Traditional Boolean logic will result in abrupt switching of response functions • Fuzzy logic alleviates this problem  Responses will vary smoothly given the degree of truth or strength of the input conditions

  6. Fuzzy logic for games • A previous game AI example… • An AI character makes his decision to chase (using FSM or DT) based on traditional Boolean logic, e.g. distance of player < 20 units, and player health < 50% • In fuzzy logic, we can represent these input conditions using a few “membership” degrees of measure • Distance: (“Far”, “Average”, “Near”) • Health: (“Good”, “Normal”, “Poor”) • The output actions can also be represented with different membership degrees (“Chase Fast”, “Chase Slow”)

  7. How to use Fuzzy Logic in Games? • 3 possible ways how fuzzy logic can be used in games • Control • Modulating steering forces, travelling/moving towards target • Threat Assessment • Assessing player’s strengths/weaknesses for deploying units and making moves • Classification • Identifying the combat prowess of characters in the game based on a variety of factors in order to choose opponent • There are many other possibilities…

  8. Fuzzy Logic Basics • Fuzzy control or fuzzy inference process – 3 basic steps

  9. Step 1: Fuzzification • Fuzzification: Process of mapping/converting crisp data (real numbers) to fuzzy data • Find degree of membership of the crisp input in predefined fuzzy sets • E.g. given a character’s health, determine the degree to which it is “Good”, “Fair” or “Poor”. • Mapping is achieved using membership functions

  10. Membership Functions • Membership Functions • Map input variables to a degree of membership, in a fuzzy set, between 0 and 1. Degree 1  absolutely true, degree 0  absolutely false, any degree in between  true or false to a certain extent • “Boolean logic membership function”

  11. Membership Functions • Fuzzy Membership Functions • Enables us to transition gradually from false to true • Grade membership function

  12. Membership Functions • Triangular m/f • Reverse grade m/f • Equations are just the inverse of the grade m/f

  13. Membership Functions • Trapezoid m/f • Other nonlinear m/f • Gaussian or Sigmoid ‘S’-shaped curves

  14. Membership Functions • Typically, we are interested in the degree of which an input variable falls within a number of qualitative sets

  15. Membership Functions • Setting up collections of fuzzy sets for an input variable is a matter of judgment and trial-and-error  not uncommon to “tune” the sets • While tuning, one can try different membership functions, increase or decrease number of sets • Some fuzzy practitioners recommend 7 fuzzy sets to fully define a practical working range (?!?!?)

  16. Membership Functions • One rule of thumb for ensuring smooth transitions (in later steps) is to enforce overlapping between neighboring sets

  17. Hedge Functions • Hedge functions are sometimes used to modify the degree of membership • Provide additional linguistic constructs that you can use in conjunction with other logical operations. • Two common hedges: • VERY(Truth(A)) = Truth(A)2 • NOT_VERY(Truth(A)) = Truth(A)0.5 (Truth(A) is the degree of membership of A in some fuzzy set)

  18. Step 2: Fuzzy Rules • Next, construct a set of rules, combining the input in some logical manner, to yield some output • If-then style rules (if A then B) – A being the antecedent/premise and B being the consequent/conclusion • Fuzzy input variables are combined logically to form premise • Conclusion will be the degree of membership of some output fuzzy set

  19. Fuzzy Axioms • Since we are writing “logical” rules with fuzzy input, we need a way to apply logical operators to fuzzy input (just like with Boolean input) • Logical OR (disjunction) • Truth(A OR B) = MAX(Truth(A), Truth(B)) • Logical AND (conjunction) • Truth(A AND B) = MIN(Truth(A), Truth(B)) • Logical NOT (negation) • Truth(NOT A) = 1 – Truth(A)

  20. Fuzzy Axioms • Example, given a person is overweight to the degree of 0.7 and tall to the degree of 0.3: • Overweight AND tall = MIN(0.7, 0.3) = 0.3 • Overweight OR tall = MAX(0.7, 0.3) = 0.7 • NOT overweight = 1 – 0.7 = 0.3 • NOT tall = 1 – 0.3 = 0.7 • NOT(overweight AND tall) = 1 – MIN(0.7, 0.3) = 0.7 • There are other definitions for these logical operators…

  21. Rule Evaluation • Unlike traditional Boolean logic, • Rules in fuzzy logic can evaluate into any number between 0 and 1 (not just 0 or 1) • All rules are evaluated in parallel (not in series that the first one that is true gets fired). Each rule always fires, to various degrees • The strength of each rule represents the degree of membership in the output fuzzy set

  22. Rule Evaluation • Example: Evaluating whether an AI should attack player • Rules can be written like: • If (in melee range AND uninjured) AND NOT hard then attack • Set up as many rules to handle all possibilities in the game

  23. Rule Evaluation • Given specific degrees for the input variables, you might get outputs (conclusions of the rules) that look something like this: Attack to degree: 0.2 Do nothing to degree: 0.4 Flee to degree: 0.7 • The most straightforward way to interpret these outputs is to take the action associated with the highest degree (in this case, the action will be flee)

  24. Step 3: Defuzzification • In some cases, you might want to use the fuzzy output degree to determine a crisp value (real number), which can be useful for further calculations • Defuzzification: Process of converting the results from the fuzzy rules to get a crisp number as an output • Opposite of fuzzification (you can say that, although the purpose and methods are different!)

  25. Step 3: Defuzzification • Previous example: Instead of determining some finite action (do nothing, flee, attack), we also want to use the output to determine the speed to take the action • To get a crisp number, aggregate the output strengths on the predefined output membership functions

  26. Step 3: Defuzzification • With the numerical output from the earlier example (0.2 degree attack, 0.4 degree do nothing, 0.7 degree flee), we have the composite membership function below

  27. Defuzzifying composite m/f • Truncate each output set to the output degree of membership for that set. Then combine all output sets by disjunction • A crisp number can be arrived from such an output fuzzy set in many ways • Geometric centroid of the area under the output fuzzy set, taking its horizontal axis coordinate as the crisp output

  28. Using “predefuzzified” output • A less computationally expensive method is the use of singleton output membership function or a “predefuzzified” output function • Instead of doing lots of calculation, assign speeds to each output action (-10 for flee, 1 for do nothing, 10 for attack). • E.g. The resulting speed for flee is simply the preset value of -10 times the degree to which the output action flee is true (-10 x 0.7 = -7)

  29. Using “predefuzzified” output • Aggregate of all outputs with a simple weighted average • In our example, we might have: Output = [(0.7)(-10) + (0.4)(1) + (0.3)(10)] / (0.7+0.4+0.3) = -2.5 • This output would result in the creature fleeing, but not earnestly in full extent • Naturally, we can obtain various output (crisp) values depending on the different input conditions

  30. Further Examples • There are 2 good examples in the textbook, showing the full process of using fuzzy logic to model game AI characters

  31. Using Fuzzy Logic in FSMs? • If we want to add some fuzzy logic into FSMs, how can that be accomplish? Is it possible? • Remember: Each state defines a behavior or action, and each state is reached by transition from another state on the basis of fulfilling some input conditions… • Conditions for transition are normally in Boolean logic, how do we accommodate fuzzy logic?

  32. Fuzzy State Machines • Different AI developers regard Fuzzy State Machines differently • State machine with fuzzy states • State transitions that use fuzzy logic to trigger • Both • Find out more about how these different variations can be worked out and implemented (refer to Millington book)

  33. • Next up • Homework 2 (due in Week 10, submission via mail) • Milestone #2 (due in Week 11, 11.00am 23/8, Thurs) • Upcoming lectures • Probabilities and Uncertainty Techniques • Tactical and Strategic AI

More Related