Anda di halaman 1dari 35

Kecerdasan Buatan/

Artificial Intelligence

Inferensi pada FOL


(First Order Logic)
Pokok Bahasan
1. Mengubah FOL inference ke PL inference
2. Unification
3. Inference Rule untuk FOL
4. Forward chaining
5. Backward chaining
6. Resolution
7. Latihan Individu + Tugas Kelompok
FOL to PL
 Ide tahun 60-an :
o Kita sudah melihat mekanisme inference untuk propositional logic
 Inference rule : Modus Ponens
Normal form : Horn clause
Algoritma : Forward chaining, Backward chaining
 Inference rule : Resolution
Normal form : Clause Normal Form (CNF)
Algoritma : Proof-by-contradiction
o Pendekatan-pendekatan ini sound dan complete.
o Cara mudah melakukan inference FOL :
 Jika KB dan query dalam FOL bisa diterjemahkan ke dalam
PL, beres!
Note : Horn clause adalah bentuk khusus dari logika predikat yang digunakan sebagai sintaks
bahasa Prolog. Horn clause mempunyai head h yang disebut sebagai predikat, dan body
yang disebut sebagai daftar dari predikat p1;p2;….;pn.
FOL to PL
 Instantiation :
o Ground term : sebuah term tanpa variable, mis: Ani, Ayah(Anto),
2007
o Instantiation : kalimat di mana sebuah variable diganti dengan
sebuah ground term (diperoleh dengan mengaplikasikan sebuah
substitution)
o Contoh :
 α = ∀ x mahasiswa(x , PTIIKUB) ⇒ Genius(x )
 β = ∃ x mahasiswa(x , Gundar ) ∧ pintar (x )
 σ = {x /Anto}
 SUBST(σ, α) menghasilkan instantiation :
• mahasiswa(Anto, PTIIKUB) ⇒ Genius(Anto)
• SUBST(σ, β) menghasilkan instantiation:
• mahasiswa(Anto, Gundar ) ∧ pintar (Anto)
FOL to PL
 Universal Instantiation :
o Sebuah kalimat dengan universal quantifier (∀) meng-entail
semua instantiation-nya:
___∀ v α _________
SUBST ({v /g},α)
o untuk sembarang variable v dan ground term g
o Contoh :
 ∀ x King(x ) ∧ Greedy (x ) ⇒ Evil (x ) meng-entail :
• King(John) ∧ Greedy (John) ⇒ Evil (John)
• King(Richard ) ∧ Greedy (Richard ) ⇒ Evil (Richard )
• King(Father (John)) ∧ Greedy (Father (John)) ⇒ Evil
(Father (John))
……
FOL to PL
 Existential Instantiation :
o Untuk sembarang variable v, kalimat α dan constant k yang tidak
muncul di knowledge-base :
___∃ v α _________
SUBST ({v / k},α)
o Contoh :
 ∃ x Crown(x) ∧ OnHead (x , John) meng-entail :
• Crown(C1) ∧ OnHead (C1, John), dengan syarat C1 adalah
constant symbol yang baru, disebut Skolem constant.
……
FOL to PL
 Menghilangkan quantifier dan variable :
o Menghilangkan ∀ :
 Universal instantiation bisa digunakan berkali-kali untuk
menambahkan kalimat baru.
 KB yang baru logically equivalent dengan yang lama.

o Menghilangkan ∃ :
 Existential instantiation cukup digunakan sekali untuk
menggantikan kalimat existential.
 KB yang baru tidak logically equivalent dengan yang lama,
tetapi satisfiable iff KB yang lama juga satisfiable →
inferentially equivalent

Note : dikatakan satisfiable jika bernilai true pada beberapa


model
FOL to PL
 Contoh :
o Andaikan KB berisi kalimat-kalimat berikut :
∀ x King(x) ∧ Greedy (x) ⇒ Evil (x) ∀ y Greedy (y)
King(John) Brother (Richard , John)
o Jika kita mengambil semua kemungkinan instantiation dari
kalimat universal, kita dapatkan KB sbb :
King(John) ∧ Greedy (John) ⇒ Evil (John)
King(Richard) ∧ Greedy (Richard ) ⇒ Evil (Richard)
Greedy (John) Greedy (Richard)
King(John) Brother (Richard , John)
o KB yang baru dikatakan propositionalized : proposition
symbol-nya : King(John), Greedy (John), Evil (John),
King(Richard) etc.
FOL to PL
 Inference FOL menggunakan inference PL :
