Course
Effective Period
: COMP6228 – Artificial Intelligence
: February 2017
Fuzzy Logic & Markov Systems
Session 09
Learning Objective
•
After completing this session, students are expected to be able to:
• LO 2 : Explain concepts of AI Techniques in Games
Content
•
•
•
•
•
Introduction to Fuzzy logic
Fuzzy Logic Decision Making
Fuzzy State Machines
Markov Processes
Markov State Machine
Fuzzy Logic Decision Making
Fuzzy logic studies reasoning systems in which the notions of truth
and falsehood are considered in a graded fashion, in contrast with
classical mathematics where only absolutly true statements are
considered.
Bob's Health
Prof. Lotfi Zadeh
• fuzzy logic is used for decision making and control systems
Fuzzy Logic Controller Flow
Fuzzy Sets Theory
• Classical Set vs Fuzzy set
Membership value
Membership value
1
1
0
0
175
Height(cm)
175
Height(cm)
Universe of discourse
6
example
Bina Nusantara University
7
example
Bina Nusantara University
8
Fuzzy components
9
Bina Nusantara University
Bina Nusantara University
9
fuzification
• Fuzzyfikasi: proses memetakan nilai crisp (numerik) ke dalam
himpunan fuzzy dan menentukan derajat keanggotaannya di
dalam himpunan fuzzy.
Bina Nusantara University
10
Operations on
Fuzzy Relation
Bina Nusantara University
11
Membership functions
Bina Nusantara University
12
Bina Nusantara University
13
Bina Nusantara University
14
example
Bina Nusantara University
15
answer
Bina Nusantara University
16
Bina Nusantara University
17
Example
• Suatu perusahaan minuman akan memproduksi minuman
jenis ABC. Dari data 1 bulan terakhir, permintaan terbesar
hingga mencapai 6000 botol/hari, dan permintaan terkecil
sampai 500 botol/hari. Persediaan barang digudang
terbanyak sampai 800 botol/hari, dan terkecil pernah sampai
200 botol/hari.
• Sampai saat ini, perusahaan baru mampu memproduksi
barang maksimum 9000 botol/hari, demi efisiensi mesin dan
SDM tiap hari diharapkan perusahaan memproduksi paling
tidak 3000 botol.
Bina Nusantara University
18
Apabila proses produksi perusahaan tersebut menggunakan 4 aturan
fuzzy sbb:
[R1]
IF Permintaan TURUN And Persediaan BANYAK
THEN Produksi Barang BERKURANG;
{R2]
IF Permintaan TURUN And Persediaan SEDIKIT
THEN Produksi Barang BERKURANG;
[R3]
IF Permintaan NAIK And Persediaan BANYAK
THEN Produksi Barang BERTAMBAH;
[R4]
IF Permintaan NAIK And Persediaan SEDIKIT
THEN Produksi Barang BERTAMBAH;
Berapa botol minuman jenis XYZ yang harus diproduksi, jika jumlah
permintaan sebanyak 4500 botol, dan persediaan di gudang masih 400
botol?
Bina Nusantara University
19
• Ada 3 variabel fuzzy yang akan dimodelkan, yaitu:
• Permintaan; terdiri-atas 2 himpunan fuzzy, yaitu: NAIK dan
TURUN
0,
x 500
x - 500
PmtNaik X
, 500 x 6000
5500
x 6000
1,
1,
x 500
6000 X
PmtTurun X
, 500 x 6000
5500
x 6000
0,
Cari nilai keanggotaan:
PmtTURUN[4500]
= (6000-4500)/5500
Fungsi keanggotaan variabel Permintaan
=
0,27
PmtNAIK[4500]
=
(4500-500)/5500
=
0,72
Bina Nusantara University
20
• Persediaan; terdiri-atas 2 himpunan fuzzy, yaitu: SEDIKIT dan
BANYAK
PsdSEDIKIT[400]
=
=
(600-400)/600
0,667
PsdBANYAK[400]
=
=
(400-200)/600
0,33
Fungsi keanggotaan variabel Persediaan
Bina Nusantara University
21
• Produksi barang; terdiri-atas 2 himpunan fuzzy, yaitu:
BERKURANG dan BERTAMBAH
z 3000
1,
9000 z
Pr BrgBERKURANG [ z]
, 3000 z 9000
6000
z 9000
0,
Fungsi keanggotaan variabel Produksi Barang
Bina Nusantara University
z 3000
0,
z 3000
Pr BrgBERTAMBAH [ z]
, 3000 z 9000
6000
z 9000
1,
22
• Sekarang kita cari nilai z untuk setiap aturan pada aplikasi fungsi
implikasinya:
[R1] IF Permintaan TURUN And Persediaan BANYAK
THEN Produksi Barang BERKURANG;
-predikat1
=
PmtTURUN PsdBANYAK
=
min(PmtTURUN [4500],PsdBANYAK[700])
=
min(0,27; 0,83)
=
0,27
Lihat himpunan Produksi Barang BERKURANG,
(9000-z)/6000 = 0,27 --->
z1 = 7380
23
{R2]
IF Permintaan TURUN And Persediaan SEDIKIT
THEN Produksi Barang BERKURANG;
-predikat2
=
PmtTURUN PsdSEDIKIT
=
min(PmtTURUN [4500],PsdSEDIKIT[700])
=
min(0,667; 0,337)
=
0,333
Lihat himpunan Produksi Barang BERKURANG,
(9000-z)/6000 = 0,333 --->
z2 = 7002
Bina Nusantara University
24
[R3]
IF Permintaan NAIK And Persediaan BANYAK
THEN Produksi Barang BERTAMBAH;
-predikat3
=
PmtNAIK PsdBANYAK
=
min(PmtNAIK
[4500],PsdBANYAK[400])
=
min(0,72; 0,33)
=
0,4
Lihat himpunan Produksi Barang BERTAMBAH,
(z-3000)/6000 = 0,333 --->
z3 = 4996
Bina Nusantara University
25
[R4]
IF Permintaan NAIK And Persediaan SEDIKIT
THEN Produksi Barang BERTAMBAH;
-predikat4
=
PmtNAIK PsdBANYAK
=
min(PmtNAIK
[4500],PsdSEDIKIT[400])
=
min(0,72; 0,667)
=
0,667
Lihat himpunan Produksi Barang BERTAMBAH,
(z-3000)/6000 = 0,667 --->
z4 = 7002
Bina Nusantara University
26
calculate z
• Dari sini kita dapat mencari berapakah nilai z, yaitu:
pred1 * z1 pred2 * z2 pred3 * z3 pred4 * z4
z
pred1 pred2 pred3 pred4
z
0,27 * 7380 0,333* 7002 0,33* 4993 0,667 * 7002 10643,3
6652
0,27 0,333 0,333 0,667
1,6
• Jadi jumlah minuman jenis XYZ yang harus diproduksi
sebanyak 6652 botol.
Bina Nusantara University
27
Bob's Healt at 65%
Fuzzy Logic Decision Making
Exclusive mapping to states for fuzzy decision making
(look further about the process at page 387-390 from your textbook)
Exercise
• Please run demo code of Fuzzy logic systems from the book:
Unity AI game programming, chapter 7
Fuzzy State Machines
• Although developers regularly talk about fuzzy state
machines, they don’t always mean the same thing by it.
• A fuzzy state machine can be any state machine with
some element of fuzziness.
• It can have transitions that use fuzzy logic to trigger, or it
might use fuzzy states rather than conventional states.
• It could even do both.
Markov Processes
Rantai markov (markov chain) adalah suatu metode yang
mempelajari sifat-sifat suatu variabel pada masa sekarang
yang didasarkan pada sifat-sifatnya di masa lalu dalam usaha
menaksir sifat-sifat variabel tersebut di masa yang akan
datang.
Markov Processes
Conservative Markov Process
•A conservative Markov process ensures that the sum of the
values in the state vector does not change over time.
•This is essential for applications where the sum of the state
vector should always be fixed (where it represents a
distribution, for example, or if the values represent the
number of some object in the game).
•The process will be conservative if all the rows in the
transition matrix sum to 1.
Markov Processes
Iterated Processes
•It is normally assumed that the same transition matrix
applies over and over again to the state vector.
•There are techniques to calculate what the final, stable
values in the state vector will be (it is an eigenvector of the
matrix, as long as such a vector exists).
•This iterative process forms a Markov chain.
•In game applications, however, it is common for there to be
any number of different transition matrices.
•Different transition matrices represent different events in the
game, and they update the state vector accordingly.
Markov Processes
• Returning to our sniper example, let’s say that we have a
state vector representing the safety of four sniping
positions:
which sums to 4.0.
• Taking a shot from the first position will alert the enemy to
its existence. The safety of that position will diminish. But,
while the enemy is focusing on the direction of the attack,
the other positions will be correspondingly safer. We could
use the transition matrix:
Markov Processes
• to represent this case. Applying this to the state vector, we
get the new safety values:
which sums to 3.4.
• So the total safety has gone down (from 4.0 to 3.4). The
safety of sniping point 1 has been decimated (from 1.0 to
0.1), but the safety of the other three points has marginally
increased. There would be similar matrices for shooting
from each of the other sniping points.
Markov Processes
• Notice that if each matrix had the same kind of form, the
overall safety would keep decreasing. After a while,
nowhere would be safe. This might be realistic (after being
sniped at for a while, the enemy is likely to make sure that
nowhere is safe), but in a game we might want the safety
values to increase if no shots are fired. A matrix such as:
would achieve this, if it is applied once for every minute that
passes without gunfire.
Markov State Machines
• Using Markov processes, we can create a decision making
tool that uses numeric values for its states.
• The state machine will need to respond to conditions or
events in the game by executing a transition on the state
vector.
• If no conditions or events occur for a while, then a default
transition can occur.
References
• Ian Millington. 2009. Artificial intelligence for games.
Morgan Kaufmann Publishers. Burlington.
ISBN:9780123747310
• Stuart Russell. (2010). Artificial intelligence : a modern
approach. 03. Pearson Education. New Jersey. ISBN:
9780132071482.
© Copyright 2026 Paperzz