lecture 7: logic and planning - mcgill university...
TRANSCRIPT
![Page 1: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/1.jpg)
Lecture 7: Logic and Planning
• Planning and representing knowledge
• Logic in general
• Propositional (Boolean) logic and its application to planning
COMP-424, Lecture 8 - January 30, 2013 1
![Page 2: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/2.jpg)
What is planning?
• A plan is a collection of actions for performing some task
– E.g., my daughter’s birthday celebration– E.g., a conference participation– E.g., assembling furniture
• There are many programs that help human planners
• The goal in AI is to generate plans automatically
COMP-424, Lecture 8 - January 30, 2013 2
![Page 3: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/3.jpg)
NASA’s Deep Space 1
• Launched in Oct. 1998 to test technologies and perform flybys of asteroidBraille and Comet Borrelly.
• Autonav system used for autonomous navigation and finding imagingtargets.
• Remote Agent system used to perform automatic fault detection andself-repair.
• First spacecraft to be controlled by AI system without humanintervention.
COMP-424, Lecture 8 - January 30, 2013 3
![Page 4: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/4.jpg)
NASA’s MAPGEN System
• Planning and scheduling system used daily to generate commandsequences for the Mars Exploration Rover mission.• Uses primarily mixed- initiative planning (i.e. collaborative planning
between human and robot)
COMP-424, Lecture 8 - January 30, 2013 4
![Page 5: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/5.jpg)
Search vs. Planning
• In theory, the types of problems above could be tackled by search methodswe discussed so far
• Two main difficulties arise in complex search problems:
– Branching factor is huge!– Difficult to find good heuristic functions
• Ideally, we don’t want to search over individual states, but over sets ofstates or (as seen last time) beliefs over states
• Key idea in planning: use a more powerful form of knowledgerepresentation to describe sets of states (or similar “abstractions”)
COMP-424, Lecture 8 - January 30, 2013 5
![Page 6: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/6.jpg)
Example: Second Life
• How do we represent states in this game?
• How do we decide what to do?
COMP-424, Lecture 8 - January 30, 2013 6
![Page 7: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/7.jpg)
Knowledge Representation
• A complete intelligent agent needs to be able to perform several tasks:
– Perception: what is my state?– Cognition/deliberation: what action should I take?– Action: how do I execute the action?
• State recognition implies some form of representation
• Figuring out the right action implies some form of inference
• Two levels to think about:
– Knowledge level: what does the agent know?– Implementation level: how is the knowledge represented?
COMP-424, Lecture 8 - January 30, 2013 7
![Page 8: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/8.jpg)
Knowledge Bases
• The golden dream:
– Tell the agent what it needs to know– The agent uses rules of inference to deduce consequences
• This is the declarative approach to building agents.
4
COMP-424: Artificial intelligence Joelle Pineau7
Knowledge bases
The golden dream of AI:
– Tell the agent what it needs to know.
– The agent uses rules of inference to deduce consequences.
This is the declarative approach to building agents.
Assumes agents have two different parts:
– A knowledge base, which contains a set of facts expressed in some formal,
standard language.
– An inference engine, with general rules for deducing new facts and drawing
conclusions.
Inference engine
Knowledge base
Domain-independent algorithms
Domain-specific content
COMP-424: Artificial intelligence Joelle Pineau8
An example: Wumpus World
Percepts: Breeze, Glitter, Smell (not the full board).
Actions: Turn-left, Turn-right, Forward, Grab,
Release, Shoot
Goal: Get gold back to start without entering
pit or wumpus square
Rules of the environment:
• Squares adjacent to wumpus are smelly.
• Squares adjacent to pit are breezy.
• Glitter if and only if gold is in the same square.
• Shooting kills the wumpus if you are facing it.
• Shooting uses up the only arrow.
• Grabbing picks up the gold if in the same square.
Stench
Stench
Stench
START
Gold
PIT
PIT
PIT
You!
• Agents have two different parts:
– A knowledge base, which contains a set of facts expressed in someformal, standard language
– An inference engine, with general rules for deducing new facts
COMP-424, Lecture 8 - January 30, 2013 8
![Page 9: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/9.jpg)
An Example: Wumpus WorldPercepts: Breeze, Glitter, SmellActions: Left turn, Right turn, Forward, Grab,Release, ShootGoals: Get gold back to start without enteringpit or wumpus squareEnvironment:
• Squares adjacent to wumpus are smelly
• Squares adjacent to pit are breezy
• Glitter if and only if gold is in the samesquare
• Shooting kills the wumpus if you are facingit
• Shooting uses up the only arrow
• Grabbing picks up the gold if in the samesquare
4
COMP-424: Artificial intelligence Joelle Pineau7
Knowledge bases
The golden dream of AI:
– Tell the agent what it needs to know.
– The agent uses rules of inference to deduce consequences.
This is the declarative approach to building agents.
Assumes agents have two different parts:
– A knowledge base, which contains a set of facts expressed in some formal,
standard language.
– An inference engine, with general rules for deducing new facts and drawing
conclusions.
Inference engine
Knowledge base
Domain-independent algorithms
Domain-specific content
COMP-424: Artificial intelligence Joelle Pineau8
An example: Wumpus World
Percepts: Breeze, Glitter, Smell (not the full board).
Actions: Turn-left, Turn-right, Forward, Grab,
Release, Shoot
Goal: Get gold back to start without entering
pit or wumpus square
Rules of the environment:
• Squares adjacent to wumpus are smelly.
• Squares adjacent to pit are breezy.
• Glitter if and only if gold is in the same square.
• Shooting kills the wumpus if you are facing it.
• Shooting uses up the only arrow.
• Grabbing picks up the gold if in the same square.
Stench
Stench
Stench
START
Gold
PIT
PIT
PIT
You!
COMP-424, Lecture 8 - January 30, 2013 9
![Page 10: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/10.jpg)
Wumpus World Characteristics
• The world is static: the positions of the pits, gold, and monster do notchange during the course of a game
• The actions have deterministic effects.
• Unlike most search problems we talked about, here the world is partiallyobservable!
• The agent does not know the map from the beginning, it has to figureit out based on local perception
COMP-424, Lecture 8 - January 30, 2013 10
![Page 11: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/11.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 8
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 11
![Page 12: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/12.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 9
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 12
![Page 13: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/13.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 10
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 13
![Page 14: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/14.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 11
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 14
![Page 15: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/15.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 12
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 15
![Page 16: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/16.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 13
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 16
![Page 17: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/17.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 14
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 17
![Page 18: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/18.jpg)
Exploring a Wumpus world
!"#!$%&'("#()%%*%+"#+,%--."#./'0"#01,213
CS 460, Session 10 15
0"#01,21345#"#+67%8#"#8/3/'%9:#"#:-/''%)
COMP-424, Lecture 8 - January 30, 2013 18
![Page 19: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/19.jpg)
Example: Getting Out of Tight Spots
6
COMP-424: Artificial intelligence Joelle Pineau11
Example: Getting out of tight spots
• 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
What knowledge representation supports this reasoning?
A
S
COMP-424: Artificial intelligence Joelle Pineau12
Logic
• Logics are formal languages for representing information such that
conclusions can be drawn.
• Logic:
– Syntax defines which sentences are allowed in the language.
– Semantics define the “meaning” of sentences.
I.e. which sentences are true in a given world.
E.g. the language of arithmetic
X+2 ! y is a sentence
x2 + y > 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
Smell in (1,1) ⇒ cannot moveCan use a strategy of coercion:
• Shoot straight ahead
• Wumpus was there ⇒ dead ⇒ safe
• Wumpus was not there ⇒ safe
What knowledge representation supports this reasoning?
COMP-424, Lecture 8 - January 30, 2013 19
![Page 20: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/20.jpg)
Logic
• Logics are formal languages for representing information such thatconclusions can be drawn
• Logic has two components:
– Syntax defines the sentences in the language– Semantics define the “meaning” of sentences
I.e. define the truth of a sentence in a world
• E.g., the language of arithmetic
x+ 2 ≥ y is a sentence; x2 + y > is not a sentence
x + 2 ≥ y is true if and only if the number x + 2 is no less than thenumber y
x+ 2 ≥ y is true in a world where x = 7, y = 1x+ 2 ≥ y is false in a world where x = 0, y = 6
COMP-424, Lecture 8 - January 30, 2013 20
![Page 21: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/21.jpg)
Types of logic
• Logics are characterized by what they commit to as “primitives”
– Ontological commitment: what exists—facts? objects? time? beliefs?– Epistemological commitment: what states of knowledge?
Language Ontological Commitment Epistemological Comm.Propositional logic facts true/false/unknownFirst-order logic facts, objects, relations true/false/unknownTemporal logic facts, objects, relations, times true/false/unknownProbability theory facts degree of belief 0. . . 1Fuzzy logic degree of truth degree of truth 0. . . 1
COMP-424, Lecture 8 - January 30, 2013 21
![Page 22: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/22.jpg)
Interpretations
• We want to have a rule for generating (or testing) new sentences thatare always true
• But the truth of a sentence may depend on its interpretation!
• Formally, an interpretation is a way of matching objects in the world withsymbols in the sentence (or in the knowledge database)
• A sentence may be true in one interpretation and false in another
• Terminology:
– A sentence is valid if it is true in all interpretations– A sentence is satisfiable if it is true in at least one interpretation– A sentence is unsatisfiable if it is false in all interpretations
COMP-424, Lecture 8 - January 30, 2013 22
![Page 23: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/23.jpg)
Entailment and Inference
KB |= α
• Knowledge base KB entails sentence α if and only if α is true in allworlds where KB is true.
E.g., the KB containing “I finished AI homework” and “I am happy”entails “I finished the AI homework or I am happy”
• KB `i α means sentence α can be derived from KB by inferenceprocedure i
• Desired qualities of an inference procedure i:
– Soundness: i is sound if, whenever KB `i α, it is also true that KB|= α. In other words, we infer only necessary truths
– Completeness: i is complete if, whenever KB |= α, it is also true thatKB `i α. In other words, we can generate all the necessary truths
COMP-424, Lecture 8 - January 30, 2013 23
![Page 24: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/24.jpg)
Example: Entailment in wumpus worldEntailment in the wumpus world
!"#$%#"&'(%)#*+(,*#*-#"'.('&#/"'.("'(012132(4&5"'.(+"./#2(6+**7*("'(08213
9&':",*+(;&::"6<*(4&,*<:()&+(=>%::$4"'.(&'<?(;"#:
CS 460, Session 10 27
%::$4"'.(&'<?(;"#:
@(>&&<*%'(-/&"-*:(! A(;&::"6<*(4&,*<:
COMP-424, Lecture 8 - January 30, 2013 24
![Page 25: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/25.jpg)
Example: Models in wumpus world
Wumpus models
CS 460, Session 10 28
COMP-424, Lecture 8 - January 30, 2013 25
![Page 26: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/26.jpg)
Example: Knowledge base in wumpus worldWumpus models
CS 460, Session 10 29
! "#$%$&'()'*+&,-./$-'.0*$1$,2*0-3456,7*
COMP-424, Lecture 8 - January 30, 2013 26
![Page 27: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/27.jpg)
Example: Model checking in wumpus worldWumpus models
CS 460, Session 10 30
! "#$%$&'()'*+&,-./$-'.0*$1$,2*0-3456,7*! 89 %$:;9<=>$6*$*4?0:<$"# ! 89<$)-,30/$2@$!"#$%&'($')*+,! A,/0.$BC0DE67F$&,-E*$,7.@$&65C$GHIHJK$&,-./*
COMP-424, Lecture 8 - January 30, 2013 27
![Page 28: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/28.jpg)
Example: Model checking in wumpus worldWumpus models
CS 460, Session 10 32
! "#$%$&'()'*+&,-./$-'.0*$1$,2*0-3456,7*! 89 %$:;9<9=$6*$*4>0:<$"#$/,0*$7,5$07546.$89! "#$! 89
COMP-424, Lecture 8 - January 30, 2013 28
![Page 29: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/29.jpg)
Propositional Logic: Syntax
• Propositional logic is the simplest logic.
• Syntax rules:
– Atomic symbols l1, l2 etc are sentences– If S is a sentence, ¬S is a sentence– If S1 and S2 are sentences, S1 ∧ S2 is a sentence– If S1 and S2 are sentences, S1 ∨ S2 is a sentence– If S1 and S2 are sentences, S1 ⇒ S2 is a sentence– If S1 and S2 are sentences, S1 ⇔ S2 is a sentence
COMP-424, Lecture 8 - January 30, 2013 29
![Page 30: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/30.jpg)
Propositional Logic: Semantics
• A model specifies true/false for each proposition symbol
E.g. A B CTrue True False
(Think of a model as a possible world in which the symbols can beevaluated)
• Rules for evaluating truth with respect to a model m:
¬S is true iff S is falseS1 ∧ S2 is true iff S1 is true and S2 is trueS1 ∨ S2 is true iff S1 is true or S2 is trueS1 ⇒ S2 is true iff S1 is false or S2 is true
i.e., is false iff S1 is true and S2 is falseS1 ⇔ S2 is true iff S1 ⇒ S2 is true and S2 ⇒ S1 is true
COMP-424, Lecture 8 - January 30, 2013 30
![Page 31: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/31.jpg)
Validity and Satisfiability
• A sentence is valid if it is true in all models
e.g., A ∨ ¬A, A ⇒ A, (A ∧ (A ⇒ B)) ⇒ B
Validity is connected to inference via the Deduction Theorem:
KB |= α if and only if KB ⇒ α is valid
• A sentence is satisfiable if it is true in some model
e.g., A ∨ B, C
• A sentence is unsatisfiable if it is true in no models
e.g., A ∧ ¬A
• Satisfiability is connected to inference via the following:
KB |= α if and only if KB ∧¬α is unsatisfiable
This is proof by contradiction!
COMP-424, Lecture 8 - January 30, 2013 31
![Page 32: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/32.jpg)
Two kinds of inference (proof) methods
• Model checking:
– Truth table enumeration (sound and complete for propositional logic)– Heuristic search in model space (sound but incomplete)
• Application of inference rules:
– Legitimate (sound) generation of new sentences from old– A proof is a sequence of inference rule applications– Inference rules can be used as operators in a standard search algorithm!
COMP-424, Lecture 8 - January 30, 2013 32
![Page 33: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/33.jpg)
Propositional Inference: Truth Table Method
• Let α = A ∨ B and KB =(A ∨ C) ∧ (B ∨¬ C)
• Is it the case that KB |= α?
• Check all possible models — α must be true wherever KB is true
A B C A ∨ C B ∨¬ C KB αFalse False FalseFalse False TrueFalse True FalseFalse True TrueTrue False FalseTrue False TrueTrue True FalseTrue True True
COMP-424, Lecture 8 - January 30, 2013 33
![Page 34: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/34.jpg)
Properties of truth table method
• The truth table method is a sound and complete inference method, whichchecks truth in all possible models.
• But the truth table method is very inefficient! 2n models for n literals
• There must be a more efficient way to prove sentences...
COMP-424, Lecture 8 - January 30, 2013 34
![Page 35: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/35.jpg)
Normal Forms
• Normal forms are standardized forms for writing sentences, which will beuseful if we want to apply inference rules in a uniform way
• Conjunctive Normal Form (CNF—universal)
conjunction of disjunctions of literals︸ ︷︷ ︸E.g., (A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)
• Disjunctive Normal Form (DNF—universal)
disjunction of conjunctions of literals︸ ︷︷ ︸E.g., (A ∧ B) ∨ (A ∧ ¬C) ∨ (A ∧ ¬D) ∨ (¬B ∧ ¬C) ∨ (¬B ∧ ¬D)
• Horn Form (restricted)
conjunction of Horn clauses (clauses with ≤ 1 positive literal) E.g.,(A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)
Often written as set of implications: B ⇒ A and (C ∧D)⇒ B
COMP-424, Lecture 8 - January 30, 2013 35
![Page 36: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/36.jpg)
Inference rules for propositional logic
• Resolution (for CNF): complete for propositional logic
α ∨ β, ¬β ∨ γα ∨ γ
• Modus Ponens (for Horn Form): complete for Horn KBs
α1, . . . , αn, α1 ∧ · · · ∧ αn ⇒ β
β
Can be used with forward chaining or backward chaining
COMP-424, Lecture 8 - January 30, 2013 36
![Page 37: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/37.jpg)
Forward chaining
• When a new sentence p is added to the KB
– Look for all sentences that share literals with p– Perform resolution– Add new sentences to the KB and continue
• Two important properties
– Forward chaining is data-drivenE.g., inferring properties and categories from new percepts
– Forward chaining is an eager method: new facts are inferred as soonas possible
COMP-424, Lecture 8 - January 30, 2013 37
![Page 38: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/38.jpg)
Backward chaining
• When a query q is asked:
– If q is in the knowledge base, return true– Else use resolution for q with other sentences in KB, and continue
from the result
• Two important properties:
– Backward chaining is goal-driven: it centers the reasoning around thequery begin asked
– It is a lazy reasoning method: new facts are only inferred as needed,and only to the extent that they help answer the query.
COMP-424, Lecture 8 - January 30, 2013 38
![Page 39: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/39.jpg)
Forward vs backward chaining: Which one is better?
• It depends on the problem at hand!
• Backward chaining is parsimonious in the amount of computationperformed, and does not grow the knowledge base as much as forwardchaining
• Backward chaining is focused on the proof that needs to be generated,so is generally more efficient
• But it does nothing until questions are asked!
• Backward chaining is usually used in proof by contradiction
• Forward chaining extends the knowledge base, and hence improves theunderstanding of the world
• Typically, backward chaining is used in proofs by contradiction
• Forward chaining is used in tasks where the focus is not on producing aproof, but on providing a model of the world
COMP-424, Lecture 8 - January 30, 2013 39
![Page 40: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/40.jpg)
Other useful rules
• And-elimination:α1 ∧ · · · ∧ αn
αi,∀i = 1, . . . n
• Implication elimination:α⇒ β
¬α ∨ β
COMP-424, Lecture 8 - January 30, 2013 40
![Page 41: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/41.jpg)
Example
• Knowledge base
– HaveAILecture ⇒ (TodayIsMonday ∨ TodayIsWednesday)– ¬ TodayIsMonday– HaveAILecture ∨ HaveNoClass– HaveNoClass ⇒ Sad– ¬ Sad
• Can you infer what day it is?
COMP-424, Lecture 8 - January 30, 2013 41
![Page 42: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/42.jpg)
Complexity of Inference
• What is the complexity of verifying the validity of a sentence of n literals?
2n
• What if our knowledge is expressed only in terms of Horn clauses?
The inference time becomes polynomial!
– Every Horn clause establishes exactly one new fact– We can add all the new facts implied by the database in n passes
This is why Horn clauses are often used in expert systems
COMP-424, Lecture 8 - January 30, 2013 42
![Page 43: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/43.jpg)
An Example: Wumpus World
• Knowledge base:
¬S1,1 ¬S2,1 S1,2 ¬B1,1 B2,1 ¬B1,2
• Knowledge about the environment:
¬S1,1 ⇒ ¬W1,1 ∧ ¬W1,2 ∧ ¬W2,1
¬S2,1 ⇒ ¬W1,1∧¬W2,2∧¬W2,1∧¬W3,1
S1,2 ⇒W1,1 ∨W1,2 ∨W2,2 ∨W1,3
• Now we can use inference rules to find outwhere the Wumpus is!
16
COMP-424: Artificial intelligence Joelle Pineau31
Complexity of inference
• What is the complexity of verifying the validity of a sentence of n
literals?
2n
• What if our knowledge is expressed only in terms of Horn
clauses?
Inference time is polynomial!
– Every Horn clause establishes exactly one fact.
– We can state all new facts implied by the KB in n passes.
– This is why Horn clauses are often used in expert systems.
COMP-424: Artificial intelligence Joelle Pineau32
Example: The Wumpus World
• KB:
¬S1,1 ¬S2,1 S1,2
¬B1,1 B2,1 ¬B2,1
• Knowledge about the environment:
¬S1,1!¬W1,1"¬W1,2"¬W2,1
¬S2,1!¬W1,1"¬W2,1"¬W2,2"¬W3,1
S1,2!W1,1#W1,2#W2,2#W1,3
Now we can use inference rules to find out where the Wumpus is!
Stench
Stench
Stench
START
Gold
PIT
PIT
PIT
COMP-424, Lecture 8 - January 30, 2013 43
![Page 44: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/44.jpg)
Summary of Propositional Logic
• The good: Propositional logic is very simple!
Few rules, inference is simple
• The bad: Propositional logic is very simple!
So we cannot express things in a compact way
• E.g for the wumpus world, we need propositions for ALL positions, ANDALL TIMES!
• We cannot say things like “for all squares” or “the wumpus is in one ofthe neighboring squares”
COMP-424, Lecture 8 - January 30, 2013 44
![Page 45: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/45.jpg)
Planning with propositional logic
• A planning problem is described just like a search problem (states,actions/operators, goal), but the problem representation is morestructured:
Search PlanningStates Data structures Logical sentencesActions Code Preconditions/outcomesGoal Goal test Logical sentence (conjunction)Plan Sequence from S0 Constraints on actions
• Natural idea: represent states using propositions, and use logical inference(forward / backward chaining) to find sequences of actions.
COMP-424, Lecture 8 - January 30, 2013 45
![Page 46: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/46.jpg)
Planning as Satisfiability: SatPlan
• Intorduced by Kautz and Selman, 1990s, very successful method overthe years
• Take a description of a planning problem and generate all possible literals,at all time slices
• Generate a humongous SAT problem
• Use a state-of-art SAT solver (eg WalkSAT) to get a plan
• Randomized SAT solvers can be used as well
COMP-424, Lecture 8 - January 30, 2013 46
![Page 47: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/47.jpg)
Complexity of planning
• Clearly NP-hard (as it can be seen as SAT in finite-length plan case)
• But actually worse (PSPACE) if we let plan duration
COMP-424, Lecture 8 - January 30, 2013 47
![Page 48: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/48.jpg)
GraphPlan
• Introduced by Blum and Furst in 1995, currently the state-of-art inplanning algorithms
• Main idea:
– Construct a graph that encodes constraints on possible plans– If a valid plan exists it will be part of this planning graph, so search
only within this graph
• Planning graph can be built in polynomial time.
COMP-424, Lecture 8 - January 30, 2013 48
![Page 49: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/49.jpg)
Problem description
• Goal is described in conjunctive form
• The preconditions of actions have to be conjunctions
• Usually operators are described in STRIPS-like notation
COMP-424, Lecture 8 - January 30, 2013 49
![Page 50: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/50.jpg)
Planning Graph
• Two types of nodes:
– Propositions– Actions
These are arranged in levels: propositions and action levels alternate
• Three types of edges between levels:
– Precondition: edge from P to A if P is a precondition of A– Add: edge from A to P if A has P as effect– Delete: edge from A to ¬P if A deletes P
• Action level includes actions whose preconditions are satisfied in theprevious level, plus “no-op” actions (do nothing)
COMP-424, Lecture 8 - January 30, 2013 50
![Page 51: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/51.jpg)
Example: Dinner Date
• Initial state: garbage ∧ cleanHands ∧ quiet
• Goal state: dinner ∧ present ∧¬garbage
• Actions:
– Cook: precondition: cleanHands; effect: dinner– Wrap: precondition: quiet; postcondition: present– Carry: effect: ¬garbage ∧ ¬cleanHands– Dolly: effect: ¬garbage ∧ ¬quiet
COMP-424, Lecture 8 - January 30, 2013 51
![Page 52: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/52.jpg)
Example: First Level of Planning Graph
11
Dinner Date example
• Thicker lines correspond to doing nothing
• Action level contains all actions whose preconditions are satisfied
• Edges between nodes on same level indicate mutual exclusion
COMP-424, Lecture 8 - January 30, 2013 52
![Page 53: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/53.jpg)
Mutual exclusion
• Two actions are mutually exclusive (mutex) at some stage if no validplan could contain both at that stage
• Two actions at the same level can be mutex because of:
– Inconsistent effects: an effect of one negates the effect of the other– Interference: one negates a precondition of the other– Competing needs: the actions have mutex preconditions
• Two propositions at the same level are mutex if:
– One is a negation of the other– Inconsistent support: All ways of achieving the propositions are
pairwise mutex
COMP-424, Lecture 8 - January 30, 2013 53
![Page 54: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/54.jpg)
Example: Mutual Exclusions
11
Dinner Date example
• wrap and dolly are mutex because dolly negates the precondition of wrap
• carry and the no-op are mutex because one negates the effect of theother
• present and ¬quiet are mutex because the actions achieving them, wrapand dolly, are mutex
COMP-424, Lecture 8 - January 30, 2013 54
![Page 55: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/55.jpg)
Constructing the Planning Graph
• Level P1 is initialized with all the literals from the initial state
• Add an action at level Ai if all its preconditions are present in level Pi
• Add a proposition in level Pi+1 if it is the effect of some action in levelAi (including no-ops)
• Maintain a set of exclusion relations to eliminate incompatiblepropositions and actions
COMP-424, Lecture 8 - January 30, 2013 55
![Page 56: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/56.jpg)
Example: Two-level Planning Graph
12
Dinner Date example
COMP-424, Lecture 8 - January 30, 2013 56
![Page 57: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/57.jpg)
Observations
• Number of propositions always increases (because all the ones from theprevious level are carried forward)
• Number of actions always increases (because the number of preconditionsthat are satisfied increases)
• Number of propositions that are mutex decreases (because there aremore ways to achieve same propositions, and not all will be mutex)
• Number of actions that are mutex decreases (because of the decrease inthe mutexes between actions)
• After some time, all levels become identical: graph “levels off”
• Because there is a finite number of propositions and actions, mutexeswill not reappear
COMP-424, Lecture 8 - January 30, 2013 57
![Page 58: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/58.jpg)
Valid Plan
• A valid plan is a subgraph of the planning graph such that:
– All goal propositions are satisfied in the last level– No goal propositions are mutex– Actions at the same level are not mutex– Each action’s preconditions are made true by the plan
• Algorithm:
1. Grow the planning graph until all goal propositions are reachable andnot mutex
2. If the graph levels off first, return failure (no valid plan exists)3. Search the graph for a planning graph4. If no valid plan is found add a level and try again
COMP-424, Lecture 8 - January 30, 2013 58
![Page 59: Lecture 7: Logic and Planning - McGill University …dprecup/courses/AI/Lectures/ai-lecture08.pdfLecture 7: Logic and Planning Planning and representing knowledge Logic in general](https://reader031.vdocuments.mx/reader031/viewer/2022022008/5ad8433a7f8b9ab8378d1f95/html5/thumbnails/59.jpg)
Example: Plan extraction
26
Dinner Date example
COMP-424, Lecture 8 - January 30, 2013 59