logical agents - sabancı...

102
Logical agents AIMA 3rd ed. - Chapter 7 AIMA 3rd ed. - Chapter 7 1

Upload: others

Post on 13-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Logical agents

AIMA 3rd ed. - Chapter 7

AIMA 3rd ed. - Chapter 7 1

Page 2: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Outline

♦ Knowledge-based agents

♦ Wumpus world

♦ Logic in general—models and entailment

♦ Propositional (Boolean) logic

♦ Equivalence, validity, satisfiability

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

♦ Model checking

AIMA 3rd ed. - Chapter 7 2

Page 3: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Knowledge bases

Inference engine

Knowledge base domain−specific content

domain−independent algorithms

Knowledge base = set of sentences in a formal language

Declarative approach to building an agent (or other system):Tell it what it needs to know

Then it can Ask itself what to do—answers should follow from the KB

Agents can be viewed at the knowledge leveli.e., what they know, regardless of how implemented

Or at the implementation leveli.e., data structures in KB and algorithms that manipulate them

AIMA 3rd ed. - Chapter 7 3

Page 4: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

A simple knowledge-based agent

function KB-Agent( percept) returns an action

static: KB, a knowledge base

t, a counter, initially 0, indicating time

Tell(KB,Make-Percept-Sentence( percept, t))

action←Ask(KB,Make-Action-Query(t))

Tell(KB,Make-Action-Sentence(action, t))

t← t + 1

return action

The agent must be able to:Represent states, actions, etc.Incorporate new perceptsUpdate internal representations of the worldDeduce hidden properties of the worldDeduce appropriate actions

AIMA 3rd ed. - Chapter 7 4

Page 5: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus World PEAS description

Performance measure

gold +1000, death -1000-1 per step, -10 for using the arrow

Environment

Squares adjacent to wumpus are smellySquares adjacent to pit are breezyGlitter iff gold is in the same squareShooting kills wumpus if you are facing itShooting uses up the only arrowGrabbing picks up gold if in same squareReleasing drops the gold in same square

Breeze Breeze

Breeze

BreezeBreeze

Stench

Stench

BreezePIT

PIT

PIT

1 2 3 4

1

2

3

4

START

Gold

Stench

Actions Left turn, Right turn,Forward, Grab, Release, Shoot

Sensors Breeze, Glitter, Smell

Goals Get gold back to start without entering pit or wumpus square

AIMA 3rd ed. - Chapter 7 5

Page 6: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable??

AIMA 3rd ed. - Chapter 7 6

Page 7: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable?? No—only local perception

Deterministic??

AIMA 3rd ed. - Chapter 7 7

Page 8: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic??

AIMA 3rd ed. - Chapter 7 8

Page 9: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static??

AIMA 3rd ed. - Chapter 7 9

Page 10: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static?? Yes—Wumpus and Pits do not move

Discrete??

AIMA 3rd ed. - Chapter 7 10

Page 11: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static?? Yes—Wumpus and Pits do not move

Discrete?? Yes

Single-agent??

AIMA 3rd ed. - Chapter 7 11

Page 12: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus world characterization

Observable?? No—only local perception

Deterministic?? Yes—outcomes exactly specified

Episodic?? No—sequential at the level of actions

Static?? Yes—Wumpus and Pits do not move

Discrete?? Yes

Single-agent?? Yes—Wumpus is essentially a natural feature

AIMA 3rd ed. - Chapter 7 12

Page 13: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

A

OK

OKOK

AIMA 3rd ed. - Chapter 7 13

Page 14: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

AIMA 3rd ed. - Chapter 7 14

Page 15: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

AIMA 3rd ed. - Chapter 7 15

Page 16: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

AIMA 3rd ed. - Chapter 7 16

Page 17: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

AIMA 3rd ed. - Chapter 7 17

Page 18: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

AIMA 3rd ed. - Chapter 7 18

