Unite 3 PDF
Unite 3 PDF
Logical Agents
Knowledge-based agents
“Logical AI:
The idea is that an agent can represent knowledge of its world,
its goals and the current situation by sentences in logic and decide
what to do by inferring that a certain action or course of action is
appropriate to achieve its goals.”
• Environment
– 4 X 4 grid of rooms
– Agent starts in square [1,1] facing to the right
– Locations of the gold, and Wumpus are chosen randomly
with a uniform distribution from all squares except [1,1]
– Each square other than the start can be a pit with proba-
bility of 0.2
Wumpus World PEAS
• Actuators:
– Left turn, Right turn, Forward, Grab, Release, Shoot
• Sensors:
– Stench, Breeze, Glitter, Bump, Scream
– Represented as a 5-element list
– Example: [Stench, Breeze, None, None, None]
Wumpus World properties
• Partially observable
• Static
• Discrete
• Single-agent
• Deterministic
• Sequential
Exploring Wumpus World
OK OK
1,1 2,1 3,1 4,1 1,1 2,1 3,1 4,1
A P?
A
V B
OK OK OK OK
(a) (b)
Exploring Wumpus World
(a) (b)
Logic
• Knowledge base: a set of sentences in a formal representa-
tion, logic
KB |= α
Propositional logic
• Propositional logic (PL) is the simplest logic.
• Given an implication p → q
• Given an implication p → q
p p→q
q
Inference (Modus Ponens)
p p→q
q
p 1 ∧ . . . ∧ pn → q
Modus Ponens deals with Horn clauses:
¬q p→q
¬p
Inference (Modus Tollens)
¬q p→q
¬p
OK OK
1,1 2,1 3,1 4,1 1,1 2,1 3,1 4,1
A P?
A
V B
OK OK OK OK
(a) (b)
OK OK
1,1 2,1 3,1 4,1 1,1 2,1 3,1 4,1
A P?
A
V B
OK OK OK OK
(a) (b)
OK OK
1,1 2,1 3,1 4,1 1,1 2,1 3,1 4,1
A P?
A
V B
OK OK OK OK
(a) (b)
KB ` α
1. Sound: does not infer false formulas, that is, derives only
entailed sentences.
{α|KB ` α} ⊆ {KB |= α}
{α|KB ` α} ⊇ {KB |= α}
Validity & satisfiability
• A sentence is valid (aka tautology) if it is true in all models,
e.g., T rue, p ∨ ¬p, p ⇒ p, (p ∧ (p ⇒ q)) ⇒ q
(a) (b)
Proof by Resolution
• Unit resolution:
`1 ∨ · · · ∨ `k m
`1 ∨ · · · ∨ `i−1 ∨ `i+1 ∨ · · · ∨ `k
where `i and m are complementary literals.
• Example:
P1,3 ∨ P2,2 ¬P2,2
P1,3
α = ¬P1,2
Forward/backward chaining
• KB = conjunction of Horn clauses
p1, . . . , pn p1 ∧ . . . ∧ p n → q
q
• Backward chaining:
- Goal-driven, appropriate for problem-solving,
• Example:
W arm W arm→Sunny
Sunny
• How can we express that all squares in the room are clean?
• How can we express that some squares in the room are clean?
∀ x Square(x) ⇒ Clean(x)
∃ x Square(x) ∧ ¬Clean(x)
Question: Now, can we express that some squares have
chairs on top?
Note:
• ∀x P (x) is like P (A) ∧ P (B) ∧ . . .
• ∃x P (x) is like P (A) ∨ P (B) ∨ . . .
• ¬∀x P (x) is like ∃ x ¬P (x)
• ∀x ∃ y likes(x, y) is NOT like ∃y ∀x likes(x, y)
First Order Logic
• All birds fly:
∀ x bird(x) ⇒ F ly(x)
• All birds except penguins fly:
http://aima.cs.berkeley.edu/