CS 541: Artificial Intelligence Lecture IV: Logic Agent and First Order Logic
Announcement CA Office Hour: 3:00pm-4:00pm, Lieb 319. Homework assignment should be checked at Moodle.
Schedule WeekDateTopicReadingHomework** 108/29/2012Introduction & Intelligent AgentCh 1 & 2N/A 209/05/2012Search: search strategy and heuristic searchCh 3 & 4sHW1 (Search) 309/12/2012Search: Constraint Satisfaction & Adversarial SearchCh 4s & 5 & 6 Teaming Due 409/19/2012Logic: Logic Agent & First Order LogicCh 7 & 8sHW1 due, Midterm Project (Game) 509/26/2012Logic: Inference on First Order LogicCh 8s & 9 610/03/2012 No class 7 10/10/2012Uncertainty and Bayesian Network Ch 13 & Ch14s HW2 (Logic) 8 10/17/2012 Midterm Presentation Midterm Project Due 9 10/24/2012Inference in Baysian NetworkCh 14sHW2 Due, HW3 (Probabilistic Reasoning) 10 10/31/2012Probabilistic Reasoning over TimeCh /07/2012Machine Learning HW3 due, 1211/14/2012Markov Decision ProcessCh 18 & 20HW4 (Probabilistic Reasoning Over Time) 1311/21/2012 No class Ch /29/2012Reinforcement learningCh 21HW4 due 1512/05/2012Final Project Presentation Final Project Due
Re-cap Lecture III Constraint Satisfaction Problem Constraint satisfaction problem (CSP) examples Backtracking search for CSPs Problem structure and problem decomposition Local search for CSPs Adversarial Search and Games Games Perfect play Minimax decisions α - β pruning Resource limits and approximate evaluation Games of chance Games of imperfect information
Logic Agent Lecture IV: Part I
Outline Knowledge-based agents Wumpus world Logic in general—models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem proving Forward chaining Backward chaining Resolution
Knowledge bases Knowledge base Set of sentences in a formal language Declarative approach to building an agent (or other system) T ELL it what is needs to know Then it can A SK itself what to do Answers should follow from the KB Agents can be viewed at the knowledge level i.e., what they know, regardless of how implemented Or at the implementation level i.e., data structures in KB and algorithms that manipulate them
A simple knowledge-based agent The agent must be able to: Represent states, actions, etc. Incorporate new percepts Update internal representations of the world Deduce hidden properties of the world Deduce appropriate actions
Wumpus world PEAS description Performance measure Gold +1000; Death -1 per step; -10 for using the arrow Environment Squares adjacent to wumpus are smelly Squares adjacent to pit are breezy Glitter iff gold is in the same square Shooting kills wumpus if you are facing it Grabbing picks up gold if in same square Releasing drops the gold in same square Actuators Left turn, right turn, forward, grab, release, shoot Sensors Breeze, glitter, smell
Wumpus world characterization Observable?? No, only local perception Deterministic?? Yes, outcomes exactly specified Episodic?? No, sequential at the level of actions Static?? Wumpus and pits do not move Discrete?? Yes Single-agent?? Yes, Wumpus is essentially a natural feature
Exploring a wumpus world
Other tight spots Breeze in (1,2) and (2, 1) No safe actions Smell in (1,1) Cannot move Can use a strategy of coercion Shoot straight ahead Wumpus was there dead safe Wumpus wasn’t there safe
Logic in general Logics are formal languages for representing information Such that conclusions can be drawn Syntax defines the sentences in the language Semantics define the “meaning” of sentences i.e., define truth of a sentence in a world E.g., the language of arithematics x+2≥y is a sentence; x2+2> is not a sentence x+2≥y is true iff the number x+2 is no less than the number y x+2≥y is true in a world where x=7, y=1 x+2≥y is false in a world where x=0, y=6
Entailment
Models
Entailment in the wumpus world Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for ?s assuming only pits 3 Boolean choices 8 possible models
Wumpus models
KB=wumpus-world rules+observations
Wumpus models
KB=wumpus-world rules+observations
Wumpus models
Inference
Propositional logic: Syntax
Propositional logic: Semantics
Truth tables for connectives
Wumpus world sentences
Truth tables for inference
Inference by enumeration
Logical equivalence
Validity and satisfiability
Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules Legitimate (sound) generation of new sentences from old Proof = a sequence of inference rule applications Can use inference rules as operators in a standard search algorithm Typically require translation of sentences into a norm form Model checking Truth table enumeration (always exponential in n) Improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL) Heurisitc search in model space (sound but incomplete) E.g., min-conflicts-like hill-climbing algorithms
Forward and backward chaining
Idea: fire any rule whose premises are satisfied in the KB, add its conclusion to the KB, until query is found Forward chaining
Forward chaining algorithm
Forward chaining example
Proof of completeness
Backward chaining Idea: work backwards from the query q: To prove q by BC, check if q is known already, or, prove by BC all premises of some rule concluding q Avoid loops: check if new subgoal is already on the goal stack Avoid repeated work: check if new sub goal Has already been proven true, or Has already failed
Backward chaining example
Forward vs. backward chaining FC is data-driven, cf. automatic, unconscious processing E.g., object recognition, routine decisions May do lots of work that is irrelevant to the goal BC is goal-driven, appropriate for problem-solving E.g., where are my keys? How do I get into a PhD program? Complexity of BC can be much less than linear in size of KB
Resolution
Conversion to CNF
Resolution algorithm
Resolution example
Summary Logical agents apply inference to a knowledge base to derive new information and make decisions Basic concepts of logic: Syntax: formal structure of sentences Semantics: truth of sentences wrt models Entailment: necessary truth of one sentence given another Inference: deriving sentences from other sentences Soundess: derivations produce only entailed sentences Completeness: derivations can produce all entailed sentences Wumpus world requires the ability to represent partial and negated information, reason by cases, etc. Forward, backward chaining are linear-time, complete for Horn clauses Resolution is complete for propositional logic Propositional logic lacks expressive power
First-order Logic Lecture IV: Part II
Outline Why first-order logic (FOL)? Syntax and semantics of FOL Fun with sentences Wumpus world in FOL
Pros and cons of propositional logic
First-order logic Whereas propositional logic assumes world contains facts, First-order logic (like natural language) assumes that the world contains Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games, wars, centuries … Relations: red, round, bogus, prime, multistoried…, brother of, bigger than, inside, part of, has color, occurred after, owns, comes between, … Functions: father of, best friend, third inning of, one more than, end of…
Logics in general
Syntax of FOL: Basic elements
Atomic sentences Atomic sentence = predicate(term 1, …, term n ) Or term 1 =term 2 Term=function(term 1,…,term n ) or constant or variable E.g., Brother(King John, RichardTheLinonHeart) >(Length(LeftLegOf(Richard))), Length(LeftLegOf(KingJohn)))
Complex sentences
Truth in first-order logic
Models for FOL: example
Truth example Consider the interpretation in which Richard Richard the Lionheart John the evil King John Brother The brotherhood relation Under this interpretation, Brother(Richard, John) is true, just in case Richard the Liohheart and the evil King John are in the brotherhood relation in the model
Models of FOL: lots! Entailment in propositional logic can be computed by enumerating models We can enumerate the FOL models for a given KB vocabulary, i.e., For each number of domain elements n from 1 to ∞ For each k-ary predicate P k in the vocabulary For each possible k-ary relation on n objects For each constant symbol C in the vocabulary For each choice of referent for C from n Objects … Computing entailment by enumerating FOL models is not easy!
Universal quantification
A common mistake to avoid
Existential quantification
Another common mistake to avoid
Properties of quantifiers
Fun with sentences
Equality
Interacting with FOL KBs
Knowledge base for the wumpus world
Deducing hidden properties
Keeping track of change
Describing actions I
Describing actions II
Making plans
Making plans: A better way
Summary First-order logic: Objects and relations are semantic primitives Syntax: constants, functions, predicates, equality, quantiers Increased expressive power: sufficient to define wumpus world Situation calculus: Conventions for describing actions and change in FOL Can formulate planning as inference on a situation calculus KB