Page 19: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

OK

OK

AIMA 3rd ed. - Chapter 7 19

Page 20: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Exploring a wumpus world

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

OK

OK

A

BGS

AIMA 3rd ed. - Chapter 7 20

Page 21: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Uncertainty

There may be situations where there are no guaranteed safe moves. In thatcase, we will consider the likelihoods of events (e.g. if we have nochoice but go to one of the squares that may have a pit, decide on whichone has a higher probability of having a pit; we will see this later).

But for now, we assume that we are dealing with problems that can be solvedwith logical thinking and there is no chance involved (i.e. no remaininguncertainty).

AIMA 3rd ed. - Chapter 7 21

Page 22: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

A

B OK

OK OK

A

B

A

P?

P?P?

P?

Breeze in (1,2) and (2,1)⇒ no safe actions

A

S

Smell in (1,1)⇒ cannot move

Can use a strategy of coercion:shoot straight aheadwumpus was there ⇒ dead ⇒ safewumpus wasn’t there ⇒ safe

AIMA 3rd ed. - Chapter 7 22

Page 23: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

AIMA 3rd ed. - Chapter 7 23

Page 24: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Inference in computers

♦ How can we get an agent do what we did? That is, how can it knowwhether it is OK to move to [2,1]?

♦ Notice that an exhaustive search is not an option here because the agentdoesnt want to die.

♦ The agent needs a formal inference mechanism to derive valid conclusionseven when it does not know what the interpretation is (the computer doesnot need to know the meaning of OK, or Wumpus or Pit... )

We will use a formal logic to extend the capacity of our agents by endowingthem with the capacity for general logical reasoning.

AIMA 3rd ed. - Chapter 7 24

Page 25: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Logic in general

Syntax defines the sentences in the language

Semantics define the “meaning” of sentences;i.e., define truth of a sentence in a world

Logic is the framework where a formal language represents informationsuch that conclusions can be drawn.

E.g., the language of arithmetic

x + 2 ≥ y is a sentence; x2 + y > is not a sentence

x + 2 ≥ y is true iff the number x + 2 is no less than the number y

x + 2 ≥ y is true in a world where x=7, y=1x + 2 ≥ y is false in a world where x=0, y=6

AIMA 3rd ed. - Chapter 7 25

Page 26: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Knowledge bases - 6.1

Knowledge base is a set of representations of facts (sentences)about the world, expressed in knowledge representation language.**

Inference engine

Knowledge base domain−specific content

domain−independent algorithms

Declarative approach to building an agent (or other system):Tell it what it needs to know

Then it can Ask itself what to do—answers should follow from the KB

AIMA 3rd ed. - Chapter 7 26

Page 27: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Knowledge bases

Agents can be viewed at the knowledge leveli.e., what they know, regardless of how implemented

The implementation level may represent the knowledge in various forms:e.g. UcakSeferi(Istanbul,Samsun) can be represented as a stringin a list of strings or as TRUE in a 2D table indexed by location pairs

etc.

But we don’t care about the implementation details of the KB.

AIMA 3rd ed. - Chapter 7 27

Page 28: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Entailment

We are interested in new sentences that we can infer from the knowledgebaseand the new percepts. E.g. seeing that there is no breeze in [1,1], can weinfer that there is no wumpus in [1,2]? We will use the word entailmentwhich means that one thing follows from another:

KB |= α

Knowledge base KB entails sentence αif and only if

α is true in all worlds where KB is true

E.g., the KB containing x = 0entails xy = 0

E.g., x + y=4 entails 4= x + y

AIMA 3rd ed. - Chapter 7 28

Page 29: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Models

We will consider possible worlds or models that define the truth settings ofall sentences.

We say m is a model of a sentence α if α is true in m

M(α) is the set of all models of α

Difference between world and model:”model” is used interchangeably with ”world” in the general sense;but a ”model” of a particular sentence is a ”world” in which that sentenceis True)

