Fuzzysystem

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Source Code: https://bitbucket.

org/twntduff/realtime-fuzzysystem/src

Overview
Fuzzy Logic is an AI logic system that handles approximate reasoning rather
than traditional binary sets (true or false). Fuzzy logic variables may have a truth
variable that varies in degree from 0 to 1. 1 being completely true and 0 being
completely false leaving a gray area where the variable can be defined as both true
and false to a certain degree. Fuzzy logic systems can be thought of as more
similar to how a human brain operates by forming a number of partial truths which
we assign to higher truths which the brain weighs and makes certain decisions.

Why Fuzzy Logic?


Normally in logic we have statements which are either true or false. For
example, the distance of an object is either 100 meters away or it isn't. This
statement is a simple Boolean check, true or false. However, there are many other
situations in which the answer isn't so cut and dry. The answer maybe something
more like "maybe", "kind of'", or "not sure." Fuzzy logic deals with these
uncertainties by attaching a degree of certainty to these answers. In doing so, the
decisions made by the NPC's in a game can be made to look more human like by
not always making a decision that is the safest or fastest and straying from a linear
course. Remember "it is human to err" and the goal of any AI system for games
should be to make it as believable as possible while still giving the game a sense of
randomness.

Fuzzy Breakdown
Fuzzy Variable:
Fuzzy variables are composed of fuzzy values which define the different
levels of that variable.
Fuzzy variables can be composed of any number of values.

Fuzzy Value:

Fuzzy values are composed of lines which points define the numerical
values (X) for the given fuzzy value.
There are multiple types of value shapes that can compose a fuzzy value.

Fuzzy Math
Calculating Degree of Membership (DoM)
Y = M (X - X1) + Y1
Example:
X = 18
M = -1 / 13 ---> -.077
X = -.077 (18 - 10) + 1
X = -1.386 + .077 + 1
X = 0.384

Calculating Degree of Certainty (DoC)


X = (Y - Y1) / M + X1
Example:
udes = 0.5
des = 0.2
vdes = 0.7

udes
M = -1 / 25 ---> -.04
X = (0.5 - 1) / (-.04) + 25
X = 37.5

Fuzzy Operators
NOT X
Example: 0.7 close ---> (1 - 0.7) = 0.3 NOT close
X OR Y
Example: 0.7 close, 0.3 ammoLow ---> max(0.7, 0.3) = 0.7 close OR
ammoLow
X AND Y
Example: 0.7 close, 0.3 ammoLow ---> min(0.7, 0.3) = 0.3 close AND
ammoLow

Alternative Interpretations
Other definitions of the operator AND use different t-norms.
Examples:

Product
X AND Y

Example: 0.7 close, 0.3 ammoLow ---> mult(0.7, 0.3) = 0.21 close AND
ammoLow
Lukasiewicz
X AND Y
Example: 0.7 close, 0.3 ammoLow ---> max(0.7 + 0.3 - 1, 0.0) = 0.0 close
AND ammoLow
Other definitions of the operator OR use different t-conorms.
Examples:

Product
X OR Y
Example: 0.7 close, 0.3 ammoLow ---> 0.7 + 0.3 - 0.7 * 0.3 = 0.79 close OR
ammoLow
Lukasiewicz
X OR Y
Example: 0.7 close, 0.3 ammoLow ---> min(0.7 + 0.3, 1.0) = 1.0 close OR
ammoLow

Defuzzification
Center of Gravity (CoG) / Centroid
This is the most commonly used defuzzification technique in engineering
because of its accuracy but isn't as commonly used in games because of its heavy
computation for complex membership functions.

Mean of Maxima (MoM)


This defuzzification technique takes the value with the highest degree of
fulfillment and the output is computed as:

Z = (A+B) / 2

Last of Maxima (LoM)


This defuzzification technique selects the largest output of the maximum
membership function as the crisp output.

Smallest of Maxima (SoM)


This defuzzification technique selects the smallest output of the maximum
membership function as the crisp output.

Graphical Demo for My Fuzzy System


Input a rule name and the values to be "fuzzified."
The rule is checked against the input values.
The corresponding fuzzy variables and fuzzy values are
graphically displayed on the screen along with their names, desirabilitys,
and DOM's.

You might also like