# Logical and Artificial Intelligence in Games Lecture 13

## Presentation on theme: "Logical and Artificial Intelligence in Games Lecture 13"— Presentation transcript:

Logical and Artificial Intelligence in Games Lecture 13
Fuzzy Logic Logical and Artificial Intelligence in Games Lecture 13

Set Logic Extended Fuzziness can be seen as an extension to Boolean set theory In classic logic, all set are crisp (true or false) Numbers are crisp also – meaning each concept is perfectly known and expressed as such E.g., health = 68, armor = 41

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.

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 x  S In fuzzy set theory set membership is not so easily determined

Membership Function A: X  [0,1] x  A(x)  x  X
A is the membership function X is universe of discourse Diagram below shows different fuzzy membership functions A – triangular B – Curve C – Crisp Singleton

Collection of Singletons
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, bot1} a = [ ] A = {(door,0), (gun,0), (fred, 0.3), (bot1, 0.8)}

Fuzzy Set Theoretic Operations Probability Theory Independent Events
Fuzzy Set Theoretic Operations Probability Theory Independent Events A(x) a B(x) 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)

Fuzzy Modifiers - 1 In “very dangerous” the word “very” could be thought of as a fuzzy linguistic modifier dangerous = [ ] very dangerous = [ ] 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)

Fuzzy Modifiers - 2 Possible fuzzy definitions (restrictive)
very(a) = a2 extremely(a) = a3 moreorless(a) = a1/2 slightly(a) = a1/3 exactly(a) = a+ always(a) = a0 Adverbs might be used as offset modifiers A(x) = m(A(x + k))

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

Liguistic Variables Linguistic variables is a collection of fuzzy variables used to define a high level concept like “allegiance” term set: {enemy,neutral,friendly} values: [0.0, 0.4, 0.9] A linguistic variable is defined over a base variable Base variables can be either crisp or fuzzy values

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

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

Defuzzification - 2 Maximum Approach Centroid 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

Fuzzy Logical Operators
The concepts of fuzzy logic are similar to those used in fuzzy set theory. Operator Notation Equation NOT 1 – x AND min(x, y) OR max(x, y) IMPLIES max(1 - x, y) max(0, x + y – 1)

Linguistic Expressions
Dead or alive Extremely nasty and more or less dead Shot and bleeding badly implies dying d  a n3  d1/2 s  b2  d

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

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, e.g., IF very confident or somewhat vulnerable THEN attack

Rule Extensions Linguistic rules Fuzzy modifiers
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

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

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

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 Product – uses the product of the rule antecedent values and treats this as the value for the output set – probabilistic reasoning

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 Sum A B

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);

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 non-programmers to write rules

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