370 likes | 512 Views
Expert Systems. Using First Order Logic. Outline. Syntax & Semantics Examples Wumpus World Example. Syntax. Constants: 2, apple, .. Predicates: >, <, Brother … Functions: Sqrt, Max, .. Variables: x, y, a , b, ... Connectives: ,, , =>, <=> Equality: = Quantifiers: , .
E N D
Expert Systems Using First Order Logic
Outline • Syntax & Semantics • Examples • Wumpus World Example
Syntax • Constants: 2, apple, .. • Predicates: >, <, Brother … • Functions: Sqrt, Max, .. • Variables: x, y, a , b, ... • Connectives: ,,, =>, <=> • Equality: = • Quantifiers: ,
Atomic Sentences • Atomic Sentence = • predicate(Term1, … , Termn) • or term1 = term2 • Term = • function(term1, …, termn) • or constant or variable • e.g. • Sqrt(x) > min( x, 1/x)
Complex Sentences • made from atomic sentences using connectives • ( S1), S1 S2… • e.g. Brother( John, Richard) => • Brother( Richard, John)
Truth in first-order logic • Sentences are true or false with respect to a model and an interpretation • Model has objects and relations among them • Interpretation maps • constant symbols -> objects • predicate symbols -> relations • function symbols -> functional relations
Universal Quantification • <variables> <sentence> • Everyone at Massey is smart • x At(x, Massey) => Smart(x) • The FOR_ALL x is actually a shorthand for writing all possible instantiations of x • e.g. At(Chris, Massey)=>Smart(Chris)AND At(John, Massey)=>Smart(John)
Existential Quantification • <variables> <sentence> • Someone at Auckland is smart • x At(x, Auckland) => Smart(x) • The THERE_EXISTS x is a shorthand for writing all possible instantiations of x • e.g. At(Alan, Auckland)=>Smart(Alan)OR At(Jack, Auckland)=>Smart(Jack)
Properties of Quantifiers • x y • same as y x • x y • same as y x • x y • NOT same as y x
Quantifier Duality • FOR_ALL can be expressed as a THERE_EXISTS and vice-versa • FOR_ALL x Likes(x, IceCream) • x Likes(x, IceCream) • THERE_EXISTS x Likes(x, broccoli) • x Likes(x, broccoli)
Examples • Brothers are siblings • Sibling is reflexive • One’s mother is one’s female parent
Equality • term1 = term2 under a given interpretation if and only if term1 and term2 refer to the same object • In this way it is possible to restrict the number of possible labels for the same object • FOR_ALL x, y P(x) AND P(y) => x = y
FOL KB Overview • Diagnostic Rules • Causal Rules • Effect Axioms • Frame Problem • Qualification Problem • Ramification Problem
FOL Knowledge Bases • Additional facts added • TELL( KB, Percept[S, B, NG]) • smell, breeze & no glitter • Query Knowledge base • ASK(KB, THERE_EXIST a, Action(a)) • ASK(KB, S) returns some or all substitutions (sigma) so that KB |= S/sigma
Deduction • Hidden properties deduced by diagnostic and causal rules • Diagnostic rule:- infer cause from effect • FOR_ALL y Breezy(y) => • THERE_EXIST x, Pit(x) AND Adjacent(x,y) • Causal rule:- infer effect from cause • FOR_ALL x,y Pit(x) AND Adjacent(x,y) => • Breezy(y)
Situation Calculus • Facts often only hold at some time • SC:- add a time argument to each non eternal argument • Holding(Gold, now) • Situations connected by results of actions • s1=Result (a, s0),result of action a applied to s0
Describing Actions • Effect axioms • FOR_ALL s AtGold(s) AND a=grab => • Holding(Gold, Result(Grab,s)) • Frame axioms, describe no changes • FOR_ALL s HoldingGold(s) AND a=grab => • Holding(Gold, Result(Grab,s))
Describing Action Cont • Frame problem:- • find elegant way to handle non changes • representation- avoid frame axioms • inference- avoid repeated copy overs • Qualification problem:- • realistic descriptions require endless additional details • Ramification problem:- • realistic problems have endless secondary consequences
Successor state axioms • Each axiom about a predicate • P true afterwards <=> • [an action made P true OR • [P already true AND no action made P false]] • FOR_ALL a, s Holding(Gold, Result(a,s)) <=> • [(a=Grab AND AtGold(s)) OR • [Holding(Gold,s) AND a != Release]]
Making Plans • Initial Conditions:- At(Agent, [1,1], s0) • At(Gold, [1,2], s0) • Query: • ASK(KB, s Holding(Gold,s)) • Answer: • {s/Result(Grab, Result(Forward,s0))}
Plans Extended • Plans are action sequences [a1, a2, .., an] • PlanResult(p,s) • is the result of executing p in s • Query: • ASK(KB, p • Holding(Gold,PlanResult(p,s0)) • Answer • {p/ [Forward, Grab]}
Summary • FOL • objects and relations are semantic primitives • syntax: constants, functions, predicates, equality and quantifiers • Situation calculus • actions and change in FOL • planning as inference on a situation calculus knowledge base
Inference • Proofs • Unification • Generalized Modus Ponens • Forward and Backward chaining
Proofs • Sound Inference: • find alpha such that KB |= alpha • Proof process is search, operators are inference rules
Inference Rules • Modus Ponens:- • alpha, alpha => beta / beta • And Introduction:- • alpha, beta / alphabeta • Universal Elimination: • x alpha / alpha{x/ t}
Inference Rules cont. • Existential Elimination:- • x alpha / alpha{x/ t’} • Existential Introduction • alpha / x alpha{ t/x}
Example Proof • Bob is a buffalo:- • 1. Buffalo(Bob) • Pat is a Pig:- • 2. Pig(Pat) • Buffaloes outrun pigs:- • 3. x, y Buffalo(x) Pig(y) => Faster(x,y) • Bob outruns Pat
Example cont • And Introduction (1 & 2 ):- • 4. Buffalo(Bob) Pig(Pat) • Universal Elimination (3), {x/Bob, y/Pat} • 5. Buffalo(Bob) Pig(Pat) => Faster(Bob, Pat) • Modus Ponens (6&7):- • Faster(Bob, Pat)
Search with primitive inference rules • Operators are inference rules • States are sets of sentences • Goal test checks state to see if it contains query sentence • AI, UE, MP is a common inference pattern • Problem:- a huge branching factor especially for UE • NEED a substitution that makes the rule premise match some known facts
Unification • A substitution sigma unifies atomic sentences p and q if p/sigma = q/sigma p Knows(John, x) Knows(John, x) Knows(John, x) q Knows(John, Jane) Knows(y,Jane) Knows(y, Mother(y)) sigma
Generalised Modus Ponens • p1’, p2’, … pn’, (p1 p2 …. Pn => q) • --------------------------------------------- • q/ sigma • where pi’/ sigma = pi/ sigma • GMP used with KB of definite clauses: • a single atomic sentence • (conjunction of atomic sentences) => • (atomic sentence)
Example • p1’ = Faster(Bob, Pat), • p2’ = Faster(pat,Steve) • p1 p2 => q = • Faster(x, y) Faster(y, z) => Faster(x,z) • sigma = {x/Bob, y/Pat, z/Steve} • q/sigma = Faster(Bob, Steve)
Forward Chaining • When a new fact p is added to KB • for each rule that p unifies with a premise • if other premises are known then add the conclusion to KB and continue chaining • Forward chaining is data driven • inferring properties and categories from percepts
Forward chaining example • 1. Buffalo(x) Pig(y) => Faster(x,y) • 2. Pig (y) Slug(z) => Faster(y,z) • 3. Faster(x, y) Faster(y, z) => Faster(x,z) • 4. Buffalo(Bob) [1a, x] • 5. Pig(Pat) [1b, ][2a, x] -> • 6. Faster(Bob, Pat) [3a,x], [3b,x] • 7. Slug(Steve)[2b, ]-> • 8. Faster (pat, Steve) [3a, x][3b, ]-> • Faster(Bob, Steve) [3a,x][3b,x]
Backward chaining • When a query q is added to KB • If a matching fact q’ is known, return the unifier • for each rule whose consequent q’ matches q • attempt to prove each premise by backward chaining • Backward chaining is query driven • can try to find one solution or all solutions • Basis of logic programming, e.g. Prolog
Faster( y, z) 1 2 Pig(y) Slug(z) Slimy(z) Creeps(z) Backward chaining example • 1. Pig(y) Slug(z) => Faster(y,z) • 2. Slimy(z) Creeps(z) => Slug(z) • 3. Pig(Pat) 4. Slimy(Steve) 5.Creeps(Steve) {y/Pat, Z/Steve} {z/Steve} 3 {y/Pat} 4 {z/Steve} 5 {z/Steve}