Logical Agents CE417: Introduction to Artificial Intelligence - - PowerPoint PPT Presentation

logical agents
SMART_READER_LITE
LIVE PREVIEW

Logical Agents CE417: Introduction to Artificial Intelligence - - PowerPoint PPT Presentation

Logical Agents CE417: Introduction to Artificial Intelligence Sharif University of Technology Spring 2018 Soleymani Artificial Intelligence: A Modern Approach , 3 rd Edition, Chapter 7 Wumpus world Wumpus Pitts Gold Wumpus


slide-1
SLIDE 1

Logical Agents

CE417: Introduction to Artificial Intelligence Sharif University of Technology Spring 2018

“Artificial Intelligence: A Modern Approach”, 3rd Edition, Chapter 7

Soleymani

slide-2
SLIDE 2

Wumpus world

2

Wumpus

 Wumpus  Pitts  Gold  Agent

slide-3
SLIDE 3

Wumpus world PEAS description

 Performance measure

 +1000 for garbing gold  -1000 for death  -1 for each action  -10 for using up the arrow  Game ends when the agent dies or climbs out of the cave

 Environment

 4×4 grid  Agent starts in [1,1] while facing to the right  Gold and wumpus are located randomly in the squares except to [1,1]  Each square other than [1,1] can be a pit with probability 0.2

3

slide-4
SLIDE 4

Wumpus world PEAS description

4

 Sensors: Stench, Breeze, Glitter, Bump, Scream

 In the squares adjacent to wumpus, agent perceives a Stench  It the squares adjacent to a pit, agent perceives a Breeze  In the gold square, agent perceives a Glitter  When walking into a wall, agent perceives a Bump  When Wumpus is killed, agent perceives a Scream

 Actuators: Forward, TurnLeft, TurnRight, Shoot, Grab, Climb

 Forward,TurnLeft,TurnRight: moving and rotating face actions.

 Moving to a square containing a pit or a live wumpus causes death.  If an agent tries to move forward and bumps into a wall then it does not move.

 Shoot: to fire an arrow in a straight line in the facing direction of the agent

 Shooting kills wumpus if the agent is facing it (o.w. the arrow hits a wall)

The first shoot action has any effect (the agent has only one arrow)

 Grab: to pick up the gold if it is in the same square as the agent.  Climb: climb out of the cave but only from [1,1]

slide-5
SLIDE 5

Wumpus world characterization

 Fully Observable? No – many aspects are not directly

perceivable

 Episodic? No – sequential at the level of actions  Static? Yes  Discrete?Yes  Single-agent?Yes

5

slide-6
SLIDE 6

Wumpus world example

A: agent OK: safe square

6

slide-7
SLIDE 7

Wumpus world example

A: agent OK: safe square A: agent OK: safe square B: Breeze

7

slide-8
SLIDE 8

Wumpus world example

A: agent OK: safe square B: Breeze P: Pit

8

slide-9
SLIDE 9

Wumpus world example

A: agent OK: safe square B: Breeze P: Pit S: Stench

9

slide-10
SLIDE 10

Wumpus world example

A: agent OK: safe square B: Breeze P: Pit S: Stench

10

slide-11
SLIDE 11

Wumpus world example

A: agent OK: safe square B: Breeze P: Pit S: Stench

11

slide-12
SLIDE 12

Wumpus world example

A: agent OK: safe square B: Breeze P: Pit S: Stench

12

slide-13
SLIDE 13

Wumpus world example

A: agent OK: safe square B: Breeze P: Pit S: Stench

13

slide-14
SLIDE 14

Logic & Language

 Logic includes formal languages for representing information

such that conclusions can be drawn

 Syntax defines the well-formed sentences in a language  Semantics define the "meaning" of sentences

 i.e., define truth of a sentence with respect to each possible world

 We will introduce Propositional Logic in this lecture

 It talks about facts  Propositions can be true, false, or unknown

14

slide-15
SLIDE 15

Propositional logic: Syntax

 Propositional logic is the simplest logic

 To illustrate basic ideas about logic & reasoning

 The proposition symbols 𝑄, 𝑅, … are sentences.  If 𝑄 is a sentence, 𝑄 is a sentence (negation)  If 𝑄 and 𝑅 are sentences, 𝑄𝑅 is a sentence (conjunction)  If 𝑄 and 𝑅 are sentences, 𝑄𝑅 is a sentence (disjunction)  If 𝑄 and 𝑅 are sentences, 𝑄 𝑅 is a sentence (implication)  If 𝑄 and 𝑅 are sentences, 𝑄 𝑅 is a sentence (biconditional)

15

slide-16
SLIDE 16

Propositional logic (Grammar)

16

𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 → 𝐵𝑢𝑝𝑛𝑗𝑑𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 | 𝐷𝑝𝑛𝑞𝑚𝑓𝑦𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 𝐵𝑢𝑝𝑛𝑗𝑑𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 → 𝑈𝑠𝑣𝑓 𝐺𝑏𝑚𝑡𝑓 𝑄 𝑅 𝑆 | … 𝐷𝑝𝑛𝑞𝑚𝑓𝑦𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 → (𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓) | ¬𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 | 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 ∧ 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 | 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 ∨ 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 | 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 ⟹ 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 | 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 ⇔ 𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 𝑄𝑠𝑓𝑑𝑓𝑒𝑓𝑜𝑑𝑓: ¬, ∧, ∨, ⟹, ⇔

slide-17
SLIDE 17

Truth tables for connectives

17

slide-18
SLIDE 18

Propositional logic: Semantics

18

 Each model specifies true/false of each proposition symbol  e.g., Propistion symbols: 𝑄

1,2, 𝑄2,2, 𝑄3,1

 8 possible models

 𝑛1 = {𝑄 1,2 = 𝑔𝑏𝑚𝑡𝑓, 𝑄2,2 = 𝑔𝑏𝑚𝑡𝑓, 𝑄3,1 = 𝑢𝑠𝑣𝑓}

 Semantics of a complex sentence in any model m:

  • 𝑄 is true iff 𝑄 is false in 𝑛.

𝑄𝑅 is true iff 𝑄 is true and 𝑅 is true in 𝑛.

𝑄 ∨ 𝑅 is true iff 𝑄 is true or 𝑅 is true in 𝑛.

𝑄 ⟹ 𝑅 is true unless 𝑄 is true and 𝑅 is false in 𝑛.

𝑄 ⟺ 𝑅 is true iff 𝑄 and 𝑅 are both true or both false in 𝑛.

slide-19
SLIDE 19

Wumpus world sentences

 𝑄𝑗,𝑘 is true if there is a pit in [𝑗, 𝑘].  𝑋

𝑗,𝑘 is true if there is a wumpus in [𝑗, 𝑘], dead or alive.

 𝐶𝑗,𝑘 is true if the agent perceives a breeze in [𝑗, 𝑘].  𝑇𝑗,𝑘 is true if the agent perceives a stench in [𝑗, 𝑘].  General rules (only related ones to the current agent position)

 𝑆1:  𝑄

1,1

(no pit in [1,1])

 𝑆2: 𝐶1,1 ⇔ 𝑄

1,2 ∨ 𝑄2,1

(Pits cause breezes in adjacent squares)

 𝑆3: 𝐶2,1 ⇔ 𝑄

1,1 ∨ 𝑄2,2 ∨ 𝑄3,1

(Pits cause breezes in adjacent squares)

 Perception

 𝑆4:  𝐶1,1  𝑆5: 𝐶2,1

19

slide-20
SLIDE 20

Models

 Models are mathematical abstraction of possible worlds  For each logical sentence, we can consider a set that specifies

all possible worlds in which 𝛽 is true

 𝑁(𝛽): set of all models of the sentence 𝛽 (all satisfying 𝛽)

 𝑛 ∈ 𝑁(𝛽) if 𝛽 is true in model 𝑛

20

slide-21
SLIDE 21

Wumpus models

21

 Agents starts at [1,1] with no active sensor, then