o Ide dasar : ubah KB + query dari FOL menjadi PL, lalu gunakan
resolution.
o Masalah : dengan adanya function, jumlah ground term menjadi
infinite.
 Greedy (Father (John)), Greedy (Father (Father (John)))
 Greedy (Father (Father (Father (John)))), dst.
o Teorema Herbrand (1930) : jika FOL KB |= α, ada sebuah finite
subset PL KB |= α.
o Ide dasar : For n = 0 to ∞
• Buat propositional KBn dengan depth-n ground term
• Periksa apakah KBn |= α
o Masalah (lagi!) : kalau α di-entail OK, kalau tidak → infinite loop.
o Teorema Church-Turing (1936) : Entailment untuk FOL bersifat
semidecidable. (tidak dapat diperbandingkan)
FOL to PL
 Masalah dengan propositionalization :
o Propositionalization menghasilkan banyak kalimat irelevan.
o Contohnya, dari KB berikut :
 ∀ x King(x) ∧ Greedy (x) ⇒ Evil (x)
 ∀ y Greedy (y)
 King(John)
 Brother (Richard , John)
manusia bisa cepat mengerti kalau Evil (John), namun
propositionalization menghasilkan :
 King(Richard) ∧ Greedy(Richard) ⇒ Evil (Richard)
 Greedy (Richard)
yang tidak relevan.
o Dengan p buah predicate k-ary dan n constant, ada p × nk
instantiation!
Unification
 Isi KB :
o ∀ x King(x) ∧ Greedy (x) ⇒ Evil (x)
o ∀ y Greedy (y)
o King(John)
o Brother (Richard , John)
Inference bahwa KB |= Evil (John) bisa langsung disimpulkan jika
kita bisa mencari substitution θ sehingga King(x) dan Greedy (x)
bisa “dicocokkan” dengan King(John) dan Greedy (y).
Contoh: θ = {x /John, y /John}
 Definisi unification
o UNIFY(α, β) = θ jika SUBST(α,θ) = SUBST(β,θ)
Unification
 Contoh unification :
P q θ
Sayang(Anto, x ) Sayang(Anto, Ani ) {x /Ani }
Sayang(Anto, x ) Sayang(y , Ani ) {x /Ani , y /Anto}
Sayang(Anto, x ) Sayang(y , Ibu (y )) {y /Anto, x /Ibu
(Anto)}
Sayang(Anto, x ) Sayang(x , Ani ) fail

o Standardized apart variable menghilangkan overlap, mis:


Sayang(x101, Ani)
Inference Rule untuk FOL
 Generalized Modus Ponens (GMP) :
o Inference rule GMP :
p1’, p2’, . . . , pn’, (p1 ∧ p2 ∧ . . . ∧ pn ⇒ q)

di mana pi’θ = piθ untuk semua i.
p1’ = King(John) p1 = King(x)
p2’ = Greedy(y) p2 = Greedy(x)
θ = {x /John, y /John} q = Evil(x)
qθ = Evil (John)
o GMP dengan KB yang berisi definite clauses (seperti Horn clause
pada PL): p1 ∧ p2 ∧ . . . ∧ pn ⇒ q
o Semua variable diasumsikan universally quantified
o GMP adalah hasil lifting MP : “mengangkat” inference rule PL ke
FOL.
o Kelebihan dibanding propositionalization : hanya melakukan
substitution yang dibutuhkan oleh inference
Inference Rule untuk FOL
 Contoh knowledge base :
o Kalimat : “The law says that, it is a crime for an American to
sell weapons to hostile nations. The country Nono, an enemy
of America, has some missiles, and all of its missiles were sold
to it by Colonel West, who is American.”
o Kalimat : “Hukum mengatakan bahwa, suatu kejahatan bagi
orang Amerika yang menjual senjata ke negara-negara yang
bermusuhan. Negara Nono dalah musuh Amerika, yang
memiliki beberapa rudal, dan semua rudalnya dari yang dijual
oleh Kolonel West, yang merupakan orang Amerika.
Buktikan bahwa Col. West adalah criminal!
o Penyelesaian :
o . . . it is a crime for an American to sell weapons to hostile nations :
American(x) ∧ Weapon(y) ∧ Sells(x , y , z ) ∧ Hostile(z) ⇒ Criminal(x)
Inference Rule untuk FOL
 Contoh knowledge base :
