chapter 7.5{7 · 2005-09-29 · chapter 7.5{7.7 35. tracking changes in the world state estimation...

39
Propositional inference, propositional agents Chapter 7.5–7.7 Chapter 7.5–7.7 1

Upload: others

Post on 15-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Propositional inference, propositional agents

Chapter 7.5–7.7

Chapter 7.5–7.7 1

Page 2: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Outline

♦ Inference rules and theorem proving– forward chaining– backward chaining– resolution

♦ Efficient model checking algorithms

♦ Boolean circuit agents

Chapter 7.5–7.7 2

Page 3: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Proof methods

Proof methods divide into (roughly) two kinds:

Application of inference rules– Legitimate (sound) generation of new sentences from old– Proof = a sequence of inference rule applications

Can use inference rules as “actions” in a standard search alg.– Typically require translation of sentences into a normal form

Model checkingtruth table enumeration (always exponential in n)improved backtracking, e.g., Davis–Putnam–Logemann–Lovelandheuristic search in model space (sound but incomplete)

e.g., min-conflicts-like hill-climbing algorithms

Chapter 7.5–7.7 3

Page 4: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward and backward chaining

Horn Form (restricted)KB = conjunction of Horn clauses

Horn clause =♦ proposition symbol; or♦ (conjunction of symbols) ⇒ symbol

E.g., C ∧ (B ⇒ A) ∧ (C ∧D ⇒ B)

Modus Ponens (for Horn Form): complete for Horn KBs

α1, . . . , αn, α1 ∧ · · · ∧ αn ⇒ β

β

Can be used with forward chaining or backward chaining.These algorithms are very natural and run in linear time

Chapter 7.5–7.7 4

Page 5: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining

Idea: fire any rule whose premises are satisfied in the KB,add its conclusion to the KB, until query is found

P ⇒ Q

L ∧M ⇒ P

B ∧ L ⇒ M

A ∧ P ⇒ L

A ∧B ⇒ L

A

B

Q

P

M

L

BA

Chapter 7.5–7.7 5

Page 6: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining algorithm

function PL-FC-Entails?(KB, q) returns true or false

inputs: KB, the knowledge base, a set of propositional Horn clauses

q, the query, a proposition symbol

local variables: count, a table, indexed by clause, initially the number of premises

inferred, a table, indexed by symbol, each entry initially false

agenda, a list of symbols, initially the symbols known in KB

while agenda is not empty do

p←Pop(agenda)

unless inferred[p] do

inferred[p]← true

for each Horn clause c in whose premise p appears do

decrement count[c]

if count[c] = 0 then do

if Head[c] = q then return true

Push(Head[c],agenda)

return false

Chapter 7.5–7.7 6

Page 7: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

P

M

L

BA

2 2

2

2

1

Chapter 7.5–7.7 7

Page 8: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

P

M

L

B

2

1

A

1 1

2

Chapter 7.5–7.7 8

Page 9: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

P

M

2

1

A

1

B

0

1L

Chapter 7.5–7.7 9

Page 10: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

P

M

1

A

1

B

0

L0

1

Chapter 7.5–7.7 10

Page 11: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

1

A

1

B

0

L0

M

0

P

Chapter 7.5–7.7 11

Page 12: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

A B

0

L0

M

0

P

0

0

Chapter 7.5–7.7 12

Page 13: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

Q

A B

0

L0

M

0

P

0

0

Chapter 7.5–7.7 13

Page 14: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward chaining example

A B

0

L0

M

0

P

0

0

Q

Chapter 7.5–7.7 14

Page 15: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Proof of completeness

FC derives every atomic sentence that is entailed by KB

1. FC reaches a fixed point where no new atomic sentences are derived

2. Consider the final state as a model m, assigning true/false to symbols

3. Every clause in the original KB is true in m

Proof: Suppose a clause a1 ∧ . . . ∧ ak ⇒ b is false in m

Then a1 ∧ . . . ∧ ak is true in m and b is false in m

Therefore the algorithm has not reached a fixed point!

4. Hence m is a model of KB

5. If KB |= q, q is true in every model of KB, including m

General idea: construct any model of KB by sound inference, check α

Chapter 7.5–7.7 15

Page 16: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining

Idea: work backwards from the query q:to prove q by BC,

check if q is known already, orprove 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 subgoal1) has already been proved true, or2) has already failed