moves to [2,1] and senses Breeze in it

 Possible models for pits in [1,2], [2,2], [3,1] after

visiting these two locations:

slide-22
SLIDE 22

Logical reasoning: entailment

22

 𝛽 ⊨ 𝛾 (entailment): 𝛽 entails 𝛾

 𝛽 ⇒ 𝛾 is a tautology or valid

 A sentence is valid or tautology if it is T𝑠𝑣𝑓 in all models (e.g.,

𝑄𝑄, (𝑄(𝑄𝑅))𝑅)  𝛾 logically follows from 𝛽 or 𝛽 is stronger than 𝛾

 𝛽 ⊨ 𝛾 iff 𝑁 𝛽  𝑁 𝛾

 𝛽 entails 𝛾 iff 𝛾 is true in all worlds where 𝛽 is true

slide-23
SLIDE 23

Entailment

 𝐿𝐶 ⊨ 𝛽

iff 𝑁(𝐿𝐶) ⊆ 𝑁(𝛽)

 Example:

 KB=“A is red” & “B is blue”  α = “A is red”

23

slide-24
SLIDE 24

Entailment in the wumpus world

 𝐿𝐶

(before perception): rules of the wumpus world

 Perception: After detecting nothing in

[1,1], moving right, a breeze in [1,2]

24

slide-25
SLIDE 25

Wumpus models

25

 Possible models for pits in [1,2], [2,2], [3,1] Consider possible models for only pits in neighboring squares 23 = 8 possible models

slide-26
SLIDE 26

Wumpus models

 𝐿𝐶 = wumpus-world rules + perceptions

26

slide-27
SLIDE 27

Wumpus models

 𝐿𝐶 = wumpus-world rules + perceptions  𝛽1 = "[1,2] is safe"

 𝑁(𝐿𝐶) ⊆ 𝑁(𝛽1) ⇒ 𝐿𝐶 ⊨ 𝛽1

27

slide-28
SLIDE 28

Wumpus models

 KB = wumpus-world rules + perceptions

28

slide-29
SLIDE 29

Wumpus models

 𝐿𝐶 = wumpus-world rules + perceptions  𝛽2 = "[2,2] is safe", 𝐿𝐶 ⊭ 𝛽2

29

slide-30
SLIDE 30

Inference

 𝐿𝐶├𝑗 𝛽: 𝛽 can be derived from 𝐿𝐶 by an inference algorithm 𝑗  An inference algorithm 𝑗 is:

 sound if whenever 𝐿𝐶├𝑗 𝛽, it is also true that 𝐿𝐶 ⊨ 𝛽

 all provable statements by this algorithm are true

 complete if whenever 𝐿𝐶 ⊨ 𝛽, it is also true that 𝐿𝐶├𝑗 𝛽

 all true statements are provable by this algorithm 30

slide-31
SLIDE 31

Inference methods

 Inference methods can be categorized into:

 Model checking (enumerating models)

 truth table enumeration (always exponential in 𝑜)  improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL)  heuristic search in model space (sound but incomplete)

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

 Theorem proving (searching proofs by applying inference rules)

 Applying a sequence of inference rules on KB to find the desired sentence  Legitimate (sound) generation of new sentences from old ones. 31

slide-32
SLIDE 32

Truth tables for inference

32

 𝐿𝐶 ⊨ 𝛽?

Enumerate the models

“Is 𝛽 true in every model in which KB is true?”

𝑆1:  𝑄

1,1

𝑆2: 𝐶1,1 ⇔ 𝑄

1,2 ∨ 𝑄2,1

𝑆3: 𝐶2,1 ⇔ 𝑄

1,1 ∨ 𝑄2,2 ∨ 𝑄3,1

𝑆4:  𝐶1,1 𝑆5: 𝐶2,1 KB

slide-33
SLIDE 33

Entailment by enumeration (model checking)

33

function 𝑈𝑈_𝐹𝑂𝑈𝐵𝐽𝑀𝑇? (𝐿𝐶, 𝛽) returns 𝑢𝑠𝑣𝑓 or 𝑔𝑏𝑚𝑡𝑓 inputs: 𝐿𝐶, the knowledge base, a sentence in propositional logic 𝛽, the query, a sentence in propositional logic 𝑡𝑧𝑛𝑐𝑝𝑚𝑡 ← a list of the proposition symbols in 𝐿𝐶 and 𝛽 return 𝑈𝑈_𝐷𝐼𝐹𝐷𝐿_𝐵𝑀𝑀(𝐿𝐶, 𝛽 , 𝑡𝑧𝑛𝑐𝑝𝑚𝑡, {}) function 𝑈𝑈_𝐷𝐼𝐹𝐷𝐿_𝐵𝑀𝑀(𝐿𝐶, 𝛽, 𝑡𝑧𝑛𝑐𝑝𝑚𝑡, 𝑛𝑝𝑒𝑓𝑚) returns 𝑢𝑠𝑣𝑓 or 𝑔𝑏𝑚𝑡𝑓 if 𝐹𝑁𝑄𝑈𝑍? ( 𝑡𝑧𝑛𝑐𝑝𝑚𝑡) then if 𝑄𝑀_𝑈𝑆𝑉𝐹? (𝐿𝐶, 𝑛𝑝𝑒𝑓𝑚) then return 𝑄𝑀_𝑈𝑆𝑉𝐹? (𝛽, 𝑛𝑝𝑒𝑓𝑚) else return 𝑢𝑠𝑣𝑓 else 𝑄 ← 𝐺𝐽𝑆𝑇𝑈(𝑡𝑧𝑛𝑐𝑝𝑚𝑡) 𝑠𝑓𝑡𝑢 ← 𝑆𝐹𝑇𝑈(𝑡𝑧𝑛𝑐𝑝𝑚𝑡) return 𝑈𝑈_𝐷𝐼𝐹𝐷𝐿_𝐵𝑀𝑀(𝐿𝐶, 𝛽, 𝑠𝑓𝑡𝑢, 𝑛𝑝𝑒𝑓𝑚⋃{𝑄 = 𝑢𝑠𝑣𝑓}) and 𝑈𝑈_𝐷𝐼𝐹𝐷𝐿_𝐵𝑀𝑀(𝐿𝐶, 𝛽, 𝑠𝑓𝑡𝑢, 𝑛𝑝𝑒𝑓𝑚⋃{𝑄 = 𝑔𝑏𝑚𝑡𝑓})

slide-34
SLIDE 34

Entailment by enumeration: properties

34

 Depth-first enumeration of all models is sound and complete

(when finite models).

 For 𝑜 symbols, time complexity is 𝑃(2𝑜), space complexity is

𝑃(𝑜).

slide-35
SLIDE 35

Satisfiability

35

 A sentence is satisfiable if it is true in some models

 e.g., 𝑄𝑅

 Determining the satisfiability of sentences in propositional

logic (SAT problem) is NP-complete

 Satisfiability and validity are connected.

 𝛽 is valid or tautology iff ¬𝛽 is unsatisfiable.  𝛽 is satisfiable iff ¬𝛽 is not valid.

𝛽 ⊨ 𝛾 iff (𝛽 ∧ ¬𝛾) is unsatisfiable

Proof by contradiction

slide-36
SLIDE 36

The DPLL (Davis, Putnam, Logemann, Loveland) algorithm

36

 Improvements over truth table enumeration (simple DFS):

 Early termination

 A clause is true if any literal is true.  A sentence is false if any clause is false.

 Pure symbol heuristic

 Pure symbol: always appears with the same "sign" in all clauses.

 e.g., In (𝐵𝐶) ∧ (¬𝐶 𝐷) ∧ (𝐷𝐵), 𝐵 and 𝐶 are pure, 𝐷 is impure.

 Make a pure symbol literal true.  In determining purity, we can ignore clauses already known to be true

 Unit clause heuristic

Unit clause: all literals except to one already assigned false by model.

 The only literal in a unit clause will be assigned true.

 Many tricks can be used to enable SAT solvers to scale up.