AIMA 3rd ed. - Chapter 7 29

Page 30: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Entailment in the wumpus world

Situation after detecting nothing in [1,1], moving right and detecting breezein [2,1].

Consider possible models for ?s assuming only pits:

AA

B

??

?

AIMA 3rd ed. - Chapter 7 30

Page 31: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus models

3 Boolean choices ⇒ 8 possible models:

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

AIMA 3rd ed. - Chapter 7 31

Page 32: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus models

Models of KB:

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB

KB = wumpus-world rules + observations

AIMA 3rd ed. - Chapter 7 32

Page 33: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB1

KB = wumpus-world rules + observations

α1 = “[1,2] is safe”, KB |= α1, proved by model checking

AIMA 3rd ed. - Chapter 7 33

Page 34: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB

KB = wumpus-world rules + observations

AIMA 3rd ed. - Chapter 7 34

Page 35: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Wumpus models

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT

1 2 3

1

2

Breeze

PIT PIT

PIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

BreezePIT

1 2 3

1

2

Breeze

PIT

PIT

1 2 3

1

2

Breeze

PIT PIT

1 2 3

1

2

Breeze

KB2

KB = wumpus-world rules + observations

α2 = “[2,2] is safe”, KB 6|= α2

AIMA 3rd ed. - Chapter 7 35

Page 36: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Models

What we saw is summarized as: KB |= α if and only if M(KB) ⊆M(α)

Equivalently; KB |= α if and only if α is true everywhere KB is true.

E.g. KB = ”GS won” and ”BJK won”α = ”GS won” M( )

M(KB)

x

x

x

x

x

x

x x

x

x

xx

xx

xx

xx

x

xxxx

x x

xx

xx x

x

xx

x x x

x

xx

x

x

x

x

x

x

x

x

AIMA 3rd ed. - Chapter 7 36

Page 37: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Inference

KB ⊢i α = sentence α can be derived from KB by procedure i

Consequences of KB are a haystack; α is a needle.Entailment = needle in haystack; inference = finding it

Soundness: i is sound ifwhenever KB ⊢i α, it is also true that KB |= α

Completeness: i is complete ifwhenever KB |= α, it is also true that KB ⊢i α

Preview: we will define a logic (first-order logic) which is expressive enoughto say almost anything of interest, and for which there exists a sound andcomplete inference procedure.

That is, the procedure will answer any question whose answer follows fromwhat is known by the KB.

AIMA 3rd ed. - Chapter 7 37

Page 38: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Representation

We know of some knowledge representation languages:

♦ Programming languages

In a programming language you can say that ”there is a pit in [2,2]” byworld[2,2] = pit, but you cannot say ”either there is a pit in [2,1] or in [3,2]”or that ”there is a wumpus in some square”

♦ Propositional logic

♦ First-order logic

♦ Natural languages are very expressive, but also too flexible/ambiguous

AIMA 3rd ed. - Chapter 7 38

Page 39: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Propositional logic: Syntax

Propositional logic is the simplest logic—illustrates basic ideas

The proposition symbols P1, P2 etc are sentences

If S is a sentence, ¬S is a sentence (negation)

If S1 and S2 are sentences, S1 ∧ S2 is a sentence (conjunction)

If S1 and S2 are sentences, S1 ∨ S2 is a sentence (disjunction)

If S1 and S2 are sentences, S1 ⇒ S2 is a sentence (implication)

If S1 and S2 are sentences, S1 ⇔ S2 is a sentence (biconditional)

AIMA 3rd ed. - Chapter 7 39

Page 40: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Propositional logic: Semantics

Each model specifies true/false for each proposition symbol:

E.g. P1,2 P2,2 P3,1

true true false

Rules for evaluating truth with respect to a model m:

¬S is true iff S is falseS1 ∧ S2 is true iff S1 is true and S2 is trueS1 ∨ S2 is true iff S1 is true or S2 is true

