Escolar Documentos
Profissional Documentos
Cultura Documentos
Logical Agents
SarfaRaaaZ NewaZ
Knowledge-Based Agent
sensors
?
environment
agent
Knowledge base
Inference Engine
Domain-independent algorithms 2
The Wumpus World
The Wumpus computer game
The agent explores a cave consisting of rooms
connected by passageways.
Lurking somewhere in the cave is the
Wumpus, a beast that eats any agent that
enters its room.
Some rooms contain bottomless pits that trap
any agent that wanders into the room.
Occasionally, there is a heap of gold in a
room.
The goal is to collect the gold and exit the
3
world without being eaten
Wumpus PEAS description
Performance measure:
gold +1000, death -1000,
-1 per step, -10 use 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
Shooting uses up the only arrow
Grabbing picks up gold if in same square
Releasing drops the gold in same square
Sensors: Breeze, Glitter, Smell, Bump, Scream
Actuators: Left turn, Right turn, Forward, Grab, Release,
Shoot 4
A typical Wumpus world
The agent
always starts in
the field [1,1].
The task of the
agent is to find
the gold, return
to the field
[1,1] and climb
out of the cave.
5
Wumpus World Characteristics
Observable?
Deterministic?
Static?
Discrete?
6
Wumpus world characterization
Fully Observable No
– only local perception
Deterministic Yes
– outcomes exactly specified
Static Yes
– Wumpus and Pits do not move
Discrete Yes
– none of the percepts and actions is continuous
with respect to time
7
The Wumpus agent’s first step
8
Later
9
Logics
M()
M(KB) 12
Entailment in the wumpus world
Situation after detecting
nothing in [1,1],
moving right, breeze in
[2,1]
Consider possible models
for KB assuming only
pits
3 Boolean choices 8
possible models
13
Wumpus models
14
Wumpus models
18
Propositional logic: Syntax
Propositional logic is the simplest logic.
Connectives:
(negation)
(conjunction)
(disjunction)
(implication)
(biconditional)
Propositional symbols, e.g., P, Q, R, …
Each Propositional symbols represent a
proposition. It’s value is either true or false. E.g.,
W1,3 stands for “wumpus in square [1,3]”.
True, False 19
Syntax of PL
sentence atomic sentence | complex sentence
atomic sentence Propositional symbol | True
\ False
complex sentence sentence
| (sentence sentence)
| (sentence sentence)
| (sentence sentence)
| (sentence sentence)
20
Syntax of PL
Examples:
((P Q) R)
(A B) (C)
Order of Precedence :
Examples:
A B C is equivalent to ((A)B)C
21
Models in Propositional Logic
Each model specifies truth value
(true/false) for each proposition symbol.
Examples:
Let A, B, C, and D be the propositional symbols
is m = {A=true, B=false, C=false, D=true} a model?
is m’ = {A=true, B=false, C=false} a model?
How many models can be defined over n
propositional symbols?
22
Semantics of PL
It specifies how to determine the truth
value of any sentence in a model m
The truth value of True is True
The truth value of False is False
The truth value of each atomic sentence
is given by m
The truth value of every other sentence is
obtained recursively by using truth tables
23
Truth Tables
24
Wumpus world sentences
Let 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
R2: B1,1
R3: B2,1
"Pits cause breezes in adjacent squares"
R4: B1,1 (P1,2 P2,1)
R5: B2,1 (P1,1 P2,2 P3,1)
Knowledge Base, KB = R1 R2 R3 R4 R5
25
Be Careful to Write Rules
Why we write the rule as follows ?
R4: B1,1 (P1,2 P2,1)
Why we don’t write the rule as follows ?
R4: B1,1 (P1,2 P2,1)
Read A B as:
“If A IS True, then I claim that B is True,
otherwise I make no claim.”
26
Example
(A B C) D A
F
F
T T
27
Model of a KB
Let KB be a set of sentences
KB = R1 R2 R3 R4 R5
A model m is a model of KB iff it is a
model of all sentences in KB, that is,
all sentences in KB are true in m
There are 7 proposition variables, so total
number of possible models are 27 = 128.
Among these 128 possible models, KB is
true only in 3 models.
28
Truth tables for inference
29
Inference by enumeration
Depth-first enumeration of all models is
sound and complete.
For n symbols, time complexity is O(2n),
space complexity is O(n).
Can we conclude KB entails P1,2 ?
Can we conclude KB entails P2,2 ?
30
Logical equivalence
Two sentences are logically equivalent iff true in same
models: α ≡ β iff α╞ β and β╞ α
31
Validity and satisfiability
A sentence is valid if it is true in all models,
e.g., True, A A, A A
Validity is connected to inference via the Deduction
Theorem: for any and β, |= β iff ( β) 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., AA
Satisfiability is connected to inference via the
following:
KB |= if and only if (KB ) is unsatisfiable
Remember proof by contradiction.
32
Validity and satisfiability
Relations between validity and
satisfiablity:
is valid iff is unsatisfiable.
is satisfiable iff is not valid.
33
Inference rules in PL
Modus Ponens ,
And-elimination: from a conjuction any
conjunction can be inferred:
All logical equivalences can be used as
inference rules.
( ) ( )
34
Example
Assume R1 through R5 on slide # 25.
38
Enumeration of Models
P: Set of propositional symbols in {KB,}
n: Size of P
ENTAILS(KB,)
For each of the 2n models on P do
If it is a model of {KB,} then
Return no
Return yes
39
Construction of a Proof
What do we need?
A complete set of sound inference
rules
A complete search algorithm to
decide which rule to apply next and
to which sentences
40
Complementary Literals
A literal is a either an atomic sentence
(positive literal) or the negated atomic
sentence (negative literal), e.g.:
P or P
41
Unit Resolution Rule
Given two sentences:
L1 … Lp and M
where L1,…, Lp and M are all literals,
and M and Li are complementary
literals
Infer: L1 … Li-1 Li+1 … Lp
This is expressed as :
42
Soundness of Unit Resolution
Let m be a model of:
L1 … Lp and M
where M and Li are complementary
literals
Li must be False in m, hence
L1 … Li-1 Li+1 … Lp
must be True
43
Shortcoming of Unit Resolution
From:
E F D
EG
we can infer nothing!
Infer:
L1 … Li-1Li+1…LpM1 … Mj-1
Mj+1…Mq
Example :
E F D
E G
Infer:
FDG 46
Not All Inferences are Useful!
From:
E F C
E F
Infer:
F F C True
tautology
47
Resolution
Uses CNF (Conjunctive normal form)
Conjunction of disjunctions of literals
(clauses)
The resolution rule is sound:
Only entailed sentences are derived
Resolution is complete in the sense that it
can always be used to either confirm or
refute a sentence (it can not be used to
enumerate true sentences.)
48
Resolution algorithm
First KB is converted into CNF
Then apply resolution rule to resulting
clauses.
The process continues until:
There are no new clauses that can be added
Hence KB does not entail
Two clauses resolve to entail the empty clause.
Hence KB entails
49
Conversion to CNF
Example: B11 (P12 v P21)
1. Eliminate , replacing with () ٨ ()
(B11 ((P12 v P21)) ٨((P12 v P21) B11))
2. Eliminate , replacing with ¬ v
(¬B11 v P12 v P21) ٨ (¬(P12 v P21) v B11))
3. Move in using deMorgan’s rules and double
negation
(¬B11 v P12 v P21) ٨ ( (¬P12 ٨ ¬P21) v B11))
4. Distribute over
(¬B11 v P12 v P21) ٨ (¬P12 v B11) ٨ (¬P21 v B11)
Set of clauses:
{(¬B11 v P12 v P21), (¬P12 v B11) ,(¬P21 v B11)} 50
Resolution example
KB = (B1,1 (P1,2 P2,1)) B1,1 = P1,2
51
Forward and backward chaining
52
Forward and backward chaining
Horn clause can be converted in following
way
(conjunction of negated symbols)
(positive symbol)
E.g. ( P R ) Q
55
Forward chaining algorithm
56
Forward chaining example
57
Forward chaining example
58
Forward chaining example
59
Forward chaining example
60
Forward chaining example
61
Forward chaining example
62
Forward chaining example
63
Forward chaining example
64
Backward chaining
Idea: work backward from the query q
to prove q using 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
subgoal
Has already been proved true, OR
Has already failed
65
Backward chaining example
66
Backward chaining example
67
Backward chaining example
68
Backward chaining example
69
Backward chaining example
70
Backward chaining example
71
Backward chaining example
72
Backward chaining example
73
Backward chaining example
74
Backward chaining example
75
Forward vs. backward chaining
FC is data-driven
Automatic, unconscious processing
May do lots of work that is irrelevant to the goal
77
The DPLL algorithm
Determine if an input propositional logic sentence
(in CNF) is satisfiable.
Improvements over truth table enumeration:
1. Early termination
A clause is true if any literal is true.
A sentence is false if any clause is false.
E.g., clause (ABC) is true whenever A=True
regardless of the value of B and C.
E.g., a sentence in CNF (P Q R). Here search
space can be pruned when P=False, or P=True,
Q=True. 78
The DPLL algorithm
2. Pure symbol heuristic
Pure symbol: always appears with the same "sign"
in all clauses. E.g., In the four clauses (A B),
(B C), (C D), (D A) A and B are pure, C
and D are impure.
Make a pure symbol literal true, because that
assignment would make more than one clauses to
be true.
Assigning truth value to a pure symbol might
make a previous impure symbol to pure. E.g., if
B is assigned True, first and second clauses
become True. So C becomes a pure symbol. 79
The DPLL algorithm
3. Unit clause heuristic
Unit clause: A clause in which all literals except
one are already assigned to ‘False’ or there is only
one literal in the clause.
The only literal in a unit clause must be true to
make the clause True. E.g., in (A D) if A is
assigned False, D must be assigned False.
Assigning one unit clause can create another unit
clause. It’s called Unit Propagation. E.g., after
assigning D=False, (C D) becomes a unit clause,
because to make it true C must be assigned True. 80
3-SAT Problem
86
Circuit Based Agent
A model based reflex agent where an agent keeps
track of internal states.
Circuit is composed of –
Gates: Each gate represents a logical connective.
Registers: Each register stores truth value of a
propositional symbol.
The inputs of the circuit are registers
corresponding to perceptions.
The outputs of the circuit are registers
corresponding to actions.
87
Example of circuit based agent
Alivet Screamt
Alivet-1
Initially, Alive set to true. 88
Tracking Location
For each square [x,y] register Lx,y should
be true if the agent is at [x,y] at a
particular time stamp.
E.g., agent is at [1,1] at time t which can
be expresses as:
89
Circuit for Tracking Location
90
Problem with circuit based agent
In case of Alivet or Lt1,1the circuit based
inference is correct, because we can initialize
the truth values when the game starts. Say, L1,1 =
True, other Lx,y = False
However the value of B4,4 (whether there is a
breeze at[4,4]) can’t be initialized until the agent
visits [4,4] or discover a pit at some adjacent
blocks.
Here three value needs to be stored: known true,
known false, unknown (initial value).
91
In the Circuit, use K(B4,4) where
needs B4,4 and use K(B4,4)
where needs B4,4.
Solution to this problem requires 2
K(B4,4) and K(B4,4) are called
registers to represent B4,4 namely
Knowledge K(B4,4)
Proposition.
and K(B4,4):
K(B4,4) K(B4,4) meaning
0 0 Unknown
0 1 Not Breezy
1 0 Breezy
1 1 Bug in the KB
92
Determining Truth value of
Knowledge Proposition
K(B4,4) starts out false and then becomes true as
soon as B4,4 can be determined to be true—that
is, when the agent is in [4,4] and detects a
breeze. It stays true thereafter.
93
Properties of circuit-based agent
design
Locality: An environment exhibits locality
if the truth of each proposition can be
determined looking only at constant
number of other propositions.
E.g., environment of Mine Sweeper game
is non-local.
94
Properties of circuit-based agent
design
Acyclicity: A circuit is acyclic if every
path that connects the output of a register
back to its input has an intervening delay
element. E.g.,
K(B4,4)t K(B4,4)t-1 (Lt4,4 Breezet)
K(P3,4)t K(P4,3)t
To determine K(P3,4)t or K(P4,3)t it needs to
determine the value of K(B4,4)t .So the
circuit contains a cycle.
95
Limitations of Circuit based agent
Accyclicity restriction attributes to the
incompleteness of circuit-based agent.
To avoid accyclicity the truth value of
K(P3,4)t and K(P4,3)t can’t be included in the
rule for determining truth value K(B4,4)t.
Which implies the agent can’t infer some
sentences which are logically entailed by the
knowledge base.
Accyclicity can be avoided by introducing
96
more hardware, but it becomes too complex.
Inference-based agent (IBA) VS
Circuit-based agent (CBA)
Conciseness:
CBA, unlike IBA, doesn’t need to have
separate copies of its knowledge for
every time step. It requires only
knowledge of only previous and current
time stamp.
However, both agents have to store the
knowledge for every square.
97
Inference-based agent (IBA) VS
Circuit-based agent (CBA)
Computational efficiency:
IBA can take time exponential in number of
symbols.
CBA takes time linear in the size of circuit.
Ease of construction:
IBA is much easier to construct.
Completeness:
CBA can be incomplete due to acyclicity
restriction.
98
99