29
Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate action

Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Agents that Reason Logically

Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate action

Page 2: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Sample: Wumpus World Show original wumpus game

goal is to shoot wumpus example of logical reasoning http://www.inthe70s.com/games/wum

pus/index.shtml Our version:

Kill the wumpus.

Page 3: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

A Wumpus Agent Agent does not perceive its own

location (unlike sample game), but it can keep track of where it has been

Percepts: Stench – wumpus is nearby Breeze – pit is nearby

Page 4: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Wumpus Agent Actuators:

Forward, Turn Left, Turn Right Shoot (shoots arrow forward until hits

wumpus or wall) Environment:

4x4 grid, start at (1,1) facing right

Page 5: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Wumpus Agent Death

Agent dies if it enters a pit or square with wumpus

Goal: kill wumpus

Page 6: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Some complex reasoning examples

Start in (1,1) Breeze in (1,2) and (2,1) Probably a pit in (2,2)

Smell in (1,1) – where can you go? Pick a direction – shoot Walk in that direction Know where wumpus is

Page 7: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

The use of logic A logic: formal language for

representing information, rules for drawing conclusions

Two kinds of logics: Propositional Logic (Chap 7)

Represents facts

First Order Logic (Chap 8) Represents facts, objects, and relations

RQP

)()( xMammalxCatx

Page 8: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Soundness Rules of inference allow us to derive

new sentences entailed by a knowledge base Rules of inference must be sound:

sentences inferred by a KB should be entailed by that KB

What is a non-sound inference? Video

Page 9: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Entailment At any given time, we have a knowledge

base of information If Jan likes ice cream, we would share tastes If we share tastes, I would like to know Jan

better Jan likes ice cream

The knowledge base KB entails means is true in all worlds where KB is true e.g. if = “I would like to know Jan better” KB

Page 10: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Propositional Logic: Semantics

Page 11: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Inference by Enumeration

Page 12: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Enumeration Solution: is entailed by KB?

Page 13: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Enumeration is too computationally intense

For n proposition symbols, enumeration takes 2n rows (exponential)

Inference rules allow you to deduce new sentences from the KB Can use inference rules as operators

in a standard search algorithm Think of testing if something as true

as searching for it

Page 14: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Modus Ponens (Implication-Elimination)

And-Elimination

And-Introduction

“Or Introduction”

Common inference rules for propositional logic

,

in 321

nn 321321 ,,,,

ni 321

Page 15: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Double-Negation Elimination

Unit Resolution

Resolution

Common inference rules for propositional logic

,

,

,

Page 16: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Example of using logic in Wumpus World

StenchAgent

Start Breeze

KB contains:

2,2

2,1

1,2

1,1

S

S

S

S

2,2

2,1

1,2

1,1

B

B

B

B

Page 17: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

KB also contains knowledge of environment

No stench no wumpus nearby

Stench wumpus nearby

3,12,22,11,12,13

1,32,21,21,11,22

1,22,11,11,11

:

:

:

WWWWSR

WWWWSR

WWWSR

3,12,22,11,12,14 : WWWWSR

Page 18: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

We can determine where wumpus is!

Method 1: Truth table At least 14 symbols currently: S1,1, S2,1,

S1,2, S2,2, W1,1, W2,1, W1,2, W2,2, W3,1, W1,3,

B1,1, B2,1, B1,2, B2,2

214 rows, ouch!

Page 19: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

We can determine where wumpus is!

Method 2: Inference Modus Ponens

And-Elimination

1,22,11,1

1,22,11,11,11 :

WWW

WWWSR

1,22,11,1 WWW

Page 20: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Inference continued... Modus Ponens and And-Elimination

again:

One more Modus Ponens:

1,32,21,21,1

1,32,21,21,11,22 :

WWWW

WWWWSR

3,12,22,11,1

3,12,22,11,12,14 :

WWWW

WWWWSR

Page 21: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Inference continued... Unit Resolution:

3,1

2,1

3,12,1

2,2

3,12,22,1

1,1

3,12,22,11,1

W

W

WW

W

WWW

W

WWWW

Wumpus is in (1,3)!!!Shoot it. Shoot where?

Page 22: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Determining action based on knowledge

Propositional logic cannot answer well the question “What action should I take?”

It only answers “Should I take action X?”

ForwardForwardPA

ShootForwardWA

A

A

3,12,1

3,12,1

Page 23: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Propositional logic seems inefficient

Rule: “Shoot if the wumpus is in front of you” 16 x 4 = 64 rules for the 4x4 grid

Ditto for pits First order logic is much more

efficient

Page 24: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

First-Order Logic: Better choice for Wumpus World

Propositional logic represents facts First-order logic gives us

Objects Relations: how objects relate to each

other Functions: return value for given

input

Page 25: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Syntax and Semantics First-order logic has the following:

Constants: represent objects book, A, cs327

Predicates: represent relations OlderSibling(Lisa,Bart) OlderSibling(Maggie,Lisa) OlderSibling(Maggie,Bart)

Functions FatherOf(Luke) = Anakin

Page 26: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Syntax and Semantics Atomic Sentences

Father(Luke,Anakin) Siblings(SonOf(Anakin),

DaughterOf(Anakin)) Complex Sentences

and, or, not, implies, equivalence

Equality

( , ) ( , )Father Luke Anakin Father Leia Anakin

)( ntDaveMusicaardDaveAppley

Page 27: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Universal Quantification “For all, for every”: Examples:

Usually use with Common mistake to use

)(),(

)()(

xWitchDuckxAsWeighsSamex

xMammalxCatx

)(),( xSmartCarletonxAtx

Page 28: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

Existential Quantification “There exists”:

Typically use with Common mistake to use

)()( LukexxverseHopeForUnix

)(),( xSmartCarletonxAtx

Page 29: Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate

First-Order Logic in Wumpus World

Suppose an agent perceives a stench, breeze, at time t = 5: Percept([Stench,Breeze],5) [Stench,Breeze] is a list

Then want to query for an appropriate action. Find an a (ask the KB):

?)5,(aBestActiona