Upload
theresa-bryan
View
221
Download
1
Embed Size (px)
Citation preview
1
The Wumpus Game
Stench Breeze
BreezeStenchGold
Breeze
Stench Breeze
Start Breeze Breeze
2
The Wumpus Game• Stench in the square containing the wumpus
and in the directly adjacent squares
• Breeze in the squares directly adjacent to a pit
• Glitter in the square where the gold is
• Bump when an agent walks into a wall
• Scream when the wumpus is killed
3
The Wumpus Game• Agent’s percept: [Stench, Breeze, Glitter, Bump, Scream]
• Agent’s actions:– Go forward, turn right 90o, turn left 90o
– Grab to pick up an object in the same square– Fire 1 arrow in a straight line in the faced direction – Climb to leave the cave
• Death if entering a square of a pit or a live wumpus
• Agent’s goal: find and bring the gold back to the start
4
The Wumpus Game
Stench Breeze
BreezeStenchGold
Breeze
StenchOK
Breeze
Start A
BreezeOK
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
5
The Wumpus Game
Stench Breeze
BreezeStenchGold
Breeze
StenchOK P?
Breeze
Start V
BreezeA P?
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
6
The Wumpus Game
Stench Breeze
BreezeStenchGold
Breeze
StenchA OK
Breeze
Start V
BreezeV
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
7
The Wumpus Game
Stench Breeze
BreezeStenchGold
Breeze
StenchV A
Breeze
Start V
BreezeV
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
8
The Wumpus Game
Stench Breeze
BreezeStenchGold A
Breeze
StenchV V
Breeze
Start V
BreezeV
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
9
Propositional Logic Syntax• Logical constants: true, false
• Propositional symbols: P, Q, …
• Logical connectives: , , , ,
• Sentences (formulas):– Logical constants– Proposition symbols– If is a sentence, then so are and ()– If and are sentences, then so are
, and
10
Propositional Logic Semantics
• Interpretation: propositional symbol true/false
• The truth value of a sentence is defined by the truth table
P Q P P Q P Q P Q P Q
false false true false false true true
false true true false true true false
true false false false true false false
true true false true true true true
11
Propositional Logic Semantics
• Satisfiable: true under an interpretation
• Valid: true under all interpretations
P Q P P (P Q) Q ((P Q) Q) P
false false false false true
false true false false true
true false false true true
true true false false true
satisfiableunsatisfiable
valid
12
Propositional Logic Semantics
• Model: an interpretation under which the sentence is true
Q
P Q
P Q
P Q
P
Q
P Q
P Q
P Q
P
13
Propositional Logic Semantics
• Entailment: KB iff every model of KB is a model of
is a logical consequence of KB
P Q P Q P Q, P
false false true false
false true true false
true false false false
true true true true
{P Q, P} Q
14
Propositional Logic Semantics
• Equivalence: iff and
P Q P Q P Q
false false true true
false true true true
true false false false
true true true true
P Q P Q
15
Propositional Logic Semantics
• Theorems: – iff is valid
KB can be proved by validity KB
– iff is unsatisfiable
KB can be proved by refutation of KB
16
Inference Rules• Rule R:
Premises:1,2,, n
Conclusion:
• Soundness: R is sound iff {1,2,, n}
17
Inference Rules• Modus Ponens:
,
-Elimination:12n
i
18
Inference Rules -Introduction:
1, 2, … , n
1 2 … n
-Introduction:i
1 2 … n
19
Inference Rules• Double-negation elimination:
20
Resolution• Unit resolution:
P1 … Pi … Pn, QPi Q (all Pi and Q are literals)
P1 … Pi-1 Pi+1 … Pn
• Full resolution:
P1 … Pi … Pn, Q1 … Qj … Qm
Pi Qj P1 … Pi-1 Pi+1 … Pn Q1 … Qj-1 Qj+1 … Qm
21
Resolution• Conjunctive normal form (CNF): conjunction of
disjunctions of literals
(L11 … L1k) … (Ln1 … Lnm)
clause
• k-CNF: each clause contains at most k literals
• Every sentence can be written in CNF
22
Inference Algorithms• To derive/assert a sentence given a knowledge
base as a set of sentences
• Inference rules + a searching algorithm
23
Inference AlgorithmsAlgorithm PL-Resolution(KB, )
input: KB and are PL sentences
output: true (to assert KB ) or false (otherwise)
Clauses = set of clauses in the CNF representation of KB New = {}
loopfor each Ci, Cj in Clauses do
Resolvents = PL-Resolve(Ci, Cj)
if Resolvents contains an empty clause then return true
New = New Resolventsif New Clauses then return falseClauses = Clauses New
24
Inference Algorithms• Soundness: every deduced answer is correct
if PL-Resolution returns true then KB
• Completeness: every correct answer is deducible
if KB then PL-Resolution returns true
25
Inference Algorithms• PL-Resolution is sound and complete
• Modus Ponens with any searching algorithm is not complete
KB = {P Q, Q R}, = P R
26
Inference Algorithms• Horn clause: disjunction of literals of which at
most one is positiveP1 P2 … Pn Q
orP1 P2 … Pn Q
• Forward or backward chaining can be used for inference on Horn clauses
27
Satisfiability Problem • SAT problem: to determine if a sentence is
satisfiable
(to determine if the symbols in the sentence can be assigned true/false as to make it evaluate to true)
(D B C) (B A C) (C B E)
(E D B) (B E C)
28
Satisfiability Problem • SAT problem in propositional logic is NP-
complete
This does not mean all instances of PL inference has the exponential complexity
Polynomial-time inference procedures for Horn clauses
• Many combinatorial problems in computer science can be reduced to SAT
29
Satisfiability Problem • Backtracking algorithms
• Davis and Putnam (1960)
• Davis, Logemann, Loveland (1962)
30
Satisfiability Problem • DPLL algorithm:
– Recursive, depth-first enumeration of possible models
– Early termination: a clause is true if any literal is true
(A B) (A C) is true if A is true regardless of B and C
– Pure symbol: has the same sign in all clauses
(A B) (B C) (C A)
A model would have the literals of pure symbols assigned true
Satisfied clause removal makes new pure symbols
– Unit clause: has just one literal
Unit clause satisfaction makes new unit clauses (unit propagation)
31
Satisfiability Problem • Local search algorithms
Evaluation function counts the number of unsatisfied clauses
• Randomness to escape local minima
Flipping the truth value of one symbol at a time
32
Statisfiability Problem Algorithm WalkSAT(Clauses, p, max_flips)
input: p is flipping probability, max_flips is number of flips allowed
output: a model or failure
Model = a random assignment of truth values to the symbols
for i = 1 to max_flips do
if Model satisfies Clauses then return Model
C = a randomly selected clause from Clauses that is false in Model
with probability p flip the value in Model of a symbol from C
else flip whichever symbol in C to maximizes no. of satisfied clauses
return failure
33
Satisfiability Problem • Complexity depends on the clause/symbol ratio
Hard when the ratio is from than 4.3
• WalkSAT is much faster than DPLL
34
Inference Monotonicity• Monotonicity: the set of entailed sentences
can only increase when information is added to the KB
if KB1 then (KB1KB2)
• Propositional logic is monotone
35
An Agent for the Wumpus Game
• Knowledge Base: Xij = column i, row j
S11 B11 R1: S11 W11 W12 W21
S21 B21 R2: S21 W11 W21 W22 W31
S12 B12 R3: S12 W11 W12 W22 W13
R4: S12 W13 W12 W22 W11
36
Agent for the Wumpus Game• Finding the wumpus:
– Modus Ponens (S11 + R1): W11 W12 W21
-Elimination: W11 W12 W21
– Modus Ponens (S21 + R2): W11 W21 W22 W31
-Elimination: W11 W21 W22 W31
– Modus Ponens (S12 + R4): W13 W12 W22 W11
– Unit resolution (W11 + W13 W12 W22 W11):
W13 W12 W22
– Unit resolution (W22 + W13 W12 W22): W13 W12
– Unit resolution (W12 + W13 W12): W13
37
Agent for the Wumpus Game• Translating knowledge into action:
A11 EastA W21 Forward
38
Agent for the Wumpus Game• Problems with the propositional agent:
– Too many propositions to handle:
"Don’t go forward if the wumpus is in front of you!" requires 16 x 4 = 64 propositions.
– Hard to deal with time and change
– Not expressive enough to represent or answer a question like "What action should the agent take?", …
39
Homework• In Russell & Norvig’s AIMA (2nd ed.): Exercises
of Chapter 7.