o Kalimat : “The law says that, it is a crime for an American to sell weapons to hostile
nations. The country Nono, an enemy of America, has some missiles, and all of its missiles
were sold to it by Colonel West, who is American.”
Buktikan bahwa Col. West adalah criminal!
o Penyelesaian :
o . . . it is a crime for an American to sell weapons to hostile nations :
American(x ) ∧ Weapon(y) ∧ Sells(x , y , z ) ∧ Hostile(z ) ⇒ Criminal(x)
o Nono . . . has some missiles : ∃ x Owns(Nono, x ) ∧ Missile(x )
Owns(Nono, M1) and Missile(M1) (Skolemization)
o . . . all of its missiles were sold to it by Colonel West :
Missile(x ) ∧ Owns(Nono, x ) ⇒ Sells(West, x , Nono)
o Missiles are weapons : Missile(x ) ⇒ Weapon(x)
o An enemy of America counts as “hostile” :
Enemy (x , America) ⇒ Hostile(x )
o West, who is American . . . :
American(West)
o The country Nono, an enemy of America . . . :
Enemy (Nono, America)
Perhatikan :
Semua kalimat KB tersebut berbentuk definite clause.
Forward Chaining
 Forward chaining pada FOL dengan GMP (Generalized Modus
Ponens) :
o Mirip dengan forward chaining pada PL.
o Mulai dari fakta yang diketahui (clause tanpa premise), mis :
Owns(Nono, M1), Missile(M1)
o “Aktifkan” (trigger) rule yang premise-nya diketahui (satisfied)
→ tambahkan kesimpulan rule ke KB, mis :
Missile(x ) ∧ Owns(Nono, x ) ⇒ Sells(West, x , Nono)
o Ulangi sampai query terbukti, atau tidak ada fakta baru yang
bisa ditambahkan ke KB.
o “Cocokkan” premise-premise setiap rule dengan fakta yang
diketahui → pattern-matching dengan unification
Forward Chaining
 Algoritma forward chaining :
Forward Chaining
 Contoh Forward Chaining FOL :
o. . . it is a crime for an American to sell weapons to hostile nations :
American(x ) ∧ Weapon(y) ∧ Sells(x , y , z ) ∧ Hostile(z ) ⇒ Criminal(x)
oNono . . . has some missiles : ∃ x Owns(Nono, x ) ∧ Missile(x )
Owns(Nono, M1) and Missile(M1) (Skolemization)
o. . . all of its missiles were sold to it by Colonel West :
Missile(x ) ∧ Owns(Nono, x ) ⇒ Sells(West, x , Nono)
oMissiles are weapons : Missile(x ) ⇒ Weapon(x)
oAn enemy of America counts as “hostile” :
Enemy (x , America) ⇒ Hostile(x )
oWest, who is American . . . :
American(West)
oThe country Nono, an enemy of America . . . :
Enemy (Nono, America)
Forward Chaining
 Contoh Forward Chaining FOL :
o. . . it is a crime for an American to sell weapons to hostile nations :
American(x ) ∧ Weapon(y) ∧ Sells(x , y , z ) ∧ Hostile(z ) ⇒ Criminal(x)
oNono . . . has some missiles : ∃ x Owns(Nono, x ) ∧ Missile(x )
Owns(Nono, M1) and Missile(M1) (Skolemization)
o. . . all of its missiles were sold to it by Colonel West :
Missile(x ) ∧ Owns(Nono, x ) ⇒ Sells(West, x , Nono)
oMissiles are weapons : Missile(x ) ⇒ Weapon(x)
oAn enemy of America counts as “hostile” :
Enemy (x , America) ⇒ Hostile(x )
oWest, who is American . . . :
American(West)
oThe country Nono, an enemy of America . . . :
Enemy (Nono, America)
Forward Chaining
 Contoh Forward Chaining FOL :
Forward Chaining
 Sifat Forward Chaining :
