Fuzzy Logic CIS 488588 Bruce R Maxim UMDearborn
Fuzzy Logic CIS 488/588 Bruce R. Maxim UM-Dearborn 2/24/2021 1
World Objects • Items – Direct effect on player state (e. g. health or armor) – No direct effect on player state (e. g. invincibility) – Strategies to maximize benefits of object collection are important for game bots to appear smart • Contraptions (puzzles) – Generally designed to slow down escape or impede access to weapons (e. g. ladder or switch) – A sequence of player actions must precede their use 2/24/2021 2
Test Bed • Fairly easy to test object collection strategies (most game levels have lots of items) • Presence of contraptions is relatively rare since these elements are often architecture centerpieces, so it is harder to test animat abilities to use them without creating simplified custom levels for training 2/24/2021 3
Human Behavior - 1 • Picking up Items – Picking up objects in many games is simply a matter of walking over them – Unlike obstacle avoidance that can be done while wondering, picking up objects requires intentional movement to be efficient • Handling Contraptions – Must combine specific skills (button pressing or waiting) with movement – Sequences of actions (plans) are often required to solve the puzzle of operation 2/24/2021 4
Human Behavior - 2 • Behavior Enhancers – Special skills that improve game play (e. g. dodging projectiles or jumping) – Just like using contraptions these actions may require development of a sequence of actions (plan) and preconditions (e. g. location or timing) for its use 2/24/2021 5
Criteria • To maintain illusion of realism the AI cannot be too good at using items or solving puzzles • Even if the AI is realistic do not over use it • Effectiveness – Make the behavior as efficient as possible (no wasteful moves or pauses) • Consistency – AI actions must be justifiable (follow up actions are taken) 2/24/2021 6
Behavior Case Study - 1 • Opening door – – NPC walks toward switch Pushes switch on contact NPC stands back while door opens NPC goes through door • Getting onto platform – NPC press switch – Waits for platform to arrive – Gets on platform and it moves 2/24/2021 7
Behavior Case Study - 2 • Getting on ladder – NPC moves till contact made – NPC must face ladder to avoid falling off – Climbing done by looking up and moving forward • Jump Pads – NPC needs to walk on pad – NPC tossed in the air – Moving while in the air controls the fall 2/24/2021 8
Behavior Case Study - 3 • Dodging – Move away from line of fire for incoming projectiles and their predicted point of impact • Rocket Jumping – NPC needs to look down – Jump using standard command – Shoot a rocket at the ground 2/24/2021 9
Interfaces - 1 • New movement functions (can be used in combination with movement) void Jump( ); void Duck( ); • New inventory functions void Items. Available(vector<Entity>& items, const Entity: : Type& unifier = 0); bool Use. Item(Symbol& item); 2/24/2021 10
Interfaces - 2 • Vision – No functional extensions needed only additional data past through it – AI will need to use of callback functions like void On. Door. Open(const Event& event); • Physical State (collection of queries) bool 2/24/2021 is. Platform( ); is. Ladder( ); is. Water( ); is. Air( ); 11
Greedy • Attempts to collect every object in sight • Moves on only after every item is picked up or is inaccessible • Built on steering behaviors • (animat not in archive) 2/24/2021 12
Fuzzy Set Theory • In ordinary set theory every element “x” from a given universe is either in or out of a set S x S • In fuzzy set theory set membership is not so easily determined 2/24/2021 13
When is a pile of chalk big? • If we have three pieces of chalk in the room is that considered a big pile of chalk? • Some people might say, yes that is a big pile and some would not. • Someplace between those three pieces of chalk and a whole room full of chalk the pile of chalk turns from a small pile into a big pile. • This could be a different spot for different people. 2/24/2021 14
Membership Function A: X [0, 1] x A(x) x X X is universe of discourse x X A(x) x X 1/x 2/24/2021 15
Fuzzy Set • Collection of ordered pairs (x, A(x)) known as a fuzzy singleton • Consider a set A defined as the set of hostile game objects from X X = {door, gun, fred, bot 1} a = [0 0 0. 3 0. 8] A = {(door, 0), (gun, 0), (fred, 0. 3), (bot 1, 0. 8)} 2/24/2021 16
Fuzzy Set Theoretic Operations Probability Theory Independent Events A(x) a a B(x) b b not A(x) complememt 1 -a 1 - a A and B intersection min(a, b) a * b A or B union max(a, b) a + b – a*b A = B equality x: A(x) = B(x) A B subset x: A(x) < B(x) 2/24/2021 17
Fuzzy Modifiers - 1 • In “very dangerous” the word “very” could be thought of as a fuzzy linguistic modifier dangerous = [0 0. 1 0. 4 0. 8 1] very dangerous = [0 0. 01 0. 16 0. 64 1] • More formally we could think of a fuzzy modifier m as a function that converts one fuzzy set a into another set m(a) m: X F(X) a m(a) | a F(X) 2/24/2021 18
Fuzzy Modifiers - 2 • Possible fuzzy definitions very(a) extremely(a) moreorless(a) slightly(a) exactly(a) always(a) = a 2 = a 3 = a 1/2 = a 1/3 = a+ = a 0 • Adverbs might be used as offset modifiers A(x) = m(A(x + k)) 2/24/2021 19
Fuzzy Variables and Values • Fuzzy variables can be considered as a term associated with a floating point value • A collection of fuzzy variables could be used to define an enemy profile {(healthy 0. 9) (dangerous 0. 3) (moving 0. 3)} • Linguistic variables is a collection of fuzzy variables used to de 2/24/2021 20
Liguistic Variables • Linguistic variables is a collection of fuzzy variables used to define a high level concept like “allegiance” term set: values: {enemy, neutral, friendly} [0. 0, 0. 4, 0. 9] • A linguistic variable is defined over a base variable • Base variables can be either crisp or fuzzy values 2/24/2021 21
2/24/2021 22
Fuzzification • Creating a fuzzy variable from a crisp one • Define a membership function with the same range as the crisp variable • Evaluating the membership based on the crisp variable value indicates degree of set membership 2/24/2021 23
2/24/2021 24
Defuzzification - 1 • • Converts a fuzzy value to a crisp value Fairly easy for fuzzy variables Can be tricky for linguistic values Process often involves information loss, unless you are doing simple conversions • There is no unique equation, since humans use problem-dependent techniques to defuzzify linguistic concepts 2/24/2021 25
Defuzzification - 2 • Maximum Approach – Uses highest points in membership function graph – First maxima – picks crisp value from highest of all membership function – Average maxima – weighted or unweighted average of all crisp values • Centroid Approach – based on finding center of gravity of the membership function graph – Very computationally intensive 2/24/2021 26
2/24/2021 27
Fuzzy Logical Operators Operator Notation Equation NOT 1–x AND min(x, y) OR max(x, y) IMPLIES max(1 - x, y) max(0, x + y – 1) 2/24/2021 28
Linguistic Expressions Dead or alive d a Extremely nasty and more or less dead n 3 d 1/2 Shot and bleeding badly implies dying s b 2 d 2/24/2021 29
Fuzzy Logic • Fuzziness is really deterministic uncertainty and depends on probability assumptions which may not be met • Fuzzy logic contains inconsistencies (e. g. the set of animats that are both dead and alive is not empty) • Seems to model human knowledge and reasoning better than standard truth functional logic 2/24/2021 30
Fuzzy Control Systems Decision Making • Working Memory – Similar to RBS, except fuzzy variables used in place of crisp symbols • Knowledge Base – Rules containing fuzzy variables are used if very confident or somewhat vulnerable then attack 2/24/2021 31
Rule Extensions • Linguistic rules – Keyword is used to refer to fuzzy terms if allegiance is friendly then happy • Fuzzy modifiers – Can be applied to both antecedent and consequent variables 2/24/2021 32
Creating Membership Functions • Knowledge engineer can try to extract information and heuristics from human experts • Survey can be used to collect information regarding several people’s understanding and membership function reflects average • Incremental tuning will be required for any approach chosen 2/24/2021 33
Fuzzy Interpreter Matching • In crisp systems it is easy to identify rules that match WM, facts are present or they are not • In fuzzy systems, fuzzy variables are rarely zero so every rule needs to be checked during every match cycle • To reduce impact of combinatorial explosion, thresholds will be used to reduce the number of low probability matches 2/24/2021 34
Fuzzy Interpreter Inference • Purpose is to determine the degree of truth for the consequent part of each rule • Two techniques used – Min (uses the minimum of the rule antecedent values and treats this as the value for the output set – possibilistic reasoning) – Products (uses the product of the rule antecedent values and treats this as the value for the output set – probabilistic reasoning) 2/24/2021 35
Fuzzy Interpreter Composition • Many rules have the same fuzzy variable in the rule body (consequent) • To combine support shown by multiple rules – Max (uses the maximum of the rule output values and uses this as the fuzzy variable value in WM – possibilistic reasoning) – Sum (uses the sum of the rule output values and uses this as the fuzzy variable value in WM – probabilistic reasoning) 2/24/2021 36
Algorithm // current WM with latest fuzzy variable values // previous is copy of most recent WM for each value in WM { previous[value] = current[value]; current[value] = 0; } for each rule { result = evaluate(rule. expression, previous); current[rule/body] = max(current[rule. body}, result); } 2/24/2021 37
Discussion – 1 • • Fuzzy systems are surprisingly robust Can cope with noisy and incomplete data Requires little feedback to perform well Fuzzy expert systems mimic human reasoning surprisingly well • Fuzzy RBS are easy to extend incrementally • Rule syntax is easy enough for nonprogrammers to write rules 2/24/2021 38
Discussion – 2 • Fuzzy systems use rules of thumb (heuristics) and not mathematical models of the problem • Every rule needs to be evaluated during every match cycle which is computationally expensive (for a large number of rules) • Creating membership functions is not easy • Combinatorial explosion of rules is possible for large numbers of input combinations, unless knowledge is represented implicitly 2/24/2021 39
Dominator • Uses fuzzy expert system to control movement and shooting • Uses fuzzy logic for weapon selection • Supposedly has the best performance of all animats • (not found in the current archive) 2/24/2021 40
Actions - 1 • Define linguistic variable move is defined with three values forwards, stop, backwards forwards = 1 if velocity is null and 0 if velocity is full backwards = 0 if velocity is null and 1 if velocity is full stop = not(forwards or backwards) • Fuzzy modifier extremely can be used to obtain steeper curve for stop 2/24/2021 41
Actions - 2 • Define base linguistic variable turn is defined as yaw turning angle (0 membership function means no turn) • Fuzzy terms as used to direct turn toward: button, door, ladder, platform, exit • Linguistic variable look controls pitch separately up = pitch of 90 ahead = pitch of 0 2/24/2021 42
Senses - 1 • Door is defined over opening height so value is 0 when closed and 1 when open – Fully open door (degree of membership) Do. M is 1 if door can be walked through 0 if crawl through is needed • Button_pressed is really a pure boolean singleton not fuzzy variable 2/24/2021 43
Senses - 2 • Platform is defined as two terms with Do. M of 1 when at starting point and 0 when player needs to double jump off – Term ready is distance off floor and how easy it is to climb on – Term arrived is distance to final location • Additional terms – aboard is 1 when on platform and 0 when not (peaks near (x, y) at platform center) 2/24/2021 44
Senses - 3 • Ladder is defined as two terms – Term held has Do. M value of 1 after 1 full second of touching 0 when released for 1 full second – Term top has Do. M defined over height and is 1 when animat can step off 0 when 1 step from the top 2/24/2021 45
Rules for Using Doors - 1 • if not button_pressed then turn to button, move forward • if button_pressed then turn toward door • if button_pressed and door not fully open then move stop • if door fully open move forward, turn toward door 2/24/2021 46
Rules for Using Doors - 2 • Note these rules rely on the animat being interrupted once the doorway is crossed • A higher level AI needs to identify this case and stop calling the fuzzy behavior to prevent the animat from heading through the door (e. g. rule 1 needs to be disabled by have the membership function of its action drop to zero once the button is pressed) 2/24/2021 47
Rules for Using Ladders • True then move forward • if ladder is not held then turn toward ladder • if ladder is held then look up • if ladder is top then look ahead, turn toward exit 2/24/2021 48
Rules for Using Platforms - 1 • if not button_pressed then turn to button, move forward • if button_pressed and platform not ready then move stop • if button_pressed and not aboard turn to platform • if platform is ready then move forward 2/24/2021 49
Rules for Using Platforms - 2 • if aboard then turn to exit • if aboard and platform has not arrived then move stop • if aboard and platform has arrived turn move forward • if platform is ready then move forward 2/24/2021 50
Working Memory - 1 • Contains fuzzy terms used by interpreter • There is no difference in representation of individual and linguistic variables • Some terms will need to be associated with a membership function to fuzzifying or defuzzifying • Symmetric triangle is sufficient for the membership function 2/24/2021 51
Working Memory - 2 <memory> <Variable name=“platform”> <Term name=“ready” /> <Term name=“arrived” /> </Variable> <Variable name=“door”> <Term name=“open”> <triangle center+” 0” base=“ 45” /> </Term> </Variable </memory> 2/24/2021 52
Rulebase <rulebase> <Rule> <conditions> <Term name=“aboard” /> <Variable name=“platform” value=“arrived” /> </conditions> <body> <Variable name=“move” term=“forward” value=“ 1” /> <Variable name=“turn” term=“exit” value=“ 1” /> </body> </Rule> </rulebase> 2/24/2021 53
Interface • Synchronization void Set. Sensor(const Sensor. Func& s, const string& symbol); void Set. Effector(const Effector. Func& e, const string& symbol); • Dynamic Access void Set(const string& symbol, const float value); void Get(const string& symbol) 2/24/2021 54
Jacky • Uses fuzzy expert system • Can climb ladders, open doors, and call elevators • Default behavior is reactive wandering 2/24/2021 55
Evaluation - 1 • Fuzzy controlled movement is smooth except for button pressing • In some cases reaction times are a little slow (e. g. first rung of ladder or anticipating the arrival of platform) • Animat generally does not waste movement • Because fuzzy interpreter has direct control over movement animat can struggle to get past some obstacles 2/24/2021 56
Evaluation - 2 • Ideally fuzzy system output should be treated as a suggestion, rather than an order • Fuzzy interpreter does not keep track of which step in the sequence the animat is one (might need context variables like XCON/R 1) • Might benefit from creating a fuzzy state machine rather than creating more complex rules 2/24/2021 57
- Slides: 57