530 likes | 682 Views
Inferencing. Finding solution to queries Propositionalization (For reference only, may leave slides 2 to 7) Unification Forward Chaining Backward Chaining Resolution. Luger’s Book: Chapter 2 and Chapter 12 (upto 12.2). Propositionalization. Brute Force Approach
E N D
Inferencing Finding solution to queries • Propositionalization • (For reference only, may leave slides 2 to 7) • Unification • Forward Chaining • Backward Chaining • Resolution CS 331 Dr M M Awais
Propositionalization • Brute Force Approach • Apply all possible bindings to the variables. • Add every clause in the sentence as a proposition to the knowledge base. • Search for the required proposition (Goal proposition) CS 331 Dr M M Awais
Reduction to propositional inference Universal Instantiation Suppose the KB contains just the following: X wealthy(X) greedy(X) bad(X) wealthy(arif) greedy(arif) cousins(shahid,arif) • Instantiating the universal sentence in all possible ways, we have: wealthy(arif) greedy(arif) bad(arif) wealthy(shahid) greedy(shahid) bad(shahid) wealthy(arif) greedy(arif) cousins(shahid,arif) • The new KB is propositionalized: proposition symbols are • wealthy(arif), greedy(arif), bad(arif), wealthy(shahid), • greedy(shahid), bad(shahid), cousins(shahid,arif). CS 331 Dr M M Awais
Reduction contd. • Every FOL KB can be propositionalized so as to preserve entailment (entailments are dependencies) • (A ground sentence is entailed by new KB iff entailed by original KB) • Idea: propositionalize KB and query, apply resolution, return result • Problem: with function symbols, there are infinitely many ground terms, • e.g., Father(Father(Father(John))) CS 331 Dr M M Awais
Reduction contd. Theorem: Herbrand (1930). If a sentence αis entailed by an FOL KB, it is entailed by a finite subset of the propositionalized KB Idea: For n = 0 to ∞ do create a propositional KB by instantiating with depth-$n$ terms see if α is entailed by this KB Problem: works if α is entailed, loops if α is not entailed Theorem: Turing (1936), Church (1936) Entailment for FOL is semidecidable (algorithms exist that say yes to every entailed sentence, but no algorithm exists that also says no to every nonentailed sentence.) CS 331 Dr M M Awais
Problems withpropositionalization • Propositionalization seems to generate lots of irrelevant sentences. • E.g., from: x King(x) Greedy(x) Evil(x) King(John) y Greedy(y) Brother(Richard,John) • it seems obvious that Evil(John), but propositionalization produces lots of facts such as Greedy(Richard) that are irrelevant • With p k-ary predicates and n constants, there are p·nk instantiations. CS 331 Dr M M Awais
Unification “It is an algorithm for determining the substitutions needed to make two predicate calculus expressions match” The process of universal/existential instantiation require substitutions CS 331 Dr M M Awais
Unification • Unify(α,β) = θ if αθ = βθ p q θ knows(ali,X) knows(ali,sana) knows(ali,X) knows(Y,hira) knows(ali,X) knows(Y,mother(Y)) knows(ali,X) knows(X,hira) • Standardizing aparteliminates overlap of variables, e.g., the fourth sentence can have knows(Z,hira) CS 331 Dr M M Awais
Unification • Unify(α,β) = θ if αθ = βθ p q θ knows(ali,X) knows(ali,sana) {sana/X} knows(ali,X) knows(Y,hira) knows(ali,X) knows(Y,mother(Y)) knows(ali,X) knows(X,hira) • Standardizing aparteliminates overlap of variables, e.g., the fourth sentence can have knows(Z,hira) CS 331 Dr M M Awais
Unification • Unify(α,β) = θ if αθ = βθ p q θ knows(ali,X) knows(ali,sana) {sana/X} knows(ali,X) knows(Y,hira) {hira/X,ali/Y} knows(ali,X) knows(Y,mother(Y)) knows(ali,X) knows(X,hira) • Standardizing aparteliminates overlap of variables, e.g., the fourth sentence can have knows(Z,hira) CS 331 Dr M M Awais
Unification • Unify(α,β) = θ if αθ = βθ p q θ knows(ali,X) knows(ali,sana) {sana/X} knows(ali,X) knows(Y,hira) {hira/X,ali/Y} knows(ali,X) knows(Y,mother(Y)) {ali/Y,mother(ali)} knows(ali,X) knows(X,hira) • Standardizing aparteliminates overlap of variables, e.g., the fourth sentence can have knows(Z,hira) CS 331 Dr M M Awais
Unification • Unify(α,β) = θ if αθ = βθ p q θ knows(ali,X) knows(ali,sana) {sana/X} knows(ali,X) knows(Y,hira) {hira/X,ali/Y} knows(ali,X) knows(Y,mother(Y)) {ali/Y,mother(ali)} knows(ali,X) knows(X,hira) {fail} • Standardizing aparteliminates overlap of variables, e.g., the fourth sentence can have knows(Z,hira) CS 331 Dr M M Awais
Unification - MGU • To unify knows(ali,X) and knows(Y,Z) θ = {ali/Y, Z/X } or θ= {ali/Y, ali/X, ali/Z} (if only ali is present in the data base of facts) • The first unifier is more general than the second. • There is a single Most General Unifier (MGU) that is unique up to renaming of variables. MGU = { ali/Y, Z/X} CS 331 Dr M M Awais
Implementation of Unification Using“List format” PC SyntaxList Syntax p(a,b) (p a b) p(f(a), g(X,Y)) (p(f a)(g X Y)) p(x) ^ q(y) ((p x) ^ (q y)) CS 331 Dr M M Awais
Unification Examples Unify ((parents X(father X) (mother bill)), (parents bill (father bill)Y)). Complete Substitution {bill/X, mother (bill)/Y} CS 331 Dr M M Awais
Logic – Based Financial Advisor • To help a user decide whether to invest in a saving A/C or the stock market orboth CS 331 Dr M M Awais
Policy: Saving inadequate - should invest in saving A/c regardless of income Saving adequateand adequate income- More profitable option of stock investment Low Income& adequate savings- Split surplus between saving and stock investment CS 331 Dr M M Awais
Defining Constraints Adequate Savings/Income: Income: Rs 15000/month extra Rs 4000/ dependent/month Saving: Rs 25,000/year extra Rs 5000/dependent/year CS 331 Dr M M Awais
Calculating Adequacy Define Functions to calculate the minimum income and savings Minimum Savings: min_saving(X) min_saving(X)=25000+5000*X where X are the number of dependents Minimum Income:min_income(X) min_income(X)=15000+4000*X CS 331 Dr M M Awais
Outputs Investment (savings) Investment (stocks) Investment (combination) How can we represent outputs? CS 331 Dr M M Awais
Rules ·saving_acc (inadequate) investment (savings) ·saving_acc(adequate) ^ income(adequate) investment(stocks) ·saving_acc (adequate) ^ income (inadequate) investment (combination) CS 331 Dr M M Awais
What next? • Define Saving adequate • Define saving inadequate • Define income adequate • Define income inadequate CS 331 Dr M M Awais
Savings Check if saved amount is greater than the minimum saving required CS 331 Dr M M Awais
Income Check if the income is greater than the minimum income CS 331 Dr M M Awais
Try firing rules with 9, 10, 11 CS 331 Dr M M Awais
Example knowledge base 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. Prove that Col. West is a criminal CS 331 Dr M M Awais
Example knowledge base contd. ... 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, i.e., 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) CS 331 Dr M M Awais
Example knowledge base contd. Rule Base: ... it is a crime for an American to sell weapons to hostile nations: R1: american(X) weapon(Y) sells(X,Y,z) hostile(z) criminal(X) Nono … has some missiles, i.e., R2: X owns(nono,X) missile(X): … all of its missiles were sold to it by Colonel West R3: missile(X) owns(nono,X) sells(west,X,nono) Missiles are weapons: R4: missile(X) weapon(X) An enemy of America counts as "hostile“: R5: enemy(X,america) hostile(X) • Database of Facts: • owns(nono,m1) and missile(m1) • West, who is American … • american(west) • The country Nono, an enemy of America … • enemy(nono,america) CS 331 Dr M M Awais
R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z) criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) • START FROM THE FACTS • THINK WHICH RULES APPLY Be careful about the convention constants start with capital letters and variables with small (applicable to next few slides) 1. FORWARD CHAINING CS 331 Dr M M Awais
R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z) criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) R5 {nono/X} R4 {m1/X} R3 {m1/X} CS 331 Dr M M Awais
R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z) criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) R1 {west/X , m1/Y , nono/Z} CS 331 Dr M M Awais
2. BACKWARD CHAINING R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z)criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) • START FROM THE CONCLUSION • THINK IS THE RULE SUPPORT AVAILABLE CS 331 Dr M M Awais
Backward chaining example R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z) criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) CS 331 Dr M M Awais
Backward chaining example R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z) criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) CS 331 Dr M M Awais
Backward chaining example R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z)criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) CS 331 Dr M M Awais
Backward chaining example R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z)criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) CS 331 Dr M M Awais
Backward chaining example R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z)criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) CS 331 Dr M M Awais
Backward chaining example R1: american(X) weapon(Y) sells(X,Y,Z) hostile(Z)criminal(X) R2: X owns(nono,X) missile(X): R3: missile(X) owns(nono,X) sells(west,X,nono) R4: missile(X) weapon(X) R5: enemy(X,america) hostile(X) CS 331 Dr M M Awais
3. Modus Ponen Based Solution • X,Y,Z[american(X)^weapon(Y)^nation(Z)^hostile(Z)^sells(X,Z,Y) criminal(X)] • X owns(nono,X)^missiles(X) sells(west,nono,X) • X missiles(X) weapons (X) • X enemy(X,america) hostile(X) • owns(nono,m1) • missiles(m1) • american(west) • nation(nono) • enemy(nono,america) • nation(america) • 6 with 3 suggests, through Modus Ponens: weapons(m1) :{m1/X} 2. From 4 and 9 hostile(nono) : {nono/X} • From 2, 5, 6, Modus Ponens sells(west,nono,m1):m1/X 4. From 2,3,4,5,6, and 9 criminal(west): {west/X, m1/Y, nono/Z} CS 331 Dr M M Awais
Composition • Find Overall Substitutions • Given two or more sets of substitutions CS 331 Dr M M Awais
Example • S1={A/K} • S2={a/A, H/J} What set would represent overall substitutions • S1.S2={a/K, H/J} • Algorithm? CS 331 Dr M M Awais
Example • S1={A/K} S2={a/A, H/J} • S1.S2={a/K, H/J} • Algorithm: • Apply S2 to S1 (find overall substitution) • Add S2 to S1 • Drop all substitutions in S2 which have common denominators with S1 CS 331 Dr M M Awais
Example • S1={A/K} S2={a/A, H/J} • Algorithm: Apply S2 to S1 (find overall substitution) Apply a/A to A/K would lead to a/K Apply H/J to A/K cannot be applied S1.S2={a/K} Add S2 to S1 S1.S2={a/K a/A,H/J} Drop all substitutions in S2 which have common denominators with S1 nothing gets dropped, hence the answer is {a/K,a/A,H/J} CS 331 Dr M M Awais
Example • S1={D/A} • S2={a/D} • S12={a/A, a/D} • S1={D/A,S/G} • S2={x/X, f/D, q/S,w/A} • S1.S2={f/A,q/G, x/X, f/D, q/S,w/A} • S1.S2={f/A,q/G, x/X,q/S} (w/A gets dropped) S1.S2={f/A,q/G, x/X,q/S} CS 331 Dr M M Awais
Is S1.S2 same as S2.S1 • S1={D/A} • S2={a/D} • S21={a/A, D/A}{a/A} where as S12={a/A, a/D} • S1={D/A,S/G} • S2={x/X, f/D, q/S,w/A} • S2.S1={x/X, f/D, q/S, w/A D/A,S/G} • S2.S1={x/X, f/D, q/S, w/A, S/G} (D/A gets dropped) Hence generally speaking S1.S2 not equal to S2.S1 CS 331 Dr M M Awais
Is S12 same as S21 • S1={D/A} • S2={X/A} • S12={D/A, X/A} • S12={D/A} • S21={X/A,D/A} • S21={X/A} CS 331 Dr M M Awais