Chapter 7.5–7.7 16

Page 17: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

Q

P

M

L

A B

Chapter 7.5–7.7 17

Page 18: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

P

M

L

A

Q

B

Chapter 7.5–7.7 18

Page 19: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

M

L

A

Q

P

B

Chapter 7.5–7.7 19

Page 20: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

M

A

Q

P

L

B

Chapter 7.5–7.7 20

Page 21: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

M

L

A

Q

P

B

Chapter 7.5–7.7 21

Page 22: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

M

A

Q

P

L

B

Chapter 7.5–7.7 22

Page 23: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

M

A

Q

P

L

B

Chapter 7.5–7.7 23

Page 24: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

A

Q

P

L

B

M

Chapter 7.5–7.7 24

Page 25: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

A

Q

P

L

B

M

Chapter 7.5–7.7 25

Page 26: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

A

Q

P

L

B

M

Chapter 7.5–7.7 26

Page 27: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Backward chaining example

A

Q

P

L

B

M

Chapter 7.5–7.7 27

Page 28: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Forward vs. backward chaining

FC is data-driven, cf. automatic, unconscious processing,e.g., object recognition, routine decisions

May do lots of work that is irrelevant to the goal

BC is goal-driven, appropriate for problem-solving,e.g., Where are my keys? How do I get into a PhD program?

Complexity of BC can be much less than linear in size of KB

Chapter 7.5–7.7 28

Page 29: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Resolution

Conjunctive Normal Form (CNF—universal)conjunction of disjunctions of literals

︸ ︷︷ ︸

clauses

E.g., (A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)

Resolution inference rule (for CNF):

`1 ∨ · · · ∨ `k, m1 ∨ · · · ∨mn

`1 ∨ · · · ∨ `i−1 ∨ `i+1 ∨ · · · ∨ `k ∨m1 ∨ · · · ∨mj−1 ∨mj+1 ∨ · · · ∨mn

