inference first order logic - share...
TRANSCRIPT
Inference First Order Logic
Chastine Fatichah
Teknik Informatika
Institut Teknologi Sepuluh Nopember
November 2012
12/10/2012 1 Inference First Order Logic @ Kecerdasan Buatan
(KI092301)
Kecerdasan Buatan (KI092301)
Pokok Bahasan
• Mengubah First Order Logic ke Propotional
Logic
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
• Ringkasan
12/10/2012 2 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Sejarah Reasoning
• 450b.c. Stoics propositional logic, inference
• 322b.c. Aristotle “syllogisms" (inference rules), quantifiers
• 1565 Cardano probability theory (propositional logic +
uncertainty)
• 1847 Boole propositional logic (again)
• 1879 Frege logic
• 1922 Wittgenstein proof by truth tables
• 1930 Gӧdel complete algorithm for FOL
• 1930 Herbrand complete algorithm for FOL (reduce to
propositional)
• 1931 Gӧdel complete algorithm for arithmetic
• 1960 Davis/Putnam “practical" algorithm for propositional logic
• 1965 Robinson “practical" algorithm for FOL resolution
12/10/2012 Inference First Order Logic @
Kecerdasan Buatan (KI092301) 3
Pokok Bahasan
• Mengubah First Order Logic ke Propotional
Logic
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
• Ringkasan
12/10/2012 4 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Universal instantiation (UI)
Semua kalimat dengan universal quantifier () meng-entail
semua instantiation-nya:
v α
Subst({v/g}, α)
untuk sembarang variabel v and ground term g
12/10/2012 5 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
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))
Contoh
Existential instantiation (EI)
Untuk sembarang kalimat α, variabel v, and konstanta k
yang tidak muncul di knowledge-base:
v α
Subst({v/k}, α)
12/10/2012 6 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
x Crown(x) OnHead(x,John) meng-entail:
Crown(C1) OnHead(C1,John) Dengan syarat C1 adalah konstanta baru, disebut konstanta Skolem
Contoh
Existential instantiation (EI)
• Universal instantiation bisa digunakan berkali-
kali untuk menambahkan kalimat baru.
• KB yang baru logically equivalent dengan yang
lama.
• 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
12/10/2012 Inference First Order Logic @
Kecerdasan Buatan (KI092301) 7
Mengubah ke Propositional Inference Misalkan KB berisi kalimat-kalimat berikut:
Dan jika kita mengambil semua kemungkinan instantiation dari kalimat universal, maka kita dapatkan KB sbb:
KB yang baru disebut propositionalized: proposition symbolnya adalah:
King(John), Greedy(John), Evil(John), King(Richard), dll.
12/10/2012 8 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
x King(x) Greedy(x) Evil(x) King(John) Greedy(John) Brother(Richard,John)
King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(John) Greedy(John) Brother(Richard,John)
Mengubah ke Propositional
Inference • Klaim : Setiap FOL KB dapat di propositional kan
sebagai entailment
• Klaim: Kalimat ground di entail dengan KB baru jika dan
hanya jika entail terhadap original KB
• Idea: propositionalize KB dan query, lalu gunakan
resolution
• Problem: dengan adanya function, ground terms menjadi
infinite.
• Contoh: Father(Father(Father(John)))
12/10/2012 9 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Masalah dengan propositionalization • Propositionalization menghasilkan banyak kalimat irrelevant.
• Contoh: x King(x) Greedy(x) Evil(x)
King(John)
y Greedy(y)
Brother(Richard,John)
manusia bisa cepat mengerti kalau Evil(John), namun
propositionalization menghasilkan:
King(Richard) Greedy(Richard) Evil(Richard)
Greedy(Richard)
yang irrelevant
• Dengan p predicate k-ary dan n constant, ada p x nk instantiation!
12/10/2012 10 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Pokok Bahasan
• Mengubah First Order Logic ke Propotional
Logic
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
• Ringkasan
12/10/2012 11 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Unification • Inference : Substitution θ sedemikian hingga King(x) dan Greedy(x)
cocok dengan King(John) dan Greedy(y)
θ = {x/John,y/John}
• Unify(α,β) = θ jika αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane)
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
12/10/2012 12 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Unification • Inference : Substitution θ sedemikian hingga King(x) dan Greedy(x)
cocok dengan King(John) dan Greedy(y)
θ = {x/John,y/John}
• Unify(α,β) = θ jika αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
12/10/2012 13 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Unification • Inference : Substitution θ sedemikian hingga King(x) dan Greedy(x)
cocok dengan King(John) dan Greedy(y)
θ = {x/John,y/John}
• Unify(α,β) = θ jika αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
12/10/2012 14 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Unification • Inference : Substitution θ sedemikian hingga King(x) dan Greedy(x)
cocok dengan King(John) dan Greedy(y)
θ = {x/John,y/John}
• Unify(α,β) = θ jika αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ)
12/10/2012 15 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Unification • Inference : Substitution θ sedemikian hingga King(x) dan Greedy(x)
cocok dengan King(John) dan Greedy(y)
θ = {x/John,y/John}
• Unify(α,β) = θ jika αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ) {fail}
• Standardizing apart variable menghilangkan overlap, contoh
Knows(z17,OJ)
12/10/2012 16 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Pokok Bahasan
• Mengubah First Order Logic ke Propotional
Logic
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
• Ringkasan
12/10/2012 17 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Generalized Modus Ponens
(GMP)
p1' is King(John) p1 is King(x)
p2' is Greedy(y) p2 is Greedy(x)
θ is {x/John,y/John} q is Evil(x)
q θ is Evil(John)
• GMP dengan KB yang berisi definite clauses: p1 p2 … pn q
• Semua variabel diasumsikan universally quantified
12/10/2012 18 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
p1', p2', … , pn', ( p1 p2 … pn q)
qθ
dimana pi'θ = pi θ untuk semua i
Inference Rule GMP
Soundness pada GMP
• Perlu menunjukkan bahwa
p1', …, pn', (p1 … pn q) ╞ qθ
dimana pi'θ = piθ untuk semua i
• Lemma: Untuk setiap definite clause p, terdapat p ╞ pθ dengan Universal instantiation (UI)
1. (p1 … pn q) ╞ (p1 … pn q)θ = (p1θ … pnθ qθ)
2. p1', …, pn' ╞ p1' … pn' ╞ p1'θ … pn'θ
3. Dari 1 dan 2, qθ mengikuti Modus Ponens
12/10/2012 19 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Knowledge Base
Buktikan bahwa Colonel West is a criminal !!
12/10/2012 20 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
“ 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. “
Contoh Knowledge Base • ... 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)
• Nono … has some missiles: x Owns(Nono,x) Missile(x):
Owns(Nono,M1) and Missile(M1)
• … all of its missiles were sold to it by Colonel West
Missile(x) Owns(Nono,x) Sells(West,x,Nono)
• Missiles are weapons:
Missile(x) Weapon(x)
• An enemy of America counts as "hostile“:
Enemy(x,America) Hostile(x)
• West, who is American …
American(West)
• The country Nono, an enemy of America …
Enemy(Nono,America)
12/10/2012 21 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Pokok Bahasan
• Mengubah First Order Logic ke Propotional
Logic
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
• Ringkasan
12/10/2012 22 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Forward chaining FOL
dengan GMP
12/10/2012 23 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Algoritma forward chaining
Contoh Forward chaining FOL
12/10/2012 24 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Forward chaining FOL
12/10/2012 25 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Forward chaining FOL
12/10/2012 26 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Forward chaining properti
• Sound dan complete untuk first-order definite clauses
• Datalog = first-order definite clauses + tanpa function
Time complexity FC pada Datalog polynomial
• Tapi pada kasus umum, bisa infinite loop kalau tidak di-
entail.
• Proses pattern matching pada premise NP-hard.
12/10/2012 27 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Pokok Bahasan
• Mengubah First Order Logic ke Propotional
Logic
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
• Ringkasan
12/10/2012 29 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Algoritma backward chaining
Backward chaining FOL
dengan GMP
SUBST(COMPOSE(θ1, θ2), p) = SUBST(θ2, SUBST(θ1, p))
12/10/2012 30 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 31 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 32 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 33 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 34 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 35 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 36 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 37 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Contoh Backward chaining FOL
12/10/2012 38 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Backward chaining properti
• Depth-first search:
• linear space complexity
• incomplete (infinite loops)
• inefficient (repeated subgoals)
• Prinsip dasar logic programming
12/10/2012 39 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Logic programming: Prolog
Logic programming Ordinary programming
1. Identify problem Identify problem
2. Assemble information Assemble information
3. Tea break Figure out solution
4. Encode information in KB Program solution
5. Encode problem instance as facts Encode problem instance as data
6. Ask queries Apply program to data
7. Find false facts Debug procedural errors
(Harusnya) lebih mudah men-debug Capital(NewYork;US) daripada x = x + 2 !
12/10/2012 40 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Prolog
• Appending two lists to produce a third:
append([],Y,Y).
append([X|L],Y,[X|Z]) :- append(L,Y,Z).
• query: append(A,B,[1,2]) ?
• answers: A=[] B=[1,2]
•
A=[1] B=[2]
A=[1,2] B=[]
12/10/2012 41 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Konversi ke CNF
• Everyone who loves all animals is loved by someone: x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
• 1. Eliminasi biconditionals dan implikasi x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
• 2. Pindah inwards: 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)]
12/10/2012 42 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Konversi ke CNF.
3. Standarisasi variabel: x [y Animal(y) Loves(x,y)] [z Loves(z,x)]
4. Skolemize: bentuk umum pada existential instantiation. Setiap variabel existential diganti dengan Skolem function pada universally
quantified variables:
x [Animal(F(x)) Loves(x,F(x))] Loves(G(x),x)
5. Hapus semua universal quantifiers: [Animal(F(x)) Loves(x,F(x))] Loves(G(x),x)
6. Distribusi over : [Animal(F(x)) Loves(G(x),x)] [Loves(x,F(x)) Loves(G(x),x)]
12/10/2012 43 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
Resolution proof: definite clauses
12/10/2012 44 Inference First Order Logic @
Kecerdasan Buatan (KI092301)
12/10/2012 Inference First Order Logic @
Kecerdasan Buatan (KI092301) 45
Sumber :
1.Slide perkuliahan Stuart Russell's (Berkeley) http://aima.cs.berkeley.edu/
2.Slide perkuliahan Sistem Cerdas Ruli Manurung (Universitas Indonesia)
http://www.cs.ui.ac.id/WebKuliah/IKI30320/