slide-37
SLIDE 37

The DPLL algorithm

37

Determining satisfiability of an input propositional logic sentence (in CNF)

slide-38
SLIDE 38

Entailment by using inference rule

38

 Propositional theorem proving  Searching proofs can be more efficient than model

checking.

 Can ignore irrelevant propositions.  When the number of models is large but the length of proof is

short, entailment by theorem proving is useful.

slide-39
SLIDE 39

Inference rules

39

 Some samples:

 Modus Ponens: α⇒β, α

β

 And elimination: 𝛽∧𝛾

𝛾

 Biconditional elimination:

𝛽⇔𝛾 (𝛽⇒𝛾)∧(𝛾⇒𝛽)

slide-40
SLIDE 40

Valid implication

40

 Deduction theorem: 𝛽 ⊨ 𝛾 iff 𝛽 ⇒ 𝛾 is valid.

 Every valid implication describes a legitimate inference.

 Modus Ponens: α⇒β, α

β

is equivalent to valid implication

α ⇒ β ∧ α ⇒ β is valid

 All logical entailments can be used as inference rules.

slide-41
SLIDE 41

Logical equivalence

 Using logical equivalence we can find many inference rules  Two sentences are logically equivalent iff they are true in the

same models 𝛽 ≡ 𝛾 iff 𝛽 ⊨ 𝛾 and 𝛾 ⊨ 𝛽

41

slide-42
SLIDE 42

Example of inference

42

 𝑆1:  𝑄

1,1

 𝑆2: 𝐶1,1 ⇔ 𝑄

1,2 ∨ 𝑄2,1

 𝑆3: 𝐶2,1 ⇔ 𝑄

1,1 ∨ 𝑄2,2 ∨ 𝑄3,1

 𝑆4:  𝐶1,1  𝑆5: 𝐶2,1

 Can we infer from 𝑆1 through 𝑆5 to prove  𝑄

1,2?

 𝑆6: 𝐶1,1 ⇒ 𝑄

1,2 ∨ 𝑄2,1

∧ 𝑄

1,2 ∨ 𝑄2,1 ⇒ 𝐶1,1

[biconditional elim. to 𝑆2]

 𝑆7:

𝑄

1,2 ∨ 𝑄2,1 ⇒ 𝐶1,1

[and elim. to 𝑆6]

 𝑆8: ¬𝐶1,1 ⇒ ¬ 𝑄

1,2 ∨ 𝑄2,1

[(𝑄 ⇒ 𝑅) ≡ (¬𝑅 ⇒ ¬𝑄)]

 𝑆9: ¬ 𝑄

1,2 ∨ 𝑄2,1

[Modus Ponens with 𝑆8 and 𝑆4]

 𝑆10: ¬𝑄

1,2 ∧ ¬𝑄2,1

[De Morgan’ rule]

slide-43
SLIDE 43

Finding a proof as a search problem

43

 𝐽𝑂𝐽𝑈𝐽𝐵𝑀_𝑇𝑈𝐵𝑈𝐹: the initial knowledge base  𝐵𝐷𝑈𝐽𝑃𝑂𝑇: all inference rules applied to all the sentences

that match their top line

 𝑆𝐹𝑇𝑉𝑀𝑈: add the sentence in the bottom line of the used

inference rule to the current ones

 𝐻𝑃𝐵𝑀: a state containing the sentence we are trying to

prove.

slide-44
SLIDE 44

Monotonicity property

44

 The

set

  • f

entailed sentences can

  • nly

grow as information is added to 𝐿𝐶.

 Inference rules can be applied where premises are found in KB

(regardless of what else is in KB)

 If 𝐿𝐶 ⊨ 𝛽 then 𝐿𝐶 ∧ 𝛾 ⊨ 𝛽

(for any 𝛽 and 𝛾)

 The assertion 𝛾 can not invalidate any conclusion 𝛽 already

inferred.

slide-45
SLIDE 45

Resolution

45

 Inference rules are sound.  Is a set of rules complete?

 Are the available inference rules adequate?

 Resolution: a single inference rule that yields a complete

inference algorithm (when couples with any complete search algorithm).

slide-46
SLIDE 46

Resolution

46

 Unit resolution: 𝑚𝑗 and 𝑛 are complementary literals

𝑚1 ∨ 𝑚2 ∨ ⋯ ∨ 𝑚𝑙, 𝑛 𝑚1 ∨ … ∨ 𝑚𝑗−1 ∨ 𝑚𝑗+1 ∨ ⋯ ∨ 𝑚𝑙

 Full resolution rule: 𝑚𝑗 and 𝑛𝑘 are complementary literals

𝑚1 ∨ 𝑚2 ∨ ⋯ ∨ 𝑚𝑙, 𝑛1∨ 𝑛2 ∨ ⋯ ∨ 𝑛𝑜 𝑚1 ∨ … ∨ 𝑚𝑗−1 ∨ 𝑚𝑗+1 ∨ ⋯ ∨ 𝑚𝑙 ∨ 𝑛1 ∨ … ∨ 𝑛𝑘−1 ∨ 𝑛𝑘+1 ∨ ⋯ ∨ 𝑛𝑜

 It resolution rule sound.Why?  A resolution-based theorem prover can (for any sentences 𝛽 and 𝛾 in

propositional logic) decide whether 𝛽 ⊨ 𝛾

 Is 𝛽 ∧ ¬𝛾 unsatisfiable?  CNF (Conjunctive Normal Form)

slide-47
SLIDE 47

CNF Grammar

47

𝐷𝑂𝐺𝑇𝑓𝑜𝑢𝑓𝑜𝑑𝑓 → 𝐷𝑚𝑏𝑣𝑡𝑓1 ∧ ⋯ ∧ 𝐷𝑚𝑏𝑣𝑡𝑓𝑜 𝐷𝑚𝑏𝑣𝑡𝑓 → 𝑀𝑗𝑢𝑓𝑠𝑏𝑚1 ∨ ⋯ ∨ 𝑀𝑗𝑢𝑓𝑠𝑏𝑚𝑛 𝑀𝑗𝑢𝑓𝑠𝑏𝑚 → 𝑇𝑧𝑛𝑐𝑝𝑚 | ¬𝑇𝑧𝑛𝑐𝑝𝑚 𝑇𝑧𝑛𝑐𝑝𝑚 → 𝑄 𝑅 𝑆 | …

slide-48
SLIDE 48

Example of resolution

48

𝑄

1,1 ∨ 𝑄3,1,

¬𝑄

1,1∨ ¬𝑄2,2

𝑄3,1 ∨ ¬𝑄2,2

slide-49
SLIDE 49

Resolution algorithm

 To show 𝐿𝐶 ⊨ 𝛽, we show 𝐿𝐶 ∧ ¬𝛽 is unsatisfiable

49

function PL-RESOLUTION(KB,α) returns 𝑢𝑠𝑣𝑓 or 𝑔𝑏𝑚𝑡𝑓 input: 𝐿𝐶, the knowledge base (a sentence in propositional logic) 𝛽, the query (a sentence in propositional logic) 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 ← the set of clauses in the CNF representation of 𝐿𝐶¬𝛽 𝑜𝑓𝑥 ← {} loop do for each pair of clauses 𝐷𝑗, 𝐷

𝑘 in 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 do

𝑠𝑓𝑡𝑝𝑚𝑤𝑓𝑜𝑢𝑡 ← 𝑄𝑀_𝑆𝐹𝑇𝑃𝑀𝑊𝐹 (𝐷𝑗, 𝐷𝑘) if 𝑠𝑓𝑡𝑝𝑚𝑤𝑓𝑜𝑢𝑡 contains the empty clause then return 𝑢𝑠𝑣𝑓 𝑜𝑓𝑥 ← 𝑜𝑓𝑥 ∪ 𝑠𝑓𝑡𝑝𝑚𝑤𝑓𝑜𝑢𝑡 if 𝑜𝑓𝑥 ⊆ 𝐷𝑚𝑏𝑣𝑡𝑓𝑡 then return 𝑔𝑏𝑚𝑡𝑓 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 ← 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 ∪ 𝑜𝑓𝑥

