Chapter7ai2007s/slides/Chapter7a-lee-2007(2-page).pdf · 1 20070426 Chap7a 1 Chapter7 Logical...
Transcript of Chapter7ai2007s/slides/Chapter7a-lee-2007(2-page).pdf · 1 20070426 Chap7a 1 Chapter7 Logical...
1
20070426 Chap7a 1
Chapter7
Logical Agents (Part A)
20070426 Chap7a 2
Knowledge Bases• Knowledge base = a set of sentences in a formal language• Declarative approach to building an agent
- Tell: to add new sentence to KB- Ask: to query what is known
• InferenceDeriving new sentences from old
percept
agent
KB
ask/resulttellsentences
inferenceengine
2
20070426 Chap7a 3
A Generic Knowledge-based Agent
KB initially contain some background knowledge.Each time the agent program is called,
it Tells KB what is perceivedit Asks KB what action it should perform
Once the action is chosen, the agent records its choice with Telland execute the action
20070426 Chap7a 4
Abilities of KB Agent
• Represent states and actions• Incorporate new percepts• Update internal representation of the world• Deduce hidden properties of the world• Deduce appropriate actions
3
20070426 Chap7a 5
Description of KB Agent• similar to agents with internal state• can be described at different levels
- Knowledge levelSpecify what they know and what its goals are ,
regardless of the actual implementation. (Declarative description)
- Implementation levelData structures in KB and algorithms that
manipulate them e.g propositional logic and resolution.
20070426 Chap7a 6
Wumpus World PEAS Description•Performance measure:
gold +1000, deadth –1000, -1 per step, -10 for using the arrow
• Environment: 4x4 grid of roomseach square other than the start can be a pit,
with probability 0.2• Sensors: Stench, Breeze, Glitter, Bump, Scream• Actuators: Left, Right, Forward, Grab, Release, Shoot
smelly (adjacent to wumpus)breezy((adjacent to pit)glitter (iff gold exists)shooting(only one arrow , face and kill the wumpus)grabbing(pick up gold)release(drop the gold)
• Goal: To maximize its average scorefor the entire class of grid environments
4
20070426 Chap7a 7
Wumpus World Characterization
Observable?? No --- only local perceptionDeterministic?? Yes --- outcomes exactly specifiedEpisodic?? No --- sequential at the level of actionsStatic?? Yes --- Wumpus and pits can not moveDiscrete?? YesSingle-agent?? Yes --- Wumpus is essentially a
nature feature
20070426 Chap7a 8
Exploring a Wumpus World
Initial situation, after percept [None, None, None, None, None]
5
20070426 Chap7a 9
Exploring a Wumpus World (cont.-1)
After one move, with percept [None, Breeze, None, None, None]
20070426 Chap7a 10
Exploring a Wumpus World (cont.-2)
Go back to another unvisited ok position
6
20070426 Chap7a 11
Exploring a Wumpus World (cont.-3)
After the third move, with percept [Stench, None, None, None, None]
20070426 Chap7a 12
Exploring a Wumpus World (cont.-4)
7
20070426 Chap7a 13
Exploring a Wumpus World (cont.-5)
20070426 Chap7a 14
Exploring a Wumpus World (cont.-6)
8
20070426 Chap7a 15
Exploring a Wumpus World (cont.-7)
After the fifth move, with percept [Stench, Breeze, Glitter, None, None]Grab the gold and end the game
20070426 Chap7a 16
Other Tight Spots
Breeze in (1,2) and (2,1)⇒ no safe actions
Assuming pits uniformly distributed,(2,2) his pit with prob. 0.86, vs. 0.31 ???
Stench in (1,1)⇒ cannot move
Can use a strategy of coercion:Shoot straight ahead
Wumpus was there ⇒ dead ⇒ safeWumpus was not there ⇒ safe
9
20070426 Chap7a 17
Logic in General• Logics are formal languages for representing
information.• Syntax defines the sentences in the language• Semantics define the meaning of sentences
i.e. define truth of a sentence in a possible world
e.g. the language of arithmeticx + y = 4 (a sentence); x4y+= (not a sentence)
x + y = 4 is true iff there are four in totalx + y = 4 is true in a world where x = 2, y = 2x + y = 4 is false in a world where x = 2, y = 1
20070426 Chap7a 18
Entailment• Entailment means that one thing follows from another
KB |= α (Knowledge base KB entails sentence α )iff α is true in all worlds where KB is true
e.g. KB containing “the Giants won” and “the Reds won”
entails “Either the Giants won or the Reds won”e.g. x + y = 4 entails 4 = x + y
• Entailment is a relationship between sentences(i.e. syntax) that is based on semantics
10
20070426 Chap7a 19
Models
m is a model of a sentence αiff α is true in m
M(α): the set of all models of α
KB |= α iff M(KB) ⊆ M(α)
i.e. Every model in which KB is true, α is also true
20070426 Chap7a 20
Entailment in the Wumpus World
Situation after detecting nothing in [1,1]Moving right, breeze in [2,1]
Consider possible models for ?sAssuming only pits3 Boolean choices ⇒ 8 possible models
11
20070426 Chap7a 21
Wumpus Models
20070426 Chap7a 22
Wumpus Models (cont.-1)
KB = wumpus world-rules + observations
12
20070426 Chap7a 23
Wumpus Models (cont.-2)
KB = wumpus world-rules + observationsα1= “no pit in [1,2]” or “[1,2] is safe”KB |= α1 , proved by model checking
20070426 Chap7a 24
Wumpus Models (cont.-3)
KB = wumpus world-rules + observations
13
20070426 Chap7a 25
Wumpus Models (cont.-4)
KB = wumpus world-rules + observationsα2= “no pit in [2,2]” or “[2,2] is safe”KB |≠ α2 , proved by model checking
20070426 Chap7a 26
Inference• KB |−i α
(an inference algorithm i can derive α from KB)
We can think as the set of all consequents of KB (haystack)
and α (needle)entailment (needle in the haystack)inference (finding it)
14
20070426 Chap7a 27
Inference (cont.-1)
• Soundness or truth-preserving inference
i is sound if whenever KB |−i α, it is also true that KB |= α
(a sentence α is generated by an inference procedure ionly if it is entailed by the KB)
• Completenessi is complete
if whenever KB |= α, it is also true that KB |−i α
(a sentence α will be generated by an inference procedure i if it is entailed by the KB)
20070426 Chap7a 28
Inference (cont.-2)
Sentences are physical configurations of the agent, and reasoning is a process of constructing new physical configurations from old ones.
Logical reasoning should ensure that the new configurations represent aspects of the world that actually follow from the aspects that the old configurations represent.
15
20070426 Chap7a 29
Propositional Logic: Syntax• Logical constants: True and False• propositional symbols: e.g. P and Q • Composition rules:
∧ (and) conjunction∨ (or) disjunction⇒ (implies) implication⇔ (equivalent) equivalence, or biconditional¬ (not) negation
• BNF grammar for propositional logic Sentence Atomic | Complex Atomic True | False | P | Q | R …Complex (Sentence) | ¬ Sentence
Sentence Connective Sentence Connective ∧ | ∨ | ⇒ | ⇔
• Precedence: ¬ , ∧ , ∨ , ⇒ |and ⇔
20070426 Chap7a 30
Propositional Logic: Semantics• Define the rules for determining the truth of a sentence with
respect to a particular model
• Each model specifies true/false for each proposition symbole.g. P1,2 P2,2 P3,1
true true false(3 symbols, 8 possible models, can be enumerated automatically)
16
20070426 Chap7a 31
Wumpus world SentencesLet Pi,j be true if there is a pit in [i, j]Let Bi,j be true if there is a breeze in [i, j]
R1: ¬ P1,1 --- no pit in [1,1]R2: B1,1 ⇔ (P1,2 ∨ P2,1 ) --- Pits cause breezes in adjacent squaresR3: B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1 )R4: ¬ B1,1 --- no breeze in [1,1]R5: B2,1 --- breeze in [2,1]
20070426 Chap7a 32
Truth Tables for Connectives
17
20070426 Chap7a 33
Truth Tables for Inference
20070426 Chap7a 34
Inference by Enumeration
Depth-first enumeration of all models is sound and complete.Time complexity: O(2n)Space complexity: O(n)
Returns true if a sentence is hold within a model
Return a new partial model in which P has the value false
18
20070426 Chap7a 35
Logical EquivalenceTwo sentences are logically equivalent iff true in same models.
20070426 Chap7a 36
Validity and Satisfiability• A sentence is valid (or a tautology) if it is true in all
models.• Validity is connected to inference via
Deduction Theorem:KB |= α iff (KB ⇒ α) is valid.
• A sentence is satisfiable if it is true in some model.• A sentence is unsatifiable if it is true in no models.• Satisfiablity is connected to inference via
Refutation (or proof by contradiction): KB |= α iff (KB ∧ ¬ α) is unsatisfiable
e.g. A ⇒ A , (A ∧ (A ⇒ B )) ⇒ B --- valid A ∧ ¬ C --- satisfiableA ∧ ¬ A --- unsatisfiable
19
20070426 Chap7a 37
Inference Rules• Modus Ponens or Implication-Elimination
• And-Elimination
• And-Introduction
• Or-Introduction
βαβα ,⇒
i
n
αααα ∧∧∧ K21
n
n
αααααα∧∧∧ K
K
21
21 ,,,
ni
i
α∨∨α∨∨α∨αα
KK21
20070426 Chap7a 38
Inference Rules (cont.)
• Double-Negation Elimination
• Unit Resolution
• Resolution
αᬬ
αββα ¬∨ ,
γαγββα
∨∨¬∨ ,
kii1
k1
llllm ll
∨∨∨∨∨∨∨
+− ......,...
11
(li, m: complementary literals)
njj1kii1
n1k1
mmmmllllmm ll
∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨
+−+− ...............,...
1111
(li, mj: complementary literals)
20
20070426 Chap7a 39
Monotonicity• The set of entailed sentences can only increase
as information is added to the knowledge base.If KB |= α then KB ∧ β |= α
• The inference rules can be applied whenever suitable premises are found in the knowledge base --- the conclusion of the rule must follow regardless of what else is in the knowledge base.
20070426 Chap7a 40
An Agent for The Wumpus World
• The Knowledge Base
• Percepts
• Environment2,12,1
1,21,2
1,11,1
321
B S B S
B S
¬
¬
¬¬
1,22,11,11,11 : WWWS R ¬∧¬∧¬⇒¬
1,32,21,21,11,22 : WWWWS R ¬∧¬∧¬∧¬⇒¬
3,12,22,11,12,13 : WWWWS R ¬∧¬∧¬∧¬⇒¬
1,12,22,13,12,14 : WWWWS R ∨∨∨⇒
21
20070426 Chap7a 41
Wumpus World
20070426 Chap7a 42
Propositional KB Wumpus Agent
• Reasoning by applying rules of inference, e.g. Finding the wumpus by deriving .
• Translating knowledge into action, e.g.
Problems: • Too many propositions are necessary. • Many rules slow down the inference procedure. • Dealing with change (or time) is difficult.
3,1W
ForwardWEastA A ¬⇒∧∧ 1,21,1