S1 ⇒ S2 is true iff S1 is false or S2 is truei.e., is false iff S1 is true and S2 is false

S1 ⇔ S2 is true iff S1 ⇒ S2 is true and S2 ⇒ S1 is true

AIMA 3rd ed. - Chapter 7 40

Page 41: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Truth tables for connectives

P Q ¬P P ∧Q P ∨Q P⇒Q P⇔Q

false false true false false true true

false true true false true true false

true false false false true false false

true true false true true true true

♦ True is true in every model

♦ False is false in every model

♦ Simple recursive process evaluates an arbitrarily complex sentence, e.g.,¬P1,2 ∧ (P2,2 ∨ P3,1) = false ∧ (false ∨ true) = false ∧ true= false

AIMA 3rd ed. - Chapter 7 41

Page 42: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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].

¬P1,1

¬B1,1

B2,1

“Pits cause breezes in adjacent squares”

AIMA 3rd ed. - Chapter 7 42

Page 43: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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].

¬P1,1

¬B1,1

B2,1

“Pits cause breezes in adjacent squares”

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

B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1)

“A square is breezy if and only if there is an adjacent pit”

AIMA 3rd ed. - Chapter 7 43

Page 44: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Truth tables for inference

B1,1 B2,1 P1,1 P1,2 P2,1 P2,2 P3,1 R1 R2 R3 R4 R5 KB

false false false false false false false true true true true false false

false false false false false false true true true false true false false... ... ... ... ... ... ... ... ... ... ... ... ...

false true false false false false false true true false true true false

false true false false false false true true true true true true true

false true false false false true false true true true true true true

false true false false false true true true true true true true true

false true false false true false false true false false true true false... ... ... ... ... ... ... ... ... ... ... ... ...

true true true true true true true false true true false true false

Enumerate rows (different assignments to symbols),if KB is true in row, check that α is true too

AIMA 3rd ed. - Chapter 7 44

Page 45: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Inference by enumeration

Depth-first enumeration of all models is sound and complete

function TT-Entails?(KB,α) returns true or false

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

α, the query, a sentence in propositional logic

symbols← a list of the proposition symbols in KB and α

return TT-Check-All(KB,α, symbols, [ ])

function TT-Check-All(KB,α, symbols,model) returns true or false

if Empty?(symbols) then

if PL-True?(KB,model) then return PL-True?(α,model)

else return true

else do

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

return TT-Check-All(KB,α, rest,Extend(P , true,model)) and

TT-Check-All(KB,α, rest,Extend(P , false,model))

O(2n) for n symbols; problem is co-NP-complete

AIMA 3rd ed. - Chapter 7 45

Page 46: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Proof methods

Proof methods divide into (roughly) two kinds:

Model checking

a) truth table enumeration (always exponential in n)b) heuristic search in model space (sound but incomplete)

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

Application of inference rules

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

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

AIMA 3rd ed. - Chapter 7 46

Page 47: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Logical equivalence

Two sentences are logically equivalent iff true in same models:α ≡ β if and only if α |= β and β |= α

(α ∧ β) ≡ (β ∧ α) commutativity of ∧(α ∨ β) ≡ (β ∨ α) commutativity of ∨

((α ∧ β) ∧ γ) ≡ (α ∧ (β ∧ γ)) associativity of ∧((α ∨ β) ∨ γ) ≡ (α ∨ (β ∨ γ)) associativity of ∨

¬(¬α) ≡ α double-negation elimination(α ⇒ β) ≡ (¬β ⇒ ¬α) contraposition(α ⇒ β) ≡ (¬α ∨ β) implication elimination(α ⇔ β) ≡ ((α ⇒ β) ∧ (β ⇒ α)) biconditional elimination¬(α ∧ β) ≡ (¬α ∨ ¬β) De Morgan¬(α ∨ β) ≡ (¬α ∧ ¬β) De Morgan