slide-50
SLIDE 50

Resolution algorithm

 To show 𝐿𝐶 ⊨ 𝛽, we show 𝐿𝐶 ∧ ¬𝛽 is unsatisfiable

50

function PL-RESOLUTION(KB,α) returns 𝑢𝑠𝑣𝑓 or 𝑔𝑏𝑚𝑡𝑓 input: 𝐿𝐶, the knowledge base (a sentence in propositional logic) 𝛽, the query (a sentence in propositional logic) 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 ← the set of clauses in the CNF representation of 𝐿𝐶¬𝛽 𝑜𝑓𝑥 ← {} loop do for each pair of clauses 𝐷𝑗, 𝐷

𝑘 in 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 do

𝑠𝑓𝑡𝑝𝑚𝑤𝑓𝑜𝑢𝑡 ← 𝑄𝑀_𝑆𝐹𝑇𝑃𝑀𝑊𝐹 (𝐷𝑗, 𝐷𝑘) if 𝑠𝑓𝑡𝑝𝑚𝑤𝑓𝑜𝑢𝑡 contains the empty clause then return 𝑢𝑠𝑣𝑓 𝑜𝑓𝑥 ← 𝑜𝑓𝑥 ∪ 𝑠𝑓𝑡𝑝𝑚𝑤𝑓𝑜𝑢𝑡 if 𝑜𝑓𝑥 ⊆ 𝐷𝑚𝑏𝑣𝑡𝑓𝑡 then return 𝑔𝑏𝑚𝑡𝑓 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 ← 𝑑𝑚𝑏𝑣𝑡𝑓𝑡 ∪ 𝑜𝑓𝑥 Each pair containing complementary literals is resolved and the resulted clause is added to the set if it is not already present. The process continues until one of these happens:

  • No new clauses (𝐿𝐶 ⊭ 𝛽)
  • Two clauses resolve to yield the empty clause (𝐿𝐶 ⊨ 𝛽)

Sound and complete inference algorithm

slide-51
SLIDE 51

Resolution example

𝐿𝐶 = 𝐶1,1  𝑄

1,2 𝑄2,1

𝐶1,1 𝛽 = ¬𝑄

1,2

 Convert 𝐿𝐶 ∧ ¬𝛽 into CNF

(𝐶1,1  𝑄

1,2 𝑄 2,1)  (𝑄 1,2 𝐶1,1)  (𝑄 2,1 𝐶1,1)(𝐶1,1)𝑄

1,2

51

Contradiction

OK?

slide-52
SLIDE 52

Completeness of resolution

52

 Resolution closure 𝑆𝐷(𝑇) : a set of clauses derivable by

repeated application of resolution rule to clauses in 𝑇 or their derivatives.

 𝑆𝐷(𝑇) is finite. Thus 𝑄𝑀_onstructed out of 𝑄

1, 𝑄2, … , 𝑄𝑙 that appear in

𝑇. 𝑆𝐹𝑇𝑃𝑀𝑉𝑈𝐽𝑃𝑂 terminates.

 Finite distinct clauses can be c

 Ground resolution theorem: If a set of clauses 𝑇 is unsatisfiable

then 𝑆𝐷(𝑇) contains the empty clause.

 If 𝑆𝐷(𝑇) does not contain the empty clause, we can find an assignment of

values to the symbols that satisfies 𝑆𝐷(𝑇) and thus 𝑇

slide-53
SLIDE 53

Horn clauses & definite clauses

53

 Some real-world KBs satisfy restrictions on the form of

sentences

 We can use more restricted and efficient inference algorithms

 Definite clause: a disjunction of literals of which exactly one is

positive literal. ¬𝑄

1 ∨ ¬𝑄2 ∨…∨ ¬𝑄𝑙 ∨ 𝑄𝑙+1 ⇔ (𝑄 1 ∧ 𝑄2 ∧ … ∧ 𝑄𝑙) ⇒ 𝑄𝑙+1

 Horn clause: a disjunction of literals of which at most one is

positive literal.

 Closed under resolution

slide-54
SLIDE 54

Grammar

54

𝑇𝑧𝑛𝑐𝑝𝑚 → 𝑄 𝑅 𝑆 | … 𝐼𝑝𝑠𝑜𝐷𝑚𝑏𝑣𝑡𝑓 → 𝐸𝑓𝑔𝑗𝑜𝑗𝑢𝑓𝐷𝑚𝑏𝑣𝑡𝑓 | 𝐻𝑝𝑏𝑚𝐷𝑚𝑏𝑣𝑡𝑓 𝐸𝑓𝑔𝑗𝑜𝑗𝑢𝑓𝐷𝑚𝑏𝑣𝑡𝑓 → 𝑇𝑧𝑛𝑐𝑝𝑚1 ∧ ⋯ ∧ 𝑇𝑧𝑛𝑐𝑝𝑚𝑚 ⇒ 𝑇𝑧𝑛𝑐𝑝𝑚 𝐻𝑝𝑏𝑚𝐷𝑚𝑏𝑣𝑡𝑓 → (𝑇𝑧𝑛𝑐𝑝𝑚1 ∧ ⋯ ∧ 𝑇𝑧𝑛𝑐𝑝𝑚𝑚) ⇒ 𝐺𝑏𝑚𝑡𝑓

slide-55
SLIDE 55

Forward and backward chaining

 Inference with Horn clauses can be done through forward

chaining or backward chaining.

 These algorithms are very natural and run in time that is linear

in the size of KB.

 They are bases of logic programming

 Prolog: backward chaining

55

slide-56
SLIDE 56

Forward chaining

 Repeated application of Modus Ponens until reaching goal  Fire any rule whose premises are satisfied in the KB

 add its conclusion to the KB, until query is found

56

Arcs show conjunctions

slide-57
SLIDE 57

Forward chaining algorithm

57

function 𝑄𝑀_𝐺𝐷_𝐹𝑂𝑈𝐵𝐽𝑀𝑇? (𝐿𝐶, 𝑟) returns 𝑢𝑠𝑣𝑓 or 𝑔𝑏𝑚𝑡𝑓 inputs: 𝐿𝐶, the knowledge base (a set of propositional definite clauses) 𝑟, the query (a propositional symbol) 𝑑𝑝𝑣𝑜𝑢 ← a table where 𝑑𝑝𝑣𝑜𝑢[𝑑] is the number of symbols in 𝑑’s premise 𝑗𝑜𝑔𝑓𝑠𝑠𝑓𝑒 ← a table, where 𝑗𝑜𝑔𝑓𝑠𝑠𝑓𝑒[𝑡] is initially false for all symbols 𝑏𝑕𝑓𝑜𝑒𝑏 ← a queue of symbols, initially symbols known to be true in 𝐿𝐶 while 𝑏𝑕𝑓𝑜𝑒𝑏 ≠ {} do 𝑞 ← 𝑄𝑃𝑄(𝑏𝑕𝑓𝑜𝑒𝑏) if 𝑞 = 𝑟 then return 𝑢𝑠𝑣𝑓 if 𝑗𝑜𝑔𝑓𝑠𝑠𝑓𝑒[𝑞] = 𝑔𝑏𝑚𝑡𝑓 then 𝑗𝑜𝑔𝑓𝑠𝑠𝑓𝑒[𝑞] ← 𝑢𝑠𝑣𝑓 for each clause 𝑑 in 𝐿𝐶 where 𝑞 is in 𝑑. 𝑄𝑆𝐹𝑁𝐽𝑇𝐹 do 𝑑𝑝𝑣𝑜𝑢[𝑑]= 𝑑𝑝𝑣𝑜𝑢[𝑑]-1 if 𝑑𝑝𝑣𝑜𝑢[𝑑] = 0 then add 𝑑. 𝐷𝑃𝑂𝐷𝑀𝑉𝑇𝐽𝑃𝑂 to 𝑏𝑕𝑓𝑜𝑒𝑏 return false

