Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chương 3 Tri thức và lập luận Nội dung chính chương 3 I. Logic – ngôn ngữ của tư duy Lecture 1 Lecture 2 Lecture 3,4 II. Logic mệnh đề (cú pháp, ngữ nghĩa, sức mạnh biểu diễn, các thuật toán suy diễn) III. Prolog (cú pháp, ngữ nghĩa, lập trình prolog, bài tập và thực hành) IV. Logic cấp một (cú pháp, ngữ nghĩa, sức mạnh biểu diễn, các thuật toán suy diễn) Lecture 4 Inference in First-Order Logic Lecture 4: Inference in First-Order Logic - Outline Proofs (chứng minh) Unification (hợp nhất) Generalized modus ponens - GMP(Luật modus ponens tổng quát) Inference procedures based on GMP (các thủ tục dựa trên luật modus ponens tổng quát) • Forward chaining (suy diễn tiến) • Backward chaining (suy diễn lùi) Incompleteness of GMP-based inferences (tính không đầy đủ của suy diễn tiến và lùi). Inference procedures based on Resolution (thủ tục suy diễn hợp giải, thủ tục có tính đầy đủ trong logic cấp một) Logic programming (lập trình logic) CS 561, Session 16-18 4 Entailment and proof - Hệ quả logic và chứng minh CS 561, Session 16-18 5 Remember: propositional logic Nhớ lại: Các định lý trong logic mệnh đề CS 561, Session 16-18 6 Proofs – chứng minh CS 561, Session 16-18 7 Proofs – Chứng minh (tiếp) The three new inference rules for FOL (compared to propositional logic) are: • Universal Elimination (UE): for any sentence , variable x and ground term , x {x/} • Existential Elimination (EE): for any sentence , variable x and constant symbol k not in KB, x {x/k} • Existential Introduction (EI): for any sentence , variable x not in and ground term g in , x {g/x} CS 561, Session 16-18 8 Proofs – Chứng minh (tiếp) The three new inference rules for FOL (compared to propositional logic) are: • Universal Elimination (UE): for any sentence , variable x and ground term , x e.g., from x Likes(x, Candy) and {x/Joe} {x/} we can infer Likes(Joe, Candy) • Existential Elimination (EE): for any sentence , variable x and constant symbol k not in KB, x e.g., from x Kill(x, Victim) we can infer {x/k} Kill(Murderer, Victim), if Murderer new symbol • Existential Introduction (EI): for any sentence , variable x not in and ground term g in , e.g., from Likes(Joe, Candy) we can infer x {g/x} x Likes(x, Candy) CS 561, Session 16-18 9 Example Proof CS 561, Session 16-18 10 Example Proof CS 561, Session 16-18 11 Example Proof CS 561, Session 16-18 12 Example Proof CS 561, Session 16-18 13 Search with primitive example rules CS 561, Session 16-18 14 Unification – Hợp nhất • Unification is a "pattern matching" procedure that takes two atomic sentences, called literals, as input, and returns "failure" if they do not match and a substitution list, Theta, if they do match. • That is, unify(p,q) = Theta means subst(Theta, p) = subst(Theta, q) for two atomic sentences p and q. • Theta is called the most general unifier (mgu) • All variables in the given two literals are implicitly universally quantified • To make literals match, replace (universallyquantified) variables by terms Unification – Hợp nhất Goal of unification: finding σ CS 561, Session 16-18 16 Unification – Hợp nhất CS 561, Session 16-18 17 Unification Algorithm – Giải thuật hợp nhất procedure unify(p, q, theta) Scan p and q left-to-right and find the first corresponding terms where p and q "disagree" ; where p and q not equal If there is no disagreement, return theta ; success Let r and s be the terms in p and q, respectively, where disagreement first occurs If variable(r) then theta = union(theta, {r/s}) unify(subst(theta, p), subst(theta, q), theta) else if variable(s) then theta = union(theta, {s/r}) unify(subst(theta, p), subst(theta, q), theta) else return "failure" end Unification… • Examples Literal 1 Literal 2 theta parents(x, father(x), mother(Bill)) parents(Bill, father(Bill), y) {x/Bill, y/mother(Bill)} parents(x, father(x), mother(Bill)) parents(Bill, father(y), z) {x/Bill, y/Bill, z/mother(Bill)} parents(x, father(x), mother(Jane)) parents(Bill, father(y), mother(y)) Failure More Unification Examples VARIABLE 1 – unify(P(a,X), P(a,b)) 2 – unify(P(a,X), P(Y,b)) 3 – unify(P(a,X), P(Y,f(a)) 4 – unify(P(a,X), P(X,b)) term σ = {X/b} σ = {Y/a, X/b} σ = {Y/a, X/f(a)} σ = failure Note: If P(a,X) and P(X,b) are independent, then we can replace X with Y and get the unification to work. CS 561, Session 16-18 20 Generalized Modus Ponens (GMP) - Luật Modus Ponens tổng quát CS 561, Session 16-18 21 Soundness of GMP – Tính đúng đắn của GMP CS 561, Session 16-18 22 Horn form – Dạng câu Horn • We convert sentences to Horn form as they are entered into the KB • Using Existential Elimination and And Elimination • e.g., x Owns(Nono, x) Missile(x) becomes Owns(Nono, M) Missile(M) (with M a new symbol that was not already in the KB) CS 561, Session 16-18 23 Forward chaining procedure – Thủ tục suy diễn tiến CS 561, Session 16-18 24 Backward chaining procedure – Thủ tục suy diễn lùi CS 561, Session 16-18 25 An Example (from Konelsky) • Nintendo example. • Nintendo says it is Criminal for a programmer to provide emulators to people. My friends don’t have a Nintendo 64, but they use software that runs N64 games on their PC, which is written by Reality Man, who is a programmer. • Query: Has Reality Man done anything criminal? CS 561, Session 16-18 26 Forward Chaining Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) Software(x) Runs(x, N64 games) Emulator(x) Programmer(Reality Man) People(friends) Software(U64) Use(friends, U64) Runs(U64, N64 games) (1) (2) (3) (4) (5) (6) (7) (8) • Premises (6), (7) and (8) satisfy the implications fully. CS 561, Session 16-18 27 Forward Chaining Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) Software(x) Runs(x, N64 games) Emulator(x) (1) (2) (3) Programmer(Reality Man) People(friends) Software(U64) Use(friends, U64) Runs(U64, N64 games) (4) (5) (6) (7) (8) • So we can infer the consequents, which are now added to the knowledge base (this is done in two separate steps). CS 561, Session 16-18 28 Forward Chaining • Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) (1) Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) (2) Software(x) Runs(x, N64 games) Emulator(x) (3) Programmer(Reality Man) (4) People(friends) (5) Software(U64) (6) Use(friends, U64) (7) Runs(U64, N64 games) (8) Provide(Reality Man, friends, U64) (9) Emulator(U64) (10) Addition of these new facts triggers further forward chaining. CS 561, Session 16-18 29 Forward Chaining Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) (1) Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) (2) Software(x) Runs(x, N64 games) Emulator(x) (3) Programmer(Reality Man) (4) People(friends) (5) Software(U64) (6) Use(friends, U64) (7) Runs(U64, N64 games) (8) Provide(Reality Man, friends, U64) (9) Emulator(U64) (10) Criminal(Reality Man) (11) • Which results in the final conclusion: Criminal(Reality Man) CS 561, Session 16-18 30 Backward Chaining • Question: Has Reality Man done anything criminal? • We will use the same knowledge as in our forward-chaining version of this example: Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) Software(x) Runs(x, N64 games) Emulator(x) Programmer(Reality Man) People(friends) Software(U64) Use(friends, U64) Runs(U64, N64 games) CS 561, Session 16-18 31 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) CS 561, Session 16-18 32 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) Yes, {x/Reality Man} CS 561, Session 16-18 33 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) People(Z) Yes, {x/Reality Man} Yes, {z/friends} CS 561, Session 16-18 34 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) Yes, {x/Reality Man} Emulator(y) People(Z) Yes, {z/friends} CS 561, Session 16-18 35 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) Yes, {x/Reality Man} Emulator(y) People(z) Yes, {z/friends} Software(y) Yes, {y/U64} CS 561, Session 16-18 36 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) Yes, {x/Reality Man} Emulator(y) People(z) Yes, {z/friends} Software(y) Yes, {y/U64} Runs(U64, N64 games) yes, {} CS 561, Session 16-18 37 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) Yes, {x/Reality Man} Emulator(y) People(z) Yes, {z/friends} Provide (reality man, U64, friends) Software(y) Runs(U64, N64 games) Yes, {y/U64} yes, {} CS 561, Session 16-18 38 Backward Chaining • Question: Has Reality Man done anything criminal? Criminal(x) Programmer(x) Emulator(y) Yes, {x/Reality Man} People(z) Yes, {z/friends} Provide (reality man, U64, friends) Software(y) Yes, {y/U64} Use(friends, U64) CS 561, Session 16-18 Runs(U64, N64 games) yes, {} 39 Backward Chaining • Backward Chaining benefits from the fact that it is directed toward proving one statement or answering one question. • In a focused, specific knowledge base, this greatly decreases the amount of superfluous work that needs to be done in searches. • However, in broad knowledge bases with extensive information and numerous implications, many search paths may be irrelevant to the desired conclusion. • Unlike forward chaining, where all possible inferences are made, a strictly backward chaining system makes inferences only when called upon to answer a query. CS 561, Session 16-18 40 Completeness Backward chaining Generalized Modus Ponens Forward chaining • As explained earlier, Generalized Modus Ponens requires sentences to be in Horn form: • atomic, or • an implication with a conjunction of atomic sentences as the antecedent and an atom as the consequent. • However, some sentences cannot be expressed in Horn form. • e.g.: x bored_of_this_lecture (x) • E.g.: x P(x) => Q(x) • Cannot be expressed in Horn form due to presence of negation. CS 561, Session 16-18 41 Completeness • A significant problem since Modus Ponens cannot operate on such a sentence, and thus cannot use it in inference. • Knowledge exists but cannot be used. • Thus inference using Modus Ponens is incomplete. CS 561, Session 16-18 42 Completeness • However, Kurt Gödel in 1930-31 developed the completeness theorem, which shows that it is possible to find complete inference rules. • The theorem states: • any sentence entailed by a set of sentences can be proven from that set. => Resolution Algorithm which is a complete inference method. CS 561, Session 16-18 43 Completeness in FOL CS 561, Session 16-18 44 Resolution Procedure… Thủ tục hợp giải • Proof by contradiction method • Given a consistent set of axioms KB and goal sentence Q, we want to show that KB |= Q. This means that every interpretation I that satisfies KB, satisfies Q. But we know that any interpretation I satisfies either Q or ~Q, but not both. Therefore if in fact KB |= Q, an interpretation that satisfies KB, satisfies Q and does not satisfy ~Q. Hence KB union {~Q} is unsatisfiable, i.e., that it's false under all interpretations. • In other words, • What's the gain? If unsatisfiable • Resolution procedure can be used to establish that a given sentence Q is entailed by KB; however, it cannot, in general, be used to generate all logical consequences of a set sentences. Also, the resolution procedure cannot be used to prove that Q is not entailed by KB. (KB |- Q) <=> (KB ^ ~Q |- False) KB union ~Q is unsatisfiable, then some finite subset is Resolution inference rule CS 561, Session 16-18 46 Resolution Algorithm – Giải thuật hợp giải procedure resolution-refutation(KB, Q) ;; KB is a set of consistent, true FOL sentences ;; Q is a goal sentence that we want to derive ;; return success if KB |- Q, and failure otherwise KB = union(KB, ~Q) while false not in KB do pick 2 sentences, S1 and S2, in KB that contain literals that unify (if none, return "failure“) resolvent = resolution-rule(S1, S2) KB = union(KB, resolvent) return "success" Kinship Example KB: (1) father (art, jon) (2) father (bob, kim) (3) father (X, Y) parent (X, Y) Goal:parent (art, jon)? CS 561, Session 16-18 48 Refutation Proof/Graph ¬parent(art,jon) ¬ father(X, Y) \/ parent(X, Y) \ / ¬ father (art, jon) father (art, jon) \ / [] CS 561, Session 16-18 49 Problems yet to be addressed – Các vấn đề cần giải quyết khi áp dụng hợp giải. • Resolution rule of inference is only applicable with sentences that are in the form P1 v P2 v ... v Pn, where each Pi is a negated or nonnegated predicate and contains functions, constants, and universally quantified variables, so can we convert every FOL sentence into this form? • Resolution strategy • How to pick which pair of sentences to resolve? • How to pick which pair of literals, one from each sentence, to unify? Remember: normal forms “product of sums of simple variables or negated simple variables” “sum of products of simple variables or negated simple variables” CS 561, Session 16-18 51 Conjunctive normal form CS 561, Session 16-18 52 Skolemization CS 561, Session 16-18 53 Examples: Converting FOL sentences to clause form… Convert the sentence 1. (x){P(x) => [(y)(P(y) => P(f(x,y))) ^ ¬(y)(Q(x,y) => P(y)))] (like A => B ^ C) (chú ý: để dễ nhìn, dùng “[“, “]”,”{“ và “}” thay cho”(“ và “)” trong một vài vị trí) 2. Eliminate => (x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ ¬(y)(¬Q(x,y) P(y)))] 3. Reduce scope of negation (x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ (y)(Q(x,y) ^ ¬P(y)))] 4. Standardize variables (x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ (z)(Q(x,z) ^ ¬P(z)))] CS 561, Session 16-18 54 Examples: Converting FOL sentences to clause form… 5. Eliminate existential quantification (x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ (Q(x,g(x)) ^ ¬P(g(x))))] 6. Drop universal quantification symbols {¬P(x) [(¬P(y) P(f(x,y))) ^ (Q(x,g(x)) ^ ¬P(g(x))))] 7. Convert to conjunction of disjunctions [¬P(x) ¬P(y) P(f(x,y))] ^ [¬P(x) Q(x,g(x))] ^[¬P(x) ¬P(g(x))] CS 561, Session 16-18 55 Examples: Converting FOL sentences to clause form… 8. Create ¬P(x) ¬P(x) ¬P(x) separate clauses ¬P(y) P(f(x,y)) Q(x,g(x)) ¬P(g(x)) 9. Standardize variables ¬P(x) ¬P(y) P(f(x,y)) ¬P(z) Q(z,g(z)) ¬P(w) ¬P(g(w)) CS 561, Session 16-18 56 Resolution proof CS 561, Session 16-18 57 Resolution proof CS 561, Session 16-18 58 Problems yet to be addressed – Các vấn đề cần giải quyết khi áp dụng hợp giải. • Resolution rule of inference is only applicable with sentences that are in the form P1 v P2 v ... v Pn, where each Pi is a negated or nonnegated predicate and contains functions, constants, and universally quantified variables, so can we convert every FOL sentence into this form? • Resolution strategy • How to pick which pair of sentences to resolve? • How to pick which pair of literals, one from each sentence, to unify? Example of Refutation Proof (in conjunctive normal form) (1) (2) (3) (4) Cats like fish Cats eat everything they like Josephine is a cat. Prove: Josephine eats fish. cat (x) likes (x,fish) cat (y) likes (y,z) eats (y,z) cat (jo) eats (jo,fish) CS 561, Session 16-18 60 Backward Chaining – Hợp giải lùi Negation of goal wff: eats(jo, fish) eats(jo, fish) cat(y) likes(y, z) eats(y, z) = {y/jo, z/fish} cat(jo) likes(jo, fish) cat(jo) = cat(x) likes(x, fish) likes(jo, fish) = {x/jo} cat(jo) cat(jo) (contradiction) CS 561, Session 16-18 61 Forward chaining – Hợp giải tiến cat (X) likes (X,fish) cat (jo) \ / cat (Y) likes (Y,Z) eats (Y,Z) likes (jo,fish) \ / cat (jo) eats (jo,fish) cat (jo) \ / eats (jo,fish) \ eats (jo,fish) / [] CS 561, Session 16-18 62 Logic programming, Prolog Language: Horn forms (at most 1 positive literal) • KB: definite clauses: (Horn forms with exact 1 positive literal) • Query (q): not(q) is a negative clause (Horn forms with 0 positive literal) Inference procedure: Backward chaining resolution (actually, SLD Resolution – Selected literals Linear from Definite clauses Resolution) • Idea: Bắt đầu với Q=not(q), hợp giải với câu trong KB, được câu hợp giải mới, câu mới này lại hợp giải với câu trong KB đến khi nào câu [] tìm thấy • Đlý: Vơi KB gồm positive clauses và Q là negative clause: KB Q |= [] khi và chỉ khi KB Q |-- SDL []