(α ∧ (β ∨ γ)) ≡ ((α ∧ β) ∨ (α ∧ γ)) distributivity of ∧ over ∨(α ∨ (β ∧ γ)) ≡ ((α ∨ β) ∧ (α ∨ γ)) distributivity of ∨ over ∧

AIMA 3rd ed. - Chapter 7 47

Page 48: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Validity and satisfiability

A sentence is valid if it is true in all models,e.g., True, A ∨ ¬A, A ⇒ A, (A ∧ (A ⇒ B)) ⇒ B

Validity is connected to inference via the Deduction Theorem:KB |= α if and only if (KB ⇒ α) is valid

A sentence is satisfiable if it is true in some modele.g., A ∨ B, C

A sentence is unsatisfiable if it is true in no modelse.g., A ∧ ¬A

Satisfiability is connected to inference via the following:KB |= α if and only if (KB ∧ ¬α) is unsatisfiable

i.e., prove α by reductio ad absurdum

AIMA 3rd ed. - Chapter 7 48

Page 49: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Propositional inference: Enumeration method

Let α = A ∨B and KB = (A ∨ C) ∧ (B ∨ ¬C)

Is it the case that KB |= α?Check all possible models—α must be true wherever KB is true

A B C A ∨ C B ∨ ¬C KB α

False False False

False False True

False True False

False True True

True False False

True False True

True True False

True True True

AIMA 3rd ed. - Chapter 7 49

Page 50: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Propositional inference: Enumeration method

Let α = A ∨B and KB = (A ∨ C) ∧ (B ∨ ¬C)

Is it the case that KB |= α?Check all possible models: α must be true wherever KB is true

A B C A ∨ C B ∨ ¬C KB α

False False False False True False False

False False True True False False False

False True False False True False True

False True True True True True True

True False False True True True True

True False True True False False True

True True False True True True True

True True True True True True True

Note that this is equivalent to proving that the sentence((A ∨ C) ∧ (B ∨ ¬C) ⇒ A ∨B is a valid sentence!

AIMA 3rd ed. - Chapter 7 50

Page 51: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Complexity of inference

Truth table method: 2N rows of table for any proof involving N symbols

Linear space requirements though using Depth-First search.

AIMA 3rd ed. - Chapter 7 51

Page 52: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Inference

An inference procedure that generates only entailed sentences is called sound

An inference procedure that generates all sentences that can be entailed iscalled complete

Formally:

KB ⊢i α = sentence α can be derived from KB by procedure i

Soundness: i is sound ifwhenever KB ⊢i α, it is also true that KB |= α

Completeness: i is complete ifwhenever KB |= α, it is also true that KB ⊢i α

AIMA 3rd ed. - Chapter 7 52

Page 53: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Rules of Inference

Instead of enumeration method, we can also use inference rules that we knoware sound. We list these rules as:

αβ

Notation: Whenever a sentence in the KB matches the pattern above theline (α), the inference rule can conclude the sentence below the line (β).

AIMA 3rd ed. - Chapter 7 53

Page 54: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Application: Propositional inference in the Wumpus world

Assume the following situation:

BG

PS

W

A = Agent = Breeze = Glitter, Gold

= Pit = Stench

= Wumpus

OK = Safe square

V = Visited

B P!

A

OK OK

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

V

SOK

W!

V

How does the agent know where to go?

AIMA 3rd ed. - Chapter 7 54

Page 55: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Complete Set of Inference rules for propositional logic

Modus Ponens (or implication elimination)

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

β

And-elimination (from a conjunction, you can infer any of the conjuncts)

α1 ∧ · · · ∧ αn

αi

Unit resolution (from a disjunction, if one of the disjuncts are false, you caninfer the other one is true)

α ∨ β ¬β

α

Resolution (for CNF): complete for propositional logic

α ∨ β, ¬β ∨ γ

α ∨ γ

AIMA 3rd ed. - Chapter 7 55

Page 56: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Normal forms

Other approaches to inference use syntactic operations on sentences whichare often expressed in standardized forms:

Horn Form (restricted)conjunction of Horn clauses (clauses with ≤ 1 positive literal)E.g., (A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)Often written as set of implications:B ⇒ A and (C ∧D) ⇒ B

Disjunctive Normal Form (DNF—universal)disjunction of conjunctions of literals

︸ ︷︷ ︸

terms

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

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

︸ ︷︷ ︸

clauses

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

AIMA 3rd ed. - Chapter 7 56

Page 57: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

♦ Resolution requires the Conjunctive Normal Form.

♦ Every sentence can be written in CNF.

AIMA 3rd ed. - Chapter 7 57

Page 58: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Resolution

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

︸ ︷︷ ︸

clauses

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

Resolution inference rule (for CNF): complete for propositional logic

ℓ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

AIMA 3rd ed. - Chapter 7 58

Page 59: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Resolution algorithm

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

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

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

AIMA 3rd ed. - Chapter 7 59

Page 60: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Resolution example

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

Add the negation of the sentence you want to prove (e.g. ¬¬P1,2) and seeif you reach a contradiction:

AIMA 3rd ed. - Chapter 7 60

Page 61: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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

AIMA 3rd ed. - Chapter 7 61

Page 62: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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)