Begin with known facts (positive literals) in KB The process continues until q is added or no further inference

slide-58
SLIDE 58

Forward chaining: example

58

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-59
SLIDE 59

Forward chaining: example

59

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-60
SLIDE 60

Forward chaining: example

60

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-61
SLIDE 61

Forward chaining: example

61

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-62
SLIDE 62

Forward chaining: example

62

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-63
SLIDE 63

Forward chaining: example

63

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-64
SLIDE 64

Forward chaining: example

64

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-65
SLIDE 65

Forward chaining: example

65

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-66
SLIDE 66

Forward chaining

66

 Assumption: KB of definite clauses

 Sound?

 Every inference is an application of Modus Ponens.

 Complete?

 Every entailed atomic sentence will be derived?

 Humans keep forward chaining under careful control (to

avoid irrelevant consequences)

slide-67
SLIDE 67

Proof of completeness

  • 1. Consider the final state of the inferred table (fixed point

where no new atomic sentences are derived)

  • 2. Consider the final state as a model 𝑛, assigning 𝑢𝑠𝑣𝑓 to

inferred symbols and 𝑔𝑏𝑚𝑡𝑓 to others

  • 3. Every definite clause in the original KB is true in 𝑛

If “𝑏1 ∧ ⋯ ∧ 𝑏𝑜 ⇒ 𝑐” is false then 𝑏1 ∧ ⋯ ∧ 𝑏𝑜 is true and 𝑐 is false. But it contradicts with reaching a fixed point.

  • 4. Thus, 𝑛 is a model of KB
  • 5. If 𝐿𝐶 ⊨ 𝑟, atomic sentence 𝑟 is true in every model of KB,

including 𝑛

67

slide-68
SLIDE 68

Backward chaining

68

 Idea: work backwards from the query 𝑟:

 To prove 𝑟:

if 𝑟 is known to be true then no work is needed else Find those rule concluding 𝑟 If all premises of one of them can be proved (by backward chaining) then 𝑟 is true

 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 failed

slide-69
SLIDE 69

Backward chaining example

69

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-70
SLIDE 70

Backward chaining example

70

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-71
SLIDE 71

Backward chaining example

71

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-72
SLIDE 72

Backward chaining example

72

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-73
SLIDE 73

Backward chaining example

73

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-74
SLIDE 74

Backward chaining example

74

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-75
SLIDE 75

Backward chaining example

75

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-76
SLIDE 76

Backward chaining example

76

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-77
SLIDE 77

Backward chaining example

77

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-78
SLIDE 78

Backward chaining example

78

𝑄 ⇒ 𝑅 𝑀 ∧ 𝑁 ⇒ 𝑄 𝐶 ∧ 𝑀 ⇒ 𝑁 𝐵 ∧ 𝑄 ⇒ 𝑀 𝐵 ∧ 𝐶 ⇒ 𝑀 𝐵 𝐶

slide-79
SLIDE 79

Forward vs. backward chaining

 Forward

chaining is data-driven, automatic, unconscious processing

 May do lots of work that is irrelevant to the goal

 Backward chaining is goal-driven, appropriate for problem-

solving

 Only relevant facts are considered.

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

79

slide-80
SLIDE 80

Efficient propositional inference

 Efficient algorithms for general propositional inference:

 We introduced DPLL algorithm as a systematic search method

 Backtracking search algorithms

 Now, we will introduceWalkSAT algorithm as a local search algorithm

80

slide-81
SLIDE 81

WalkSAT

 It tests entailment 𝐿𝐶 ⊨ 𝛽 by testing unsatisfiability of 𝐿𝐶

∧ ¬𝛽.

 Local search algorithms (hill climbing, SA, …)

 state space: complete assignments  evaluation function: number of unsatisfied clauses

 WalkSat

 Simple & effective  Balance between greediness and randomness

 To escape from local minima 81

slide-82
SLIDE 82

WalkSAT

82

If max _𝑔𝑚𝑗𝑞𝑡 = ∞ and 𝑞 > 0, WalkSAT will find a model (if any exists) If max _𝑔𝑚𝑗𝑞𝑡 = ∞, it never terminates for unsatisfiable sentences.

slide-83
SLIDE 83

WalkSAT

83

 Failure may mean:

1)

The sentence is unsatisfiable.

2)

The algorithm needs more time.

 It can not detect unsatisfiability.

 Cannot be reliably used for deciding entailment.

slide-84
SLIDE 84

Knowledge-based agents

84

 Knowledge-based agents

 Reasoning

  • perates
  • n

internal representation

  • f

knowledge

 Logic as a general class of representation

 Propositional logic  First-order logic

slide-85
SLIDE 85

A generic knowledge-based agent

85

function KB_AGENT(𝑞𝑓𝑠𝑑𝑓𝑞𝑢) returns an 𝑏𝑑𝑢𝑗𝑝𝑜 persistent: 𝐿𝐶, a knowledge base 𝑢, 𝑏 counter for time, initially 0 TELL(𝐿𝐶, MAKE_PERCEPT_SENTENCE(𝑞𝑓𝑠𝑑𝑓𝑞𝑢, 𝑢)) 𝑏𝑑𝑢𝑗𝑝𝑜 ← ASK(𝐿𝐶, MAKE_ACTION_QUERY(𝑢)) TELL(𝐿𝐶, MAKE_ACTION_SENTENCE(𝑏𝑑𝑢𝑗𝑝𝑜, 𝑢)) 𝑢 ← 𝑢 + 1 return 𝑏𝑑𝑢𝑗𝑝𝑜

 The agent must be able to:

 Represent states, actions, percepts,….  Incorporate new percepts  Update internal representations of the world  Deduce hidden properties of the world  Deduce appropriate actions

  • Makes a sentence asserting that the agent

perceived the given percept at the given time.

  • Makes a sentence that asks what action

should be done at the current time.

  • Makes a sentence asserting that the chosen

action was executed.

slide-86
SLIDE 86

Knowledge Base (KB)

86

 KB

= a set

  • f

sentences expressed in a knowledge representation language

 TELL: adds new sentences to the knowledge base  ASK: asks a question of KB

 the answer follows from previously TELLed sentences to the KB

 Inference: derives new sentences from old ones

 Basis of TELL and ASK operations

slide-87
SLIDE 87

Wumpus world PEAS description

 Performance measure

 +1000 for garbing gold  -1000 for death  -1 for each action  -10 for using up the arrow  Game ends when the agent dies or climbs out of the cave

 Environment

 4×4 grid  Agent starts in [1,1] while facing to the right  Gold and wumpus are located randomly in the squares except to [1,1]  Each square other than [1,1] can be a pit with probability 0.2

87

slide-88
SLIDE 88

Wumpus world PEAS description

88

 Sensors: Stench, Breeze, Glitter, Bump, Scream

 In the squares adjacent to wumpus, agent perceives a Stench  It the squares adjacent to a pit, agent perceives a Breeze  In the gold square, agent perceives a Glitter  When walking into a wall, agent perceives a Bump  When Wumpus is killed, agent perceives a Scream

 Actuators: Forward, TurnLeft, TurnRight, Shoot, Grab, Climb

 Forward,TurnLeft,TurnRight: moving and rotating face actions.

 Moving to a square containing a pit or a live wumpus causes death.  If an agent tries to move forward and bumps into a wall then it does not move.

 Shoot: to fire an arrow in a straight line in the facing direction of the agent

 Shooting kills wumpus if the agent is facing it (o.w. the arrow hits a wall)

The first shoot action has any effect (the agent has only one arrow)

 Grab: to pick up the gold if it is in the same square as the agent.  Climb: climb out of the cave but only from [1,1]

slide-89
SLIDE 89

Wumpus world example: propositional symbols

89

 Atemporal variables that may be needed

 𝑄𝑗,𝑘 is true if there is a pit in [𝑗, 𝑘].  𝑋

