310 likes | 565 Views
Unification. “It is an algorithm for determining the substitutions needed to make two predicate calculus expressions match” Reference: Luger’s Book chapter 3, 2 nd edition. Implementation of Unification. Using“List format” (PNF have already been discussed) PC Syntax List Syntax
E N D
Unification “It is an algorithm for determining the substitutions needed to make two predicate calculus expressions match” Reference: Luger’s Book chapter 3, 2nd edition CS 331/531 Dr M M Awais
Implementation of Unification Using“List format” (PNF have already been discussed) 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/531 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/531 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/531 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/531 Dr M M Awais
Defining Constraints Adequate Savings/Income: Income: Rs 15,000/month extra Rs 4000/ dependent/month Saving: Rs 25,000/year extra Rs 5000/dependent/year CS 331/531 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 Minimum Income:min_income(X) min_income(X)=15000+4000*X where X are the number of dependents CS 331/531 Dr M M Awais
Outputs Investment (savings) Investment (stocks) Investment (combination) How can we represent outputs? CS 331/531 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/531 Dr M M Awais
What next? • Define saving adequate • Define saving inadequate • Define income adequate • Define income inadequate CS 331/531 Dr M M Awais
Savings Check if saved amount is greater than the minimum saving required CS 331/531 Dr M M Awais
Income Check if the income is greater than the minimum income CS 331/531 Dr M M Awais
Try firing rules with 9, 10, 11 CS 331/531 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 Solution presented using alternate syntax Reference: Norviq and Russell CS 331/531 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) (skolemization) … 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/531 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) ^ Missile(M1) • West, who is American … • American(West) • The country Nono, an enemy of America … • Enemy(Nono,America) CS 331/531 Dr M M Awais
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x) R2: x Owns(Nono,x) Mssile(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/531 Dr M M Awais
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x) R2: x Owns(Nono,x) Mssile(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/531 Dr M M Awais
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x) R2: x Owns(Nono,x) Mssile(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/531 Dr M M Awais
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x) R2: x Owns(Nono,x) Mssile(x) R3: Missile(x) Owns(Nono,x) Sells(West,x,Nono) R4: Missile(x) Weapon(x) R5: Enemy(x, America) Hostile(x) 2. BACKWARD CHAINING • START FROM THE CONCLUSION • THINK IS THE RULE SUPPORT • AVAILABLE CS 331/531 Dr M M Awais
Backward chaining example West/x CS 331/531 Dr M M Awais
Backward chaining example West/x CS 331/531 Dr M M Awais
Backward chaining example West/x CS 331/531 Dr M M Awais
Backward chaining example West/x , M1/y M1/y CS 331/531 Dr M M Awais
Backward chaining example West/x , M1/y , Nono/z Nono/z M1/y CS 331/531 Dr M M Awais
Backward chaining example West/x , M1/y , Nono/z Nono/z M1/y CS 331/531 Dr M M Awais
Backward chaining example West/x , M1/y , Nono/z Nono/z M1/y CS 331/531 Dr M M Awais