where `i and mj are complementary literals. E.g.,

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

P1,3 ∨ P2,2, ¬P2,2

P1,3

Resolution is sound and complete for propositional logic

Chapter 7.5–7.7 29

Page 30: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Conversion to CNF

B1,1⇔ (P1,2 ∨ P2,1)

1. Eliminate ⇔, replacing α⇔ β with (α ⇒ β) ∧ (β ⇒ α).

(B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1)

2. Eliminate ⇒, replacing α⇒ β with ¬α ∨ β.

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬(P1,2 ∨ P2,1) ∨B1,1)

3. Move ¬ inwards using de Morgan’s rules and double-negation:

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ ((¬P1,2 ∧ ¬P2,1) ∨B1,1)

4. Apply distributivity law (∨ over ∧) and flatten:

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬P1,2 ∨B1,1) ∧ (¬P2,1 ∨B1,1)

Chapter 7.5–7.7 30

Page 31: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Resolution algorithm

Proof by contradiction, i.e., show KB ∧ ¬α unsatisfiable

function PL-Resolution(KB,α) returns true or false

inputs: KB, the knowledge base, a sentence in propositional logic

α, the query, a sentence in propositional logic

clauses← the set of clauses in the CNF representation of KB ∧ ¬α

new←{}

loop do

for each Ci, Cj in clauses do

resolvents←PL-Resolve(Ci,Cj)

if resolvents contains the empty clause then return true

new← new ∪ resolvents

if new ⊆ clauses then return false

clauses← clauses ∪new

Chapter 7.5–7.7 31

Page 32: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Resolution example

KB = (B1,1 ⇔ (P1,2 ∨ P2,1)) ∧ ¬B1,1 α = ¬P1,2

P1,2

P1,2

P2,1

P1,2 B1,1

B1,1 P2,1 B1,1 P1,2 P2,1 P2,1P1,2B1,1 B1,1

P1,2B1,1 P2,1B1,1P2,1 B1,1

P1,2 P2,1 P1,2

Chapter 7.5–7.7 32

Page 33: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

DPLL: backtracking++

Backtracking applied to SAT problems:– variables are proposition symbols, clauses are constraints

Several key improvements:

1. Early termination: stop if all clauses true or any clause falsee.g., {A = true} satisfies (A ∨B) ∧ (A ∨ C)

2. Pure symbols: symbol has same sign in all as-yet-unsatisfied clausese.g., A and B are pure in (A ∨ ¬B) ∧ (¬B ∨ ¬C) ∧ (C ∨ A)⇒ assign symbol to make literals true

3. Unit clauses: clause has exactly one as-yet-unfalsified literale.g., if {A = true} already, (¬A ∨ ¬B) is a unit clause⇒ assign symbol to make clause true (cf. forward chaining, MRV)

Chapter 7.5–7.7 33

Page 34: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

DPLL algorithm

function DPLL(clauses, symbols,model) returns true or false

if every clause in clauses is true in model then return true

if some clause in clauses is false in model then return true

P, value←Find-Pure-Symbol(symbols, clauses,model)

if P is non-null then return DPLL(clauses, symbols–P, [P = value|model ])

P, value←Find-Unit-Clause(clauses,model)

if P is non-null then return DPLL(clauses, symbols–P, [P = value|model ])

P←First(symbols); rest←Rest(symbols)

return DPLL(clauses, rest, [P = true|model ]) or

DPLL(clauses, rest, [P = false|model ])

Highly optimized implementation + caching unsolvable subassignments⇒ modern solvers handle tens of millions of clauses⇒ practical for large hardware and medium software verification

Chapter 7.5–7.7 34

Page 35: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Propositions and time

Suppose the wumpus-world agent wants to keep track of its location

A sentence such as L1,1 ∧ FacingRight ∧ Forward ⇒ L2,1

doesn’t work: after one inference step, L1,1 and L2,1 are in KB!!

Changeable aspects of world need separate symbols for each time stepe.g., L1

1,1 means “Agent is at [1,1] at time step 1”, and

L1

1,1 ∧ FacingRight 1 ∧ Forward 1 ⇒ L2

2,1

Reflex rules: for every t, we have, e.g., Glittert ⇒ Grabt

Need copies of all axioms involving temporal symbolsfor every time step (might be infinitely many!)

Chapter 7.5–7.7 35

Page 36: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Tracking changes in the world

State estimation is the general task of keeping track of environment stategiven a stream of percepts

For logic-based systems: maintain a representation of the set of all logicallypossible world states, given axioms and percepts

Basic trick: successor-state axioms define truth of proposition at t+1 frompropositions at t

E.g., Alive t ⇔ ¬Scream t ∧ Alive t−1

Lt1,1 ⇔ (Lt−1

1,1 ∧ (¬Forward t−1 ∨ Bumpt))

∨(Lt−11,2 ∧ (FacingDown t−1 ∧ Forward t−1))

∨(Lt−12,1 ∧ (FacingLeft t−1 ∧ Forward t−1))

Chapter 7.5–7.7 36

Page 37: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Boolean circuit agents

Alive

Stench

Scream

Forward

Bump

Glitter

Breeze

Shoot

Grab

TurnRight

TurnLeft

∧ ¬

Chapter 7.5–7.7 37

Page 38: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Boolean circuit agents contd.

FacingLeft

L2,1

FacingDown∧

¬

Forward

Shoot

Grab

TurnRight

TurnLeft Stench

Scream

Bump

Glitter

Breeze

L1,2

∧ ∨ L1,1

Chapter 7.5–7.7 38

Page 39: Chapter 7.5{7 · 2005-09-29 · Chapter 7.5{7.7 35. Tracking changes in the world State estimation is the general task of keeping track of environment state given a stream of percepts

Summary

Inference methods work by theorem proving or model checking

Forward, backward chaining are linear-time, complete for Horn clauses

Resolution is complete for propositional logic

DPLL is an efficient, complete model checker;WalkSAT is incomplete but often very fast in practice

Circuit-based agents provide a simple way to handle timebut are usually less complete than inference-based agents

Chapter 7.5–7.7 39