𝑗,𝑘 is true if there is a wumpus in [𝑗, 𝑘], dead or alive.

 𝐶𝑗,𝑘 is true if the agent perceives a breeze in [𝑗, 𝑘].  𝑇𝑗,𝑘 is true if the agent perceives a stench in [𝑗, 𝑘].

 Some of the temporal variables that may be needed

 Variables for percepts and actions  𝑀𝑗,𝑘

𝑢 , 𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢𝑢, 𝐺𝑏𝑑𝑗𝑜𝑕𝑋𝑓𝑡𝑢𝑢, 𝐺𝑏𝑑𝑗𝑜𝑕𝑂𝑝𝑠𝑢ℎ𝑢, 𝐺𝑏𝑑𝑗𝑜𝑕𝑇𝑝𝑣𝑢ℎ𝑢

 𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥𝑢  𝑋𝑣𝑛𝑞𝑣𝑡𝐵𝑚𝑗𝑤𝑓𝑢

slide-90
SLIDE 90

Wumpus world example: axioms on atemporal aspect of the world

90

 Axioms: general knowledge about how the world works  General rules on atemporal variables

  • 𝑄

1,1

  • 𝑋

1,1

𝐶𝑦,𝑧  (𝑄

𝑦,𝑧+1  𝑄 𝑦,𝑧−1  𝑄 𝑦+1,𝑧 𝑄 𝑦−1,𝑧)

𝑇𝑦,𝑧  (𝑋

𝑦,𝑧+1  𝑋 𝑦,𝑧−1  𝑋 𝑦+1,𝑧  𝑋 𝑦−1,𝑧)

𝑋

1,1  𝑋 1,2  …  𝑋 4,4

  • 𝑋

1,1  𝑋 1,2

  • 𝑋

1,1  𝑋 1,3

A distinct rule is needed for each square

slide-91
SLIDE 91

Wumpus world example: perceptions & actions

91

 Perceptions are converted to facts and are Telled to KB

 𝑁𝐵𝐿𝐹_𝑄𝐹𝑆𝐷𝐹𝑄𝑈_𝑇𝐹𝑂𝑈𝐹𝑂𝐷𝐹 𝐶𝑠𝑓𝑓𝑨𝑓, 𝑇𝑢𝑓𝑜𝑑ℎ, 𝑂𝑝𝑜𝑓, 𝑂𝑝𝑜𝑓, 𝑂𝑝𝑜𝑓 , 𝑢 

𝐶𝑠𝑓𝑓𝑨𝑓𝑢, 𝑇𝑢𝑓𝑜𝑑ℎ𝑢 are added to KB

 Selected action is converted to a fact and is Telled to KB

 𝑁𝐵𝐿𝐹_𝐵𝐷𝑈𝐽𝑃𝑂_𝑇𝐹𝑂𝑈𝐹𝑂𝐷𝐹 𝐺𝑝𝑠𝑥𝑏𝑠𝑒, 𝑢  𝐺𝑝𝑠𝑥𝑏𝑠𝑒𝑢 is added to KB

slide-92
SLIDE 92

Wumpus world example: transition model

92

 Changing aspect of world (Temporal variables)

 They are also called as fluents or state variables

 Initial KB includes the initial status of some of the temporal variables:

 𝑀1,1

0 , 𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢0, 𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥0, 𝑋𝑣𝑛𝑞𝑣𝑡𝐵𝑚𝑗𝑤𝑓0

 Percepts are connected to fluents describing the properties of

squares

 𝑀𝑦,𝑧

𝑢

⇒ (𝐶𝑠𝑓𝑓𝑨𝑓𝑢 ⇔ 𝐶𝑦,𝑧)

 𝑀𝑦,𝑧

𝑢

⇒ 𝑇𝑢𝑓𝑜𝑑ℎ𝑢 ⇔ 𝑇𝑦,𝑧

 …

 Transition model: fluents can change as the results of agent’s actions

slide-93
SLIDE 93

Wumpus world example: transition model Frame problem

93

 Transition model: 𝑀1,1 ∧ 𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢0 ∧ 𝐺𝑝𝑠𝑥𝑏𝑠𝑒0 ⇒ (𝑀2,1

1

∧ ¬𝑀1,1

1 )

𝑀1,1 ∧ 𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢0 ∧ 𝑈𝑣𝑠𝑜𝑀𝑓𝑔𝑢0 ⇒ (𝑀1,1

1

∧ 𝐺𝑏𝑑𝑗𝑜𝑕𝑂𝑝𝑠𝑢ℎ1 ∧ ¬𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢1)

 After doing 𝐺𝑝𝑠𝑥𝑏𝑠𝑒 action at time 0:

 𝐵𝑇𝐿 𝐿𝐶, 𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥1 = 𝑔𝑏𝑚𝑡𝑓

 Why?

 Frame problem: representing the effects of actions without having to

represent explicitly a large number of intuitively obvious non-effects

slide-94
SLIDE 94

Wumpus world example

Solution to frame problem: successor-state axioms

94

 A Solution to frame problem: Successor-state axioms

Instead of writing axioms about actions, we write axioms about fluents

 𝐺𝑢+1 ⇔ 𝐵𝑑𝑢𝑗𝑝𝑜𝐷𝑏𝑣𝑡𝑓𝑡𝐺𝑢 ∨ (𝐺𝑢 ∧ ¬𝐵𝑑𝑢𝑗𝑝𝑜𝐷𝑏𝑣𝑡𝑓𝑡𝑂𝑝𝑢𝐺𝑢)

𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥𝑢+1 ⇔ 𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥𝑢 ∧ ¬𝑇ℎ𝑝𝑝𝑢𝑢 𝑀1,1

𝑢+1 ⇔ (𝑀1,1 𝑢

∧ (¬𝐺𝑝𝑠𝑥𝑏𝑠𝑒𝑢 ∨ 𝐶𝑣𝑛𝑞𝑢+1)) ∨ (𝑀1,2

𝑢

∧ (𝐺𝑏𝑑𝑗𝑜𝑕𝑇𝑝𝑣𝑢ℎ𝑢 ∧ 𝐺𝑝𝑠𝑥𝑏𝑠𝑒𝑢)) ∨ (𝑀2,1

𝑢

∧ (𝐺𝑏𝑑𝑗𝑜𝑕𝑋𝑓𝑡𝑢𝑢 ∧ 𝐺𝑝𝑠𝑥𝑏𝑠𝑒𝑢))

slide-95
SLIDE 95

A hybrid agent for the wumpus world

95

 Basic concepts:

 Safeness of [𝑦, 𝑧] square:

 𝑃𝐿𝑦,𝑧

𝑢

⇔ ¬𝑄

𝑦,𝑧 ∧ ¬(𝑋 𝑦,𝑧 ∧ 𝑋𝑣𝑛𝑞𝑣𝑡𝐵𝑚𝑗𝑤𝑓𝑢)

 Set of safe squares:

 𝑡𝑏𝑔𝑓 ←

𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, 𝑃𝐿𝑦,𝑧

𝑢

= 𝑢𝑠𝑣𝑓

 Set of unvisited squares:

 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ←

𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, 𝑀𝑦,𝑧

𝑢′

= 𝑔𝑏𝑚𝑡𝑓 𝑔𝑝𝑠 𝑏𝑚𝑚 𝑢′ ≤ 𝑢

slide-96
SLIDE 96

