Fuzzy Logic By Andrew Pro References • • • • • • • Alexander, Thor, “An Optimized Fuzzy Logic Architecture For Decision Making”, AI Game Wisdom. Bonissone, P. Piero and Cheetham, William, “Fuzzy Case Based Reasoning For Residential Property Valuation” (http://www.rpi.edu/~bonisp/fuzzycourse/99/L10/fuzzycbr4realestate.pdf) Hansen, Bjarne K., and Riordan, Denis, “Weather Prediction Using Case-Based Reasoning and Fuzzy Set Theory” (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.3814) Hellman, M., “Fuzzy Logic Introduction” (http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.85.9757&rep=rep 1&type=pdf) Shwab, Brian, AI Game Engine Programming. (http://site.ebrary.com/lib/lehighlibrary/docDetail.action?docID=10074871&f orce=1) Zarozinski, Michael, “Imploding Combinatorial Explosion In A Fuzzy System”, Game Programming Gems 2. http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/sbaa/report.html Outline • Introduction to Fuzzy Logic • Fuzzy Game AI • Fuzzy Logic in CBR Introducing Fuzzy Logic • Takes into account the approximate nature of human reasoning – If the light is turned off, the room will be dark. How dark? • Everything in Fuzzy logic is a matter of degree – Binary logic is fixed at a degree of 0 or 1, where fuzzy truth values can be anywhere in the range of [0,1] Paradox of Self-Reference (just for fun) • Liar paradox – “This sentence is false.” – In binary logic, X cannot equal ¬X. – We can use fuzzy logic and declare X to be (.5) false, so ¬((.5)X) = (.5)X. “This sentence is (half) false.” is (half) true. • Epimenedes – A Cretan says: “All Cretans are liars.” – Perhaps he means with a truth value of .999 Fuzzy Membership Functions • Fuzzy Logic extends multi-valued logic • A function is defined for each logic value • Instead of values being mutually exclusive like in a normal logic system, the logic values overlap . Fuzzy Membership Functions • Functions can be simple or complex (fuzzily speaking of course) • Which functions could describe the fuzzy value, Tall? Fuzzy Sets and Operations • Fuzzy Set defined by function. – COLD(x) = – Negation ¬COLD(x) = 1 if temp(x)<= 50 (60 – temp(x))/10 if 50<temp(x)<60 0 if temp(x)>=60 0 if temp(x)<= 50 (temp(x)-60)/10 if 50<temp(x)<60 1 if temp(x)>=60 • The function and its inverse overlap! Fuzzy Set Operation • A AND B at x=4.75 A AND B = min(A,B) = .25 • A OR B at x=4.75 A AND B = max(A,B) = .75 Fuzzy Logic or Probability Theory • Fuzzy logic deals with the measure of how much a variable is in a particular set. • Probability theory handles subjective probability where a function may map how likely a variable is to be in a particular set. Fuzzy Logic in Game AI • Fuzzy logic can be used in a variety of ways to help game AI seem more human-like • NPC Finite State Machines can be improved by making fuzzy determinations for state transition logic Example NPC FSM • Character stays in state until distance value is crossed FSM Rules • FSM transition rules: State Chase – IF player is close THEN attack – ELSE IF player is far THEN returnHome – ELSE chase • Close and far are crisply defined – Is necessary if distance is the only state transition measure Fuzzy Rules cont’d • Fuzzy rules might be – IF player is close THEN attack – IF player is far THEN returnHome – IF player is inbetween THEN chase • Combined with other factors (weapon range, time of day, weather condition) a distance measured close may not be close enough • The NPC now has more varied, interesting behavior Fuzzy AI Decision • Rules are created using every combination of 1 set from each variable. • Rules may be difficult to produce. Variables can be given weights or rule base can be generated by expert. Fuzzy AI Decision cont’d • Each rule has an aggressiveness value (or truth value) using the Fuzzy AND operation. • All-out attack is the best choice because is has the highest degree of truth, but there still is a small part of Fight defensively that wants to be considered. So… Defuzzification • Want to derive a numeric output value for aggressiveness. One method is the center-ofmass method • Take the maximum value from each output variable set. (attack – 53, defend – 18, run – 0) • Create a full output block by capping each membership function at the final output value, then OR the functions. • Find the center of mass. Combinatorial Explosion • For real time AI, this becomes unpractical at a certain point. • Can compromise some of the functionality to significantly reduce the number of rules. The Combs Method • Use rules based on each set’s relationship to the output. • Take output from each rule fired, OR the matching sets to get the overall truth value for each output set. – (Run – 0, Defense – 83, Attack – 60) • Different, but still reasonable – Aggressiveness values fairly close after defuzzification Fuzzy AI • Keep fuzziness in game AI on a small scale • FuSM can be used where states don’t interfere with eachother. – Face modeling can be fuzzy to look more natural Fuzzy CBR • Think about CBR using fuzzy logic – Case is similar or not similar – Retrieval can be more accurate with fuzzy attributes (…symbolic attributes) – Case can be adapted using fuzzy set functions based on differences between problem case and retrieved case Restaurant Example Ex’ple Bar Fri Hun x1 x4 x5 x6 no no no yes no yes yes no yes yes no yes x7 x8 yes no no no x9 yes x10 x11 yes no Pat Alt Type wait some full full some yes yes yes no French yes Thai yes French no Italian yes no yes none some no no Burger no Thai yes yes no full no Burger no yes No yes no full none yes no Italian Thai no no Restaurant Example • Bar / No Bar doesn’t really work, but fuzzifying Hungry and Patrons could help – (starving, pretty hungry, a little hungry) • Patrons seems to be begging for fuzziness. – Is the difference between None and Some really just 1 patron? – Does full actually mean there are no open tables whatsoever? Fuzzy CBR Systems • WIND-1 – Weather prediction for airports. Expert identifies fuzzy attributes (cloud ceiling, visibility, etc) – Expert defines similarity thresholds to measure sim between cases. Outputs are fuzzy. (Very near, near, slightly near) – Fuzzy predictor performs more accurately than system finding k-NN using crisp attribute values. Fuzzy CBR Systems • PROFIT – Fuzzy CBR system for real estate value estimation that uses fuzzy logic in similarity computation, case adaptation, and confidence value generation – Sale comparison approach: “finding the most similar houses, located close to the subject property, sold not too long ago; and selecting a balanced subset of the most promising comparables to derive the final estimate.” Fuzzy CBR Systems cont’d (PROFIT) • Similarity functions describing living area, lot size, preferred #bedrooms, and preferred #bathrooms Fuzzy CBR Systems cont’d (PROFIT) • Finds most similar cases, applies adjustment rule set using differences to subject case. Similarity rank could differ from net adjustment rank. Discard cases with too much price adjustment. Final estimate = sum(adjPrice*sim)/sum(sim) • Confidence assessment using aggregation of fuzzy functions related to cases retrieved, similarity, average price adjustment, etc. Conclusion • Fuzzy logic helps represent vague variables and sets in a more natural • Game AI can be altered using fuzzy state transitions and/or fuzzy states to add variance to NPCs • In Case-Based Reasoning, the Retrieve and Revise steps can benefit from having fuzzy membership functions of case features.