AIMA 3rd ed. - Chapter 7 62

Page 63: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Restricted Forms: Horn Form

The completeness of resolution makes it a very important inference method.In many practical situations however, the full power of resolution is notneeded.

Horn Form (restricted): A KB is said to be in Horn Form if it is a conjunctionof Horn clauses.

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

Alternative definition: a Horn clause is a disjunction of literals of which at

most one is positive

Example KB: C ∧ (B ⇒ A) ∧ (C ∧D ∧ E ⇒ B)Terminology: premise ⇒ conclusion

AIMA 3rd ed. - Chapter 7 63

Page 64: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Restricted Forms: Horn Form

The Horn form seems very restricted, but many real databases can be writtenin Horn form. How?

♦ Definite clauses: with exactly one positive literal

e.g.: (C ∧D ⇒ B)

♦ Facts: a definite clause with no negative literals simply asserts a givenproposition

e.g.: C

♦ Integrity constraints: a Horn clause with no positive literals

e.g.: ¬(W11 ∧W22)

AIMA 3rd ed. - Chapter 7 64

Page 65: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Restricted Forms: Horn Form

How can you convert each sentence into an implication?

(W11 ∧W22) ⇒ False

AIMA 3rd ed. - Chapter 7 65

Page 66: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Restricted Forms: Horn Form

Modus Ponens is complete for Horn KBs (not in general)

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

β

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

They are also sound (easy to show) and complete (slightly more complicatedargument).

AIMA 3rd ed. - Chapter 7 66

Page 67: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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

AIMA 3rd ed. - Chapter 7 67

Page 68: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining algorithm

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

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 to be true

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

AIMA 3rd ed. - Chapter 7 68

Page 69: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

P

M

L

BA

2 2

2

2

1

AIMA 3rd ed. - Chapter 7 69

Page 70: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

P

M

L

B

2

1

A

1 1

2

AIMA 3rd ed. - Chapter 7 70

Page 71: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

P

M

2

1

A

1

B

0

1L

AIMA 3rd ed. - Chapter 7 71

Page 72: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

P

M

1

A

1

B

0

L0

1

AIMA 3rd ed. - Chapter 7 72

Page 73: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

1

A

1

B

0

L0

M

0

P

AIMA 3rd ed. - Chapter 7 73

Page 74: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

A B

0

L0

M

0

P

0

0

AIMA 3rd ed. - Chapter 7 74

Page 75: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

Q

A B

0

L0

M

0

P

0