96 function 𝐼𝑍𝐶𝑆𝐽𝐸_𝑋𝑉𝑁𝑄𝑉𝑇_𝐵𝐻𝐹𝑂𝑈(𝑞𝑓𝑠𝑑𝑓𝑞𝑢) returns an action sequence inputs: 𝑞𝑓𝑠𝑑𝑓𝑞𝑢, a list, 𝑐𝑠𝑓𝑓𝑨𝑓, 𝑡𝑢𝑓𝑜𝑑ℎ, 𝑕𝑚𝑗𝑢𝑢𝑓𝑠, 𝑐𝑣𝑛𝑞, 𝑡𝑑𝑠𝑓𝑏𝑛 persistent: 𝐿𝐶, initially the atemporal “wumpus physics” 𝑢, a time counter, initially 0 𝑞𝑚𝑏𝑜, an action sequence, initially empty TELL(𝐿𝐶, 𝑁𝐵𝐿𝐹_𝑄𝐹𝑆𝐷𝐹𝑄𝑈_𝑇𝐹𝑂𝑈𝐹𝑂𝐷𝐹 𝑞𝑓𝑠𝑑𝑓𝑞𝑢, 𝑢 ) TELL the 𝐿𝐶 the temporal “physics” sentences for time 𝑢 𝑡𝑏𝑔𝑓 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, 𝑃𝐿𝑦,𝑧

𝑢

= 𝑢𝑠𝑣𝑓 if 𝐵𝑇𝐿(𝐿𝐶, 𝐻𝑚𝑗𝑢𝑢𝑓𝑠𝑢) = 𝑢𝑠𝑣𝑓 then 𝑞𝑚𝑏𝑜 ← 𝐻𝑠𝑏𝑐 + 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹 𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 1,1 , 𝑡𝑏𝑔𝑓 + [𝐷𝑚𝑗𝑛𝑐] if 𝑞𝑚𝑏𝑜 = {} then 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, 𝑀𝑦,𝑧

𝑢′

= 𝑔𝑏𝑚𝑡𝑓 𝑔𝑝𝑠 𝑏𝑚𝑚 𝑢′ ≤ 𝑢 𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ∩ 𝑡𝑏𝑔𝑓, 𝑡𝑏𝑔𝑓) if 𝑞𝑚𝑏𝑜 = {} and 𝐵𝑇𝐿 𝐿𝐶, 𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥𝑢 = 𝑢𝑠𝑣𝑓 then 𝑞𝑝𝑡𝑡𝑗𝑐𝑚𝑓_𝑥𝑣𝑛𝑞𝑣𝑡 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, ¬𝑋

𝑦,𝑧 = 𝑔𝑏𝑚𝑡𝑓

𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑇𝐼𝑃𝑈(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑞𝑝𝑡𝑡𝑗𝑐𝑚𝑓_𝑥𝑣𝑛𝑞𝑣𝑡, 𝑡𝑏𝑔𝑓) if 𝑞𝑚𝑏𝑜 = {} then 𝑜𝑝𝑢_𝑣𝑜𝑡𝑏𝑔𝑓 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, ¬𝑃𝐿𝑦,𝑧

𝑢

= 𝑔𝑏𝑚𝑡𝑓 𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ∩ 𝑜𝑝𝑢_𝑣𝑜𝑡𝑏𝑔𝑓, 𝑡𝑏𝑔𝑓) if 𝑞𝑚𝑏𝑜 = {} then 𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹 𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 1,1 , 𝑡𝑏𝑔𝑓 + [𝐷𝑚𝑗𝑛𝑐] action ← 𝑄𝑃𝑄(𝑞𝑚𝑏𝑜) 𝑈𝐹𝑀𝑀(𝐿𝐶, 𝑁𝐵𝐿𝐹_𝐵𝐷𝑈𝐽𝑃𝑂_𝑇𝐹𝑂𝑈𝐹𝑂𝐷𝐹(𝑏𝑑𝑢𝑗𝑝𝑜, 𝑢)) 𝑢 ← 𝑢 + 1 return 𝑏𝑑𝑢𝑗𝑝𝑜

slide-97
SLIDE 97

Hybrid agent (phases listed based on priority)

97

 Simple-reflex (condition-action rule): if 𝐵𝑇𝐿(𝐿𝐶, 𝐻𝑚𝑗𝑢𝑢𝑓𝑠𝑢) = 𝑢𝑠𝑣𝑓 then 𝑞𝑚𝑏𝑜 ← [𝐻𝑠𝑏𝑐] + 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹 𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 1,1 , 𝑡𝑏𝑔𝑓 + [𝐷𝑚𝑗𝑛𝑐]  Goal-based & reasoning: if 𝑞𝑚𝑏𝑜 = {} then 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, 𝑀𝑦,𝑧

𝑢′

= 𝑔𝑏𝑚𝑡𝑓 𝑔𝑝𝑠 𝑏𝑚𝑚 𝑢′ ≤ 𝑢 𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ∩ 𝑡𝑏𝑔𝑓, 𝑡𝑏𝑔𝑓) if 𝑞𝑚𝑏𝑜 = {} and 𝐵𝑇𝐿 𝐿𝐶, 𝐼𝑏𝑤𝑓𝐵𝑠𝑠𝑝𝑥𝑢 = 𝑢𝑠𝑣𝑓 then 𝑞𝑝𝑡𝑡𝑗𝑐𝑚𝑓_𝑥𝑣𝑛𝑞𝑣𝑡 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, ¬𝑋

𝑦,𝑧 = 𝑔𝑏𝑚𝑡𝑓

𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑇𝐼𝑃𝑈(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑞𝑝𝑡𝑡𝑗𝑐𝑚𝑓_𝑥𝑣𝑛𝑞𝑣𝑡, 𝑡𝑏𝑔𝑓)

slide-98
SLIDE 98

Hybrid agent (phases listed based on priority)

98

 Exploration & reasoning if 𝑞𝑚𝑏𝑜 = {} then 𝑜𝑝𝑢_𝑣𝑜𝑡𝑏𝑔𝑓 ← 𝑦, 𝑧 : 𝐵𝑇𝐿 𝐿𝐶, ¬𝑃𝐿𝑦,𝑧

𝑢

= 𝑔𝑏𝑚𝑡𝑓 𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑣𝑜𝑤𝑗𝑡𝑗𝑢𝑓𝑒 ∩ 𝑜𝑝𝑢_𝑣𝑜𝑡𝑏𝑔𝑓, 𝑡𝑏𝑔𝑓)  Goal-based: if 𝑞𝑚𝑏𝑜 = {} then 𝑞𝑚𝑏𝑜 ← 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹 𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 1,1 , 𝑡𝑏𝑔𝑓 + [𝐷𝑚𝑗𝑛𝑐]

slide-99
SLIDE 99

Hybrid agent: Using A* to make a plan

99

function 𝑄𝑀𝐵𝑂_𝑆𝑃𝑉𝑈𝐹(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑕𝑝𝑏𝑚, 𝑏𝑚𝑚𝑝𝑥𝑓𝑒) returns an action sequence inputs: 𝑑𝑣𝑠𝑠𝑓𝑜𝑢, the agent’s current position 𝑕𝑝𝑏𝑚𝑡, a set of squares; try to plan a route to one of them 𝑏𝑚𝑚𝑝𝑥𝑓𝑒, a set of squares that can form part of the route 𝑞𝑠𝑝𝑐𝑚𝑓𝑛 ← 𝑆𝑃𝑉𝑈𝐹_𝑄𝑆𝑃𝐶𝑀𝐹𝑁(𝑑𝑣𝑠𝑠𝑓𝑜𝑢, 𝑕𝑝𝑏𝑚𝑡, 𝑏𝑚𝑚𝑝𝑥𝑓𝑒) return 𝐵∗_𝐻𝑆𝐵𝑄𝐼_𝑇𝐹𝐵𝑆𝐷𝐼(𝑞𝑠𝑝𝑐𝑚𝑓𝑛)

slide-100
SLIDE 100

SATPlan

100

 SATPlan is a method to solve the whole problem as a SAT

problem

 It considers both state fluents and actions (of each time)

as proposition

slide-101
SLIDE 101

101

Pictorial view of fluent for (P,k)

… …

s0 sk ak-1

Initial state fluents (t=0) state fluents at t=k action fluents at t=k-1

… … …

 Truth assignment selects a subset of these nodes to be true  Propositional formulas correspond to valid plans

a0

slide-102
SLIDE 102

102

