Artificial Intelligence Chapter 7: Logical Agents
Artificial Intelligence Chapter 7: Logical Agents
• Procedural
– Encode desired behaviors directly as program
code
• Minimizing the role of explicit representation and
reasoning can result in a much more efficient
system
Wumpus World
• Performance Measure
– Gold +1000, Death – 1000
– Step -1, Use arrow -10
• Environment
– Square adjacent to the Wumpus are smelly
– Squares adjacent to the 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 the gold if in the same
square
– Releasing drops the gold in the same square
• Actuators
– Left turn, right turn, forward, grab, release,
shoot
• Sensors
– Breeze, glitter, and smell
• Modus Ponens
– Given: S1 S2 and S1, derive S2
• And-Elimination
– Given: S1 S2, derive S1
– Given: S1 S2, derive S2
• DeMorgan’s Law
– Given: ( A B) derive A B
– Given: ( A B) derive A B
Reasoning Patterns
• And Elimination • Modus Ponens
𝛼∧𝛽 𝛼 ⇒ 𝛽, 𝛼
𝛼 𝛽
• Inferences
S3: (B22 (P21 P23 P12 P32 ))
((P21 P23 P12 P32 ) B22) [S1,bi elim]
S4: ((P21 P23 P12 P32 ) B22) [S3, and elim]
S5: (B22 ( P21 P23 P12 P32 )) [contrapos]
S6: (P21 P23 P12 P32 ) [S2,S6, MP]
S7: P21 P23 P12 P32 [S6, DeMorg]
Evaluation of Deductive
Inference
• Sound
– Yes, because the inference rules themselves are
sound. (This can be proven using a truth table
argument).
• Complete
– If we allow all possible inference rules, we’re
searching in an infinite space, hence not complete
– If we limit inference rules, we run the risk of leaving
out the necessary one…
• Monotonic
– If we have a proof, adding information to the DB will
not invalidate the proof
Resolution
• Resolution allows a complete inference
mechanism (search-based) using only one rule
of inference
• Resolution rule:
– Given: P1 P2 P3 … Pn, and P1 Q1 … Qm
– Conclude: P2 P3 … Pn Q1 … Qm
Complementary literals P1 and P1 “cancel out”
• Why it works:
– Consider 2 cases: P1 is true, and P1 is false
Resolution in Wumpus World
• There is a pit at 2,1 or 2,3 or 1,2 or 3,2
– P21 P23 P12 P32
• There is no pit at 2,1
P21
• Therefore (by resolution) the pit must be at
2,3 or 1,2 or 3,2
– P23 P12 P32
Horn Clauses
• A Horn Clause is a CNF clause with exactly one positive
literal
– The positive literal is called the head
– The negative literals are called the body
– Prolog: head:- body1, body2, body3 …
– English: “To prove the head, prove body1, …”
– Implication: If (body1, body2 …) then head
• Horn Clauses form the basis of forward and backward
chaining
• The Prolog language is based on Horn Clauses
• Deciding entailment with Horn Clauses is linear in the
size of the knowledge base
Reasoning with Horn Clauses
• Forward Chaining
– For each new piece of data, generate all new
facts, until the desired fact is generated
– Data-directed reasoning
• Backward Chaining
– To prove the goal, find a clause that contains
the goal as its head, and prove the body
recursively
– (Backtrack when you chose the wrong clause)
– Goal-directed reasoning
Forward Chaining
• Fire any rule whose premises are satisfied in the KB
• Add its conclusion to the KB until the query is found
Forward Chaining
• AND-OR Graph
– multiple links joined by an arc indicate conjunction – every link must be proved
– multiple links without an arc indicate disjunction – any link can be proved
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Backward Chaining
• Idea: work backwards from the query q:
– To prove q by 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
Idea: fire any rule whose premises are satisfied in the KB,
– add its conclusion to the KB, until query is found
AND-OR graph
Forward Chaining vs. Backward
Chaining
• Forward Chaining is data driven
– Automatic, unconscious processing
– E.g. object recognition, routine decisions
– May do lots of work that is irrelevant to the goal
P P (P Q) Addition
PQ
PQ (P Q) P Simplification
P
P [(P) (Q)] (P Q) Conjunction
Q
PQ
Crown(C1) OnHead(C1,John)
»
–
»
Reduction contd.
• Every FOL KB can be propositionalized so as to
preserve entailment
Idea: For n = 0 to ∞ do
create a propositional KB by instantiating with depth-$n$ terms
see if α is entailed by this KB
• E.g., from:
x King(x) Greedy(x) Evil(x)
King(John)
y Greedy(y)
Brother(Richard,John)
θ = {x/John,y/John} works
• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane)
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
θ = {x/John,y/John} works
• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
θ = {x/John,y/John} works
• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
θ = {x/John,y/John} works
• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ)
θ = {x/John,y/John} works
• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ) {fail}
•
Efficiency of forward chaining
Incremental forward chaining: no need to match a rule on
iteration k if a premise wasn't added on iteration k-1
match each rule whose premise contains a newly added positive
literal
–
Hard matching example
Diff(wa,nt) Diff(wa,sa) Diff(nt,q)
Diff(nt,sa) Diff(q,nsw) Diff(q,sa)
Diff(nsw,v) Diff(nsw,sa) Diff(v,sa)
Colorable()