220 likes | 229 Views
Artificial Intelligence. CS 165A Thursday, November 8, 2007. Inference in FOL (Ch 9) Brief midterm review. Today. 1. 1. 1. What we’ve been talking about. Complete and sound inference procedures New inference rules: Universal Instantiation (gets rid of )
E N D
Artificial Intelligence CS 165A Thursday, November 8, 2007 • Inference in FOL (Ch 9) • Brief midterm review Today 1 1 1
What we’ve been talking about • Complete and sound inference procedures • New inference rules: • Universal Instantiation (gets rid of ) • Existential Instantiation (gets rid of ) • Existential Introduction (adds ) • Generalized Modus Ponens • Generalized (First-Order) Resolution • Complete but semidecidable • Unification • Finds the substitution(s) necessary to make two sentences match • Conjunctive normal form (CNF)
FOL example • Domain elements: {Bob, Alice, Carol, Ted} • x Sleepy(x) • Sleepy(Bob) Sleepy(Alice) Sleepy(Carol) Sleepy(Ted) • x Hungry(x) • Hungry(Bob) Hungry(Alice) Hungry(Carol) Hungry(Ted) • Universal Instantiation: x Sleepy(x) • Sleepy(Alice) • Existential Instantiation: x Hungry(x) • Hungry(k) where k is a constant (not a variable!) • Existential Introduction: AtHome(Ted) • x AtHome(x)
For literals piand qi , where UNIFY(pj , qk) = Disjunctions For atomic sentences pi, qi, ri, si , where UNIFY(pj , qk) = Implications Two versions of Generalized Resolution
Thursday quiz Note: Everyone gets a 100% for last Thursday! • If the domain is natural numbers (0, 1, 2, ...), what is a general unifier (if one exists) for these two atomic sentences: GreaterThan(x, 7) GreaterThan(Squared(y), y) E.g., = { a/13, b/4 } • What new (to us) dimension does situational calculus allow us to represent and reason about?
Conjunctive normal form (CNF) • First we must convert all sentences to Conjunctive Normal Form (CNF) • A CNF sentence is a disjunctions of literals • Literals: Possibly negated propositions, variables, constants, or predicates • So each sentence in the KB is a disjunction of literals, e.g.: • P(x) Q(y) • Dog(x) Cat(y) • Big(x) Slow(x) Young(x) • The KB itself is a conjunction of disjunctions of literals, e.g.: • P(x)Q(y) Dog(x)Cat(y) Big(x)Slow(x)Young(x)
Another “canonical” form: INF • Implicative Normal Form (INF) • Each sentence in the KB is an implication with a conjunction of atoms on the left and a disjunction of atoms on the right, e.g.: • P(x) Q(x) • P(x) Q(x) R(x) S(x) • INF and CNF are logically equivalent
Conversion to Conjunctive Normal Form (CNF) • Replace (P Q) with (P Q) and (Q P) • Eliminate implications: Replace (P Q) with (P Q) • Move inwards: , , , (P Q), (P Q) • Standardize variables apart: x P(x) x Q(x) becomes x1 P(x1) x2 Q(x2) [Give all variables different names] • Move quantifiers left in order: x P(x) y Q(y) becomesx y P(x) Q(y) • Eliminate by “Skolemization” (coming) • Drop universal quantifiers • Distribute over , e.g.: (P Q) R becomes (P R) (Q R) [What about (P Q) R ?] • Flatten nesting: (P Q) R becomes P Q R
Conversion to Implicative Normal Form (INF) • First convert to CNF • Convert disjunctions to implications: negative literals to the left, positive literals to the right P Q R S becomes P Q R S P Q becomes P Q False R S becomes True R S Remember that P(x) is logically equivalent to True P(x) and P(x) is logically equivalent to P(x) False
Skolemization • To “Skolemize” is to remove existential quantifiers by elimination • Existential elimination when x is on the outside x Sleepy(x) …becomes… Sleepy(RipVanWinkle) [If what?] • More complicated when inside a universal quantifier x Person(x) y Heart(y) Has(x, y) “Everyone has a heart” x Person(x) Heart(H1) Has(x, H1) “Everyone has the heart H1” • Rather, introduce a “Skolem function” H(x) x Person(x) Heart(H(x)) Has(x, H(x)) where H() does not appear elsewhere in the KB • Arguments of the Skolem function: all enclosing universally quantified variables
Skolemization examples By Existential Elimination, y MajorsIn(y, Sociology) MajorsIn(Somedude, Sociology) But it’s not true that x y MajorsIn(y, x) x MajorsIn(Somedude, x) Rather, x y MajorsIn(y, x) x MajorsIn(P(x), x) where P(x) refers to a different constant for every x x y Student(x) TakesCourses(x) KnowsAbout(x, y) x Student(x) TakesCourses(x) KnowsAbout(x, S(x))
Simple examples • How to put these into CNF and INF? • CNFINF • P(x) Q(x) P(x) Q(x) • P(x) True P(x) • P(x) Q(x) True P(x) Q(x) • P(x) Q(y) True P(x) Q(y) • P(x) Q(y) Q(y) P(x) • P(x), Q(x) True P(x), True Q(x) • P(x) Q(x) • P(x) • P(x) Q(x) • P(x) Q(y) • P(x) Q(y) • P(x) Q(x) In practice, we can leave out the “True ” in these sentences
Moving inwards • x S(x) (is equivalent to…) • xS(x) • x Hungry(x) xHungry(x) • x S(x) • xS(x) • x Hungry(x) xHungry(x) • (P Q) • (P Q) • (P Q) • (P Q) [In CNF that’s two sentences!]
For literals piand qi , where UNIFY(pj , qk) = Disjunctions Examples: Generalized (first-order) resolution • Note: • p and q do not unify • Rather, p and q unify pj: Engineer(x) qj: Engineer(Bill) = { x/Bill } pj: Loves(x, Broccoli) qj: Loves(Joe, y) = { x/Joe, y/Broccoli }
Generalized resolution example • KB: Rich(x) Famous(x) Rich(x) Content(x) Famous(x) Happy(x) Content(x) Happy(x) Rich(Bob) • Is Bob happy? • ASK(KB, Happy(Bob)) • GMP can’t answer this • GR can • First put KB in CNF • KB in CNF: Rich(x) Famous(x) Rich(x) Content(x) Famous(x) Happy(x) Content(x) Happy(x) Rich(Bob) and the negated query: Happy(Bob) • What’s this method called? • Proof by contradiction • Refutation
Rich(x) Content(x) Content(x) Happy(x) { } Rich(x) Happy(x) {x/Bob} Happy(Bob) { } False • Rich(x) Famous(x) • Rich(x) Content(x) • Famous(x) Happy(x) • Content(x) Happy(x) • Rich(Bob) • Happy(Bob) Example (cont.) Rich(Bob) Happy(Bob) QED
Forward and Backward Chaining • A reasoning program needs • A language for representing knowledge – First-Order Logic • Rules – just one, Generalized Resolution • Control mechanism– ??? • Two general approaches to control • Start with the KB and generate new conclusions (which can enable more inferences to be made) • E.g., when a new fact is added to the KB • Given what we want to prove, find implication sentences that would allow us to conclude it, and attempt to establish their premises • E.g., when a goal is to be proved
Forward chaining S G Backward chaining S G Forward and Backward Chaining
Forward and Backward Chaining • Forward chaining • Data driven or data directed • New version of TELL(KB, p) • Add the sentence p, then apply inference rules to the updated KB until no more rules apply (“chaining” – “chain reaction”) • Backward chaining • Goal oriented • ASK(KB, q) • If SUBST(, q) is in KB, return q' = SUBST(, q) • Else, find implication sentences p q then set p as a subgoals • Keep doing this, working “backwards” • If p is not in KB, look for r p, then set r as a subgoal • Etc….. • Backward chaining is the basis for logic programming (e.g., Prolog)
Midterm Review • Tuesday during class • Please be on time! • Closed book exam • You may bring one sheet of paper with notes (8.5” x 11”, both sides) • Test paper will be supplied (don’t need to bring your own) • Calculator not necessary • What are you responsible for? • Possibly anything that has been covered in the reading (textbook through Ch. 8 and articles), lectures, discussion sessions, and homework assignments • But you should probably focus on the lectures….
You will be given… • Inference rules for Propositional logic • Modus ponens, and-elimination, and-introduction, or-introduction, double-negation elimination, unit resolution, resolution • FOL • Universal elimination, existential elimination, existential introduction • Generalized modus ponens • Generalized (first-order) resolution • Procedure to convert logic sentences to CNF These are posted on the course web
Examples of things you might be asked • Which search algorithm(s) would be most appropriate in this particular situation? • What are the main difference(s) between these two search algorithms • What does it mean for a search alg. to be optimal? To be complete? • Are these heuristics admissible or not? • Do {iterative deepening search, A*, minimax, expectimax, …} on this problem. • Show the truth table for this propositional logic sentence. • Are these logic sentences satisfiable, unsatisfiable, or valid? • What does it mean for an inference procedure to be optimal? To be complete? • Does the KB entail this sentence S? • How are these terms unified? • Apply certain inference rules to this KB.