Translating PDDL to propositional logic

 Initial state: Conjunction of all true literals at time 0 (and negation of not

mentioned literals)

 Goal state: Conjunction of all goal literals at time 𝑙

 Instantiate literals containing variable (replace with ∨ over constants).

 Actions

 successor-state axioms at each time up to 𝑢

 𝐺𝑢+1 ⟺ 𝐵𝑑𝑢𝑗𝑝𝑜𝐷𝑏𝑣𝑡𝑓𝑡𝐺𝑢 ∨ (𝐺𝑢 ∧ ¬𝐵𝑑𝑢𝑗𝑝𝑜𝐷𝑏𝑣𝑡𝑓𝑡𝑂𝑝𝑢𝐺𝑢)

 precondition axioms:

 𝐵𝑢 ⇒ PRECOND 𝐵 𝑢

 action exclusion axioms:

 ¬𝐵𝑗

𝑢 ∨ ¬𝐵𝑘 𝑢

slide-103
SLIDE 103

SATPlan example

 Domain:

 T

wo locations 𝑀1, 𝑀2

 One operator “move” the robot

 Initial state: 𝐵𝑢(𝑀1)  Goal: 𝐵𝑢(𝑀2)  Action schema:

 𝑁𝑝𝑤𝑓 𝑚, 𝑚’

 𝑄𝑆𝐹𝐷𝑃𝑂𝐸: 𝐵𝑢(𝑚)  𝐹𝐺𝐺𝐹𝐷𝑈: 𝐵𝑢(𝑚’) ∧ ¬𝐵𝑢(𝑚)

103

𝑀1 𝑀2

slide-104
SLIDE 104

SATPlan example (translation to SAT)

104

 Encode (𝑄, 1)

 Initial state:

 𝐵𝑢(𝑀1, 0) ∧ ¬ 𝐵𝑢(𝑀2, 0)

 Goal:

 𝐵𝑢(𝑀2, 1)

 Actions preconditions:

 𝑁𝑝𝑤𝑓(𝑀1, 𝑀2, 0) ⇒ 𝐵𝑢(𝑀1, 0)  𝑁𝑝𝑤𝑓(𝑀2, 𝑀1, 0) ⇒ 𝐵𝑢(𝑀2, 0)

 Action exclusion axiom:

 ¬𝑁𝑝𝑤𝑓(𝑀2, 𝑀1, 0) ∨ ¬𝑁𝑝𝑤𝑓(𝑀1, 𝑀2, 0)

slide-105
SLIDE 105

SATPlan example (translation to SAT)

 Fluents (Success-state axioms):

𝐵𝑢 𝑀1, 1 ⟺ (𝐵𝑢 𝑀1, 0 𝑁𝑝𝑤𝑓 𝑀1, 𝑀2, 0 ) ∨ 𝑁𝑝𝑤𝑓 𝑀2, 𝑀1, 0

 𝐵𝑢 𝑀2, 1 ⟺ (𝐵𝑢 𝑀2, 0 𝑁𝑝𝑤𝑓 𝑀2, 𝑀1, 0 ) ∨ 𝑁𝑝𝑤𝑓 𝑀1, 𝑀2, 0

105

slide-106
SLIDE 106

Propositional logic solver and decoding

106

 Apply a SAT solver to the whole sentence 

 : conjunction of encoding initial state, goals, successor-state axioms,

precondition axioms, action exclusion axioms

 If an assignment of truth values that satisfies  is found,

extract action sequence.

 This means 𝑄 has a solution of length 𝑙

 Extract solution: For 𝑗 = 0, … , 𝑙 − 1, there is exactly one

action that has been assigned “True”

 This is the 𝑗’th action of the plan.

slide-107
SLIDE 107

SATPlan example (translation to SAT)

𝐵𝑢(𝑀1, 0) ∧ ¬𝐵𝑢(𝑀2, 0) ∧ 𝐵𝑢(𝑀2, 1) ∧ [𝑁𝑝𝑤𝑓 𝑀1, 𝑀2, 0  𝐵𝑢 𝑀1, 0 ] ∧ [𝑁𝑝𝑤𝑓 𝑀1, 𝑀2, 0  𝐵𝑢 𝑀2, 1 ] ∧ [¬𝑁𝑝𝑤𝑓(𝑀2, 𝑀1, 0) ∨ ¬𝑁𝑝𝑤𝑓(𝑀1, 𝑀2, 0)] ∧ [𝐵𝑢 𝑀1, 0  𝐵𝑢 𝑀1, 1  𝑁𝑝𝑤𝑓 𝑀2, 𝑀1, 0 ] ∧ [𝐵𝑢 𝑀2, 0  𝐵𝑢 𝑀2, 1  𝑁𝑝𝑤𝑓 𝑀1, 𝑀2, 0 ] ∧ [𝐵𝑢 𝑀1, 0 𝐵𝑢 𝑀1, 1  𝑁𝑝𝑤𝑓 𝑀1, 𝑀2, 0 ] ∧ 𝐵𝑢 𝑀2, 0 𝐵𝑢 𝑀2, 1  𝑁𝑝𝑤𝑓 𝑀2, 𝑀1, 0

Above formula is converted to CNF and solved by a SAT solver.

107

SAT formula for (P,1)

slide-108
SLIDE 108

SATPlan example (Extracting a plan)

108

  can be satisfied with 𝑛𝑝𝑤𝑓(𝑆, 𝑀1, 𝑀2, 0) = 𝑢𝑠𝑣𝑓  ⇒ 𝑛𝑝𝑤𝑓(𝑆, 𝑀1, 𝑀2, 0) is a solution (and the only one) for

panning problem with 1 step plan

slide-109
SLIDE 109

SATPlan

109

function SATPLAN(𝑗𝑜𝑗𝑢, 𝑢𝑠𝑏𝑜𝑡𝑗𝑢𝑗𝑝𝑜, 𝑕𝑝𝑏𝑚, 𝑈_𝑛𝑏𝑦) returns solution or failure inputs: 𝑗𝑜𝑗𝑢, 𝑢𝑠𝑏𝑜𝑡𝑗𝑢𝑗𝑝𝑜, 𝑕𝑝𝑏𝑚, constitute a description of the problem 𝑈_𝑛𝑏𝑦, an upper limit for plan length for 𝑢 = 0 to 𝑈_max do 𝑑𝑜𝑔 ← TRANSLATE_TO_SAT(𝑗𝑜𝑗𝑢, 𝑢𝑠𝑏𝑜𝑡𝑗𝑢𝑗𝑝𝑜, 𝑕𝑝𝑏𝑚, 𝑢 ) 𝑛𝑝𝑒𝑓𝑚 ← SAT_SOLVER(𝑑𝑜𝑔) if 𝑛𝑝𝑒𝑓𝑚 ≠ {} then return EXTRACT_SOLUTION(𝑛𝑝𝑒𝑓𝑚) return 𝑔𝑏𝑗𝑚𝑣𝑠𝑓 It is guaranteed to find the shortest plan if one exist.

slide-110
SLIDE 110

Solving SAT problem

110

 Systematic search

 DPLL (Davis Putnam Logemann Loveland)

 Local search

 WalkSAT

slide-111
SLIDE 111

 Wumpus world

 Distinct rules “for each square [x,y]” and “for each time t”

𝑀𝑦,𝑧

𝑢

∧ 𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢𝑢 ∧ 𝑈𝑣𝑠𝑜𝑀𝑓𝑔𝑢𝑢 ⇒ (𝑀𝑦,𝑧

𝑢+1 ∧ 𝐺𝑏𝑑𝑗𝑜𝑕𝑉𝑞𝑢+1 ∧ ¬𝐺𝑏𝑑𝑗𝑜𝑕𝐹𝑏𝑡𝑢𝑢+1)

 Many rules are needed to describe the world axioms

 Rather impractical for bigger world

 We can not express general knowledge about “physics” of the world

directly in propositional language

 More expressive language is needed.

 Qualification problem: specifying all the exceptions

 Probability theory allows us to summarize all the exceptions (without

explicitly naming them)

Limitations of propositional logic

111