o Sound dan complete untuk first-order definite clause.
o Datalog = first-order definite clause tanpa function.
Time complexity FC pada Datalog → polynomial
o Tapi pada kasus umum, bisa infinite loop kalau α tidak di-entail. (Konsekuensi dari teorema Church-
Turing : entailment adalah semidecidable)
o Proses pattern matching pada premise NP-hard.
 Pattern matching premise NP-hard(Non-deterministic Polynomial-time hard)?

Diff(wa, nt ) ∧ Diff(wa, sa)∧


Diff(nt , q) ∧ Diff(nt , sa)∧
Diff(q, nsw ) ∧ Diff(q, sa)∧
Diff(nsw , v ) ∧ Diff(nsw , sa)∧
Diff(v , sa) ⇒ Colorable()
Diff(Red , Blue)
Diff(Red , Green)
Diff(Green, Red )
Diff(Green, Blue)
Diff(Blue, Red )
Diff(Blue, Green)
o Query ASK(KB,Colorable()) jhj CSP-nya menemui solusi!
o Terdapat kasus CSP 3SAT (satisfiability pada CNF dengan clause berukuran 3 literal) yang diketahui NP-
hard.
Backward chaining
 Backward chaining pada FOL dengan GMP :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Contoh Backward Chaining FOL :
Backward chaining
 Sifat Backward Chaining :
o Depth-first search :
 linear space complexity 
 incomplete (infinite loop) 
 repeated state 
o Prinsip dasar Logic Programming
Resolution
 Resolution pada FOL :
o Resolution inference rule pada FOL (lifting resolution PL) :

di mana
o Contoh :

di mana θ = {x /Anto}

o Gunakan resolution rule pada CNF (KB ∧ ¬α): complete untuk FOL
Resolution
 Mengubah FOL ke CNF :
“Everyone who loves all animals is loved by someone:”
∀ x [∀ y Animal (y ) = ⇒ Loves(x , y )] = ⇒ [∃ y Loves(y , x )]
o Eliminasi implikasi dan biimplikasi
∀ x [¬∀ y ¬Animal (y ) ∨ Loves(x , y )] ∨ [∃ y Loves(y , x )]
o Pindahkan ¬ ke “dalam”: ¬∀ x , p ≡ ∃ x ¬p, ¬∃ x , p ≡ ∀ x ¬p :
∀ x [∃ y ¬(¬Animal (y ) ∨ Loves(x , y ))] ∨ [∃ y Loves(y , x )]
∀ x [∃ y ¬¬Animal (y ) ∧ ¬Loves(x , y )] ∨ [∃ y Loves(y , x )]
∀ x [∃ y Animal (y ) ∧ ¬Loves(x , y )] ∨ [∃ y Loves(y , x )]
o Standardize variables: setiap quantifier variable-nya beda
∀ x [∃ y Animal (y ) ∧ ¬Loves(x , y )] ∨ [∃ z Loves(z , x )]
o Skolemize: generalisasi existential instantiation. ∃ x diganti Skolem function universal
quantified variable di “luar” :
∀ x [Animal (F (x )) ∧ ¬Loves(x , F (x ))] ∨ Loves(G(x ), x )
o Buang universal quantifiers :
[Animal (F (x )) ∧ ¬Loves(x , F (x ))] ∨ Loves(G(x ), x )
o Distribusi ∧ over ∨ :
[Animal (F (x )) ∨ Loves(G(x ), x )] ∧ [¬Loves(x , F (x )) ∨ Loves(G(x ), x )]
Resolution
 Contoh pembuktian dengan resolution :
Tugas Kelompok
 Jelaskan konsep Inference FOL?
 Ubahlah FOL berikut menjadi bentuk CNF
o ∀ x [∀ y A(y )  L(x , y )]  [∃ y L(y , x )]
o ∀ x ∀ y [P(x ) ˄ Q(y )]  [∃ z R(x, y, z)]
o ∃ x ∀ y ∃ z [P(x)  [ Q(y )  R(z)] ]
o Not everybody is your friend or someone is not perfect
 Buat Case Study “Kreatif” kemudian selesaikan menggunakan :
 Forward Chaining
 Backward Chaining
Selesai

Anda mungkin juga menyukai