0

AIMA 3rd ed. - Chapter 7 75

Page 76: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Forward chaining example

A B

0

L0

M

0

P

0

0

Q

AIMA 3rd ed. - Chapter 7 76

Page 77: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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

The algorithm is essentially identical to the AND-OR-GRAPH search givenin Fig. 4.11.

AIMA 3rd ed. - Chapter 7 77

Page 78: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

Q

P

M

L

A B

AIMA 3rd ed. - Chapter 7 78

Page 79: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

P

M

L

A

Q

B

AIMA 3rd ed. - Chapter 7 79

Page 80: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

M

L

A

Q

P

B

AIMA 3rd ed. - Chapter 7 80

Page 81: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

M

A

Q

P

L

B

AIMA 3rd ed. - Chapter 7 81

Page 82: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

M

L

A

Q

P

B

AIMA 3rd ed. - Chapter 7 82

Page 83: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

M

A

Q

P

L

B

AIMA 3rd ed. - Chapter 7 83

Page 84: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

M

A

Q

P

L

B

AIMA 3rd ed. - Chapter 7 84

Page 85: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

A

Q

P

L

B

M

AIMA 3rd ed. - Chapter 7 85

Page 86: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

A

Q

P

L

B

M

AIMA 3rd ed. - Chapter 7 86

Page 87: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

A

Q

P

L

B

M

AIMA 3rd ed. - Chapter 7 87

Page 88: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Backward chaining example

A

Q

P

L

B

M

AIMA 3rd ed. - Chapter 7 88

Page 89: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

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

AIMA 3rd ed. - Chapter 7 89

Page 90: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Satisfiability Problem

Satisfiability problem (is this sentence satisfiable?) is at the core of manygeneral problems (e.g. constraint satisfaction problems).

Satisfiability can be checked by enumerating the possible models until oneis found that satisfies the sentence using depth-first enumeration of possiblemodels.

However, determining the satisfiability of sentences in propositional logic wasthe first problem proved to be NP-complete.

AIMA 3rd ed. - Chapter 7 90

Page 91: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Davis-Putnam (or DPLL) Algorithm

♦ Recursive, depth-first enumeration of possible models,

♦ similar to TT-ENTAILS but with important improvements such as earlytermination...

DPLL algorithm is one of the fastest satisfiability algorithms, despite the factthat it is very old. It can solve hardware verification problems with a millionvariables.

AIMA 3rd ed. - Chapter 7 91

Page 92: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Local search algorithms

We can use local search algorithms for satisfiability problems, as well.

Since each clause in the sentence needs to be satisfied, evaluation functionshould count the number of unsatisfied clauses (e.g. min-conflict heuristic).

WALKSAT algorithm is one of the most effective algorithms.

AIMA 3rd ed. - Chapter 7 92

Page 93: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

WALKSAT algorithm

♦ In each iteration, pick an unsatisfied clause and picks a symbol to flip.

♦ Two ways to decide how to choose the symbol:

- randomly select the symbol from the clause and flip it with probability p

- pick one that minimizes the number of unsatisfied clauses in the new state

AIMA 3rd ed. - Chapter 7 93

Page 94: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Local search algorithms

In underconstrained situations, solutions are easy to find.

Ex. A 3-CNF with 5 symbols and 5 clauses:

(¬D ∨ ¬B ∨ C) ∧ (B ∨ ¬A ∨ ¬C) ∧ (¬C ∨ ¬B ∨ E)∧ (E ∨ ¬D ∨B) ∧ (B ∨ E ∨ ¬C)

How many solutions?

What makes it a hard satisfiability problem?

What if WALKSAT returns failure?

AIMA 3rd ed. - Chapter 7 94

Page 95: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Local search algorithms

In underconstrained situations, solutions are easy to find.

Ex. A 3-CNF with 5 symbols and 5 clauses:

(¬D ∨ ¬B ∨ C) ∧ (B ∨ ¬A ∨ ¬C) ∧ (¬C ∨ ¬B ∨ E)∧ (E ∨ ¬D ∨B) ∧ (B ∨ E ∨ ¬C)

How many solutions?

16 of the 32 possible worlds are models for this sentence!

What makes it a hard satisfiability problem?

How constrained it is (w.r.t number of constraints and number of variables)

What if WALKSAT returns failure?

We cannot tell if the sentence is unsatisfiable or just WALKSAT needs moretime.

AIMA 3rd ed. - Chapter 7 95

Page 96: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Shortcomings of PL

Lack of Expressive Efficiency:

We need to state the general rule about breeze and pits as a separate sentencefor each square:

B11 ⇒ P21 ∨ P12

B21 ⇒ P11 ∨ P22 ∨ P31

AIMA 3rd ed. - Chapter 7 96

Page 97: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Shortcomings of PL - Fluents

Fluents: changing aspects of the world

E.g. Keeping track of location and orientation.

Let Lij be a location proposition. Then we would like to say something like:

L11 ∧ FacingRight ∧ Forward ⇒ L21

But then we will have both L11 and L21 in the database!

AIMA 3rd ed. - Chapter 7 97

Page 98: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Shortcomings of PL - Fluents

Solution: Associate propositions with time steps:

L011, FacingEast0, HaveArrow0...

After associating time with prepositions, we need axioms to keep track ofthese fluents:

Ltxy ⇒ (Breezet ⇔ Breezexy)

Effect axioms:

L011 ∧ FacingEast0 ∧ Forward0 ⇒ (L1

21 ∧ ¬L111)

We would need one such sentence for each possible time step and eachpossible square and orientation!

AIMA 3rd ed. - Chapter 7 98

Page 99: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Shortcomings of PL - Frame Problem

We still have other problems. The effect axioms fail to state what is un-

changed as the result of an action.

E.g. That the agent still has an arrow.

One possible solution is to add frame axioms explicitly asserting all thepropositions that remain the same:

Forwardt ⇒ (HaveArrowt ⇔ HaveArrowt+1)

Forwardt ⇒ (WumpusAlivet ⇔ WumpusAlivet+1)

...

AIMA 3rd ed. - Chapter 7 99

Page 100: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Shortcomings of Propositional Logic - Representational Frame Problem

The proliferation of frame axioms is very inefficient and this problem was asignificant problem for AI researchers.

Solution: Focusing from writing axioms about actions to writing axiomsabout fluents (successor-state axioms): HaveArrowt+1 ⇔ (HaveArrowt∧¬Shoott)

Lt+111 ⇔ (Lt

11 ∧ (¬Forwardt ∨Bumpt+1))∨(Lt

12 ∧ (¬FacingSoutht ∧ Forwardt))∨(Lt

21 ∧ (¬FacingWestt ∧ Forwardt)).

AIMA 3rd ed. - Chapter 7 100

Page 101: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Summary

Logical agents apply inference to a knowledge baseto derive new information and make decisions

Basic concepts of logic:– syntax: formal structure of sentences– semantics: truth of sentences wrt models– entailment: necessary truth of one sentence given another– inference: deriving sentences from other sentences– soundess: derivations produce only entailed sentences– completeness: derivations can produce all entailed sentences

Wumpus world requires the ability to represent partial and negated infor-mation, reason by cases, etc. Propositional logic suffices for some of thesetasks.

Truth table method is sound and complete for propositional logic.

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

AIMA 3rd ed. - Chapter 7 101

Page 102: Logical agents - Sabancı Üniversitesipeople.sabanciuniv.edu/berrin/cs404/lectures/chapter07-new.pdf · -Chapter7 37. Representation We know of some knowledge representation languages:

Resolution is complete for propositional logic.

Propositional logic lacks expressive power

AIMA 3rd ed. - Chapter 7 102