Genetic Algorithms Logical and Artificial Intelligence in Games Lecture 14.
Fuzzy Logic Logical and Artificial Intelligence in Games Lecture 13.
-
Upload
gabrielle-flores -
Category
Documents
-
view
218 -
download
0
Transcript of Fuzzy Logic Logical and Artificial Intelligence in Games Lecture 13.
Fuzzy LogicFuzzy Logic
Logical and Artificial Intelligence in Games
Lecture 13
2
Set Logic ExtendedSet 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
3
When is a pile of chalk big?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.
4
Fuzzy Set TheoryFuzzy Set Theory
In ordinary set theory every element “x” from a given universe is either in or out of a set S
x Sx S
In fuzzy set theory set membership is not so easily determined
5
Membership FunctionMembership 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
6
Collection of SingletonsCollection 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 = [0 0 0.3 0.8]
A = {(door,0), (gun,0), (fred, 0.3), (bot1, 0.8)}
7
Fuzzy SetTheoretic
Operations
Probability TheoryIndependent
Events
A(x) a a
B(x) b b
not A(x)complememt
1-a 1 - a
A and Bintersection
min(a,b) a * b
A or Bunion
max(a,b) a + b – a*b
A = Bequality
x: A(x) = B(x)
A Bsubset
x: A(x) < B(x)
8
9
Fuzzy Modifiers - 1Fuzzy 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)
10
Fuzzy Modifiers - 2Fuzzy 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))
11
12
Fuzzy Variables and ValuesFuzzy 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
13
Liguistic VariablesLiguistic 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
14
15
FuzzificationFuzzification
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
16
17
Defuzzification - 1Defuzzification - 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
18
Defuzzification - 2Defuzzification - 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
19
20
Fuzzy Logical OperatorsFuzzy 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)
The concepts of fuzzy logic are similar to those used in fuzzy set theory.
21
Linguistic ExpressionsLinguistic 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
22
Fuzzy LogicFuzzy 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
23
Fuzzy Control SystemsFuzzy Control SystemsDecision MakingDecision MakingWorking 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
24
Rule ExtensionsRule 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
25
Creating Membership FunctionsCreating 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
26
Fuzzy InterpreterFuzzy InterpreterMatchingMatchingIn 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
27
Fuzzy InterpreterFuzzy InterpreterInferenceInferencePurpose 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
28
Fuzzy InterpreterFuzzy InterpreterCompositionCompositionMany 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
A B
Sum
29
AlgorithmAlgorithm
// 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);
}
30
Discussion – 1Discussion – 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
31
Discussion – 2Discussion – 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