Logical agents
Download
1 / 84

Logical Agents - PowerPoint PPT Presentation


  • 96 Views
  • Updated On :

Logical Agents. Russell and Norvig: Chapter 7 CMSC 421 – Fall 2006. “Thinking Rationally”. Computational models of human “thought” processes Computational models of human behavior Computational systems that “think” rationally Computational systems that behave rationally. sensors.

Related searches for Logical Agents

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Logical Agents' - sandra_john


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Logical agents l.jpg

Logical Agents

Russell and Norvig: Chapter 7CMSC 421 – Fall 2006


Thinking rationally l.jpg
“Thinking Rationally”

  • Computational models of human “thought” processes

  • Computational models of human behavior

  • Computational systems that “think” rationally

  • Computational systems that behave rationally


Knowledge based agent l.jpg

sensors

environment

?

agent

actuators

Knowledge base

Inference Engine

Domain-independent algorithms

Knowledge-Based Agent

Domain-specific content


Logical agents4 l.jpg
Logical Agents

  • Reflex agents find their way from Arad to Bucharest by dumb luck

  • Chess program calculates legal moves of its king, but doesn’t know that no piece can be on 2 different squares at the same time

  • Logic (Knowledge-Based) agents combine general knowledge with current percepts to infer hidden aspects of current state prior to selecting actions

    • Crucial in partially observable environments


Outline l.jpg
Outline

  • Knowledge-based agents

  • Wumpus world

  • Logic in general

  • Propositional and first-order logic

    • Inference, validity, equivalence and satisfiability

    • Reasoning patterns

      • Resolution

      • Forward/backward chaining


Knowledge base l.jpg
Knowledge Base

Knowledge Base: set of sentences represented in a knowledge representation language and represents assertions about the world.

Inference rule: when one ASKs questions of the KB, the answer should follow from what has been TELLed to the KB previously.

ask

tell



Abilities kb agent l.jpg
Abilities KB agent

  • Agent must be able to:

    • Represent states and actions,

    • Incorporate new percepts

    • Update internal representation of the world

    • Deduce hidden properties of the world

    • Deduce appropriate actions


Description level l.jpg
Description level

  • The KB agent is similar to agents with internal state

  • Agents can be described at different levels

    • Knowledge level

      • What they know, regardless of the actual implementation. (Declarative description)

    • Implementation level

      • Data structures in KB and algorithms that manipulate them e.g propositional logic and resolution.


Types of knowledge l.jpg
Types of Knowledge

  • Procedural, e.g.: functionsSuch knowledge can only be used in one way -- by executing it

  • Declarative, e.g.: constraints and rulesIt can be used to perform many different sorts of inferences


The wumpus world l.jpg
The Wumpus World

  • The Wumpus computer game

  • The agent explores a cave consisting of rooms connected by passageways.

  • Lurking somewhere in the cave is the Wumpus, a beast that eats any agent that enters its room.

  • Some rooms contain bottomless pits that trap any agent that wanders into the room.

  • Occasionally, there is a heap of gold in a room.

  • The goal is to collect the gold and exit the world without being eaten


History of hunt the wumpus l.jpg
History of “Hunt the Wumpus”

  • WUMPUS /wuhm'p*s/ n. The central monster (and, in many versions, the name) of a famous family of very early computer games called “Hunt The Wumpus,” dating back at least to 1972 (several years before ADVENT) on the Dartmouth Time-Sharing System. The wumpus lived somewhere in a cave with the topology of a dodecahedron's edge/vertex graph (later versions supported other topologies, including an icosahedron and Mobius strip). The player started somewhere at random in the cave with five “crooked arrows”; these could be shot through up to three connected rooms, and would kill the wumpus on a hit (later versions introduced the wounded wumpus, which got very angry). Unfortunately for players, the movement necessary to map the maze was made hazardous not merely by the wumpus (which would eat you if you stepped on him) but also by bottomless pits and colonies of super bats that would pick you up and drop you at a random location (later versions added “anaerobic termites” that ate arrows, bat migrations, and earthquakes that randomly changed pit locations).

  • This game appears to have been the first to use a non-random graph-structured map (as opposed to a rectangular grid like the even older Star Trek games). In this respect, as in the dungeon-like setting and its terse, amusing messages, it prefigured ADVENT and Zork and was directly ancestral to both. (Zork acknowledged this heritage by including a super-bat colony.) Today, a port is distributed with SunOS and as freeware for the Mac. A C emulation of the original Basic game is in circulation as freeware on the net.


Wumpus peas description l.jpg
Wumpus PEAS description

  • Performance measure:gold +1000, death -1000, -1 per step, -10 use arrow

  • Environment:Squares adjacent to wumpus are smellySquares adjacent to pit are breezyGlitter iff gold is in the same squareBump iff move into a wallWoeful scream iff the wumpus is killedShooting 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

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

  • Actuators: Let turn, Right turn, Forward, Grab, Release, Shoot


A typical wumpus world l.jpg
A typical Wumpus world

  • The agent always starts in [1,1].

  • The task of the agent is to find the gold, return to the field [1,1] and climb out of the cave.


Wumpus world characteristics l.jpg
Wumpus World Characteristics

  • Observable?

  • Deterministic?

  • Episodic or Sequential?

  • Static?

  • Discrete?

  • Single-agent?


Wumpus world characterization l.jpg
Wumpus World Characterization

  • Observable?

    • No, only local perception

  • Deterministic?

    • Yes, outcome 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.


The wumpus agent s first step l.jpg
The Wumpus agent’s first step

[1,1] The KB initially contains the rules of the environment. The first percept is [none, none,none,none,none], move to safe cell e.g. 2,1

[2,1] breeze which indicates that there is a pit in [2,2] or [3,1], return to [1,1] to try next safe cell


Slide18 l.jpg
Next….

[1,2] Stench in cell which means that wumpus is in [1,3] or [2,2]

YET … not in [1,1]

YET … not in [2,2] or stench would have been detected in [2,1]

THUS … wumpus is in [1,3]

THUS [2,2] is safe because of lack of breeze in [1,2]

THUS pit in [3,1]

move to next safe cell [2,2]


Slide19 l.jpg
Then…

[2,2] move to [2,3]

[2,3] detect glitter , smell, breeze

THUS pick up gold

THUS pit in [3,3] or [2,4]


World wide web wumpi l.jpg
World-wide web wumpi

  • http://en.wikipedia.org/wiki/Hunt_the_Wumpus

  • http://www.atariarchives.org/bcc1/showpage.php?page=247

  • http://www.ifiction.org/games/play.phpz

  • http://www.taylor.org/~patrick/wumpus/

  • http://www.inthe70s.com/games/wumpus/index.shtml#


What is a logic l.jpg
What is a logic?

  • A formal language

    • Syntax – what expressions are legal (well-formed)

    • Semantics – what legal expressions mean

      • in logic the truth of each sentence with respect to each possible world.

  • E.g the language of arithmetic

    • X+2 >= y is a sentence, x2+y is not a sentence

    • X+2 >= y is true in a world where x=7 and y =1

    • X+2 >= y is false in a world where x=0 and y =6


Connection world representation l.jpg

entail

Sentences

Sentences

represent

represent

Conceptualization

World W

Facts about W

Facts about W

hold

hold

Connection World-Representation


Entailment l.jpg
Entailment

  • One thing follows from another

    KB |= 

  • KB entails sentence  if and only if is true in worlds where KB is true.

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

  • Entailment is a relationship between sentences that is based on semantics.


Models l.jpg
Models

  • Models are formal definitions of possible states of the world

  • We say m is a model of a sentence  if  is true in m

  • M() is the set of all models of 

  • Then KB  if and only if M(KB)  M()

M()

M(KB)


Entailment in the wumpus world l.jpg
Entailment in the Wumpus World

  • Situation after detecting nothing in [1,1], moving right, breeze in [2,1]

  • What are possible models for ? – assume only possibility pit or no pit.



Wumpus models27 l.jpg
Wumpus Models

B

B

B

B

B

B

B

B


Wumpus models28 l.jpg
Wumpus Models

B

B

B

B

B

B

B

B


Wumpus models29 l.jpg
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

1=“[1,2] is safe”

KB |=1


Wumpus models30 l.jpg
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

2=“[2,2] is safe”

KB |=2 ??


Wumpus models31 l.jpg
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

2=“[2,2] is safe”

KB |=2 ??


Wumpus models32 l.jpg
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

2=“[2,2] is safe”

KB |=2 NOT!


Logical inference l.jpg
Logical inference

  • The notion of entailment can be used for logic inference.

    • Model checking (see wumpus example): enumerate all possible models and check whether is true.

  • If an algorithm only derives entailed sentences it is called sound or truth preserving.

    • Otherwise it just makes things up.

      i is sound if whenever KB |-i it is also true that KB|= 

  • Completeness : the algorithm can derive any sentence that is entailed.

    i is complete if whenever KB |=  it is also true that KB|-i 


Inference l.jpg
Inference

  • 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 if whenever KB  it is also true that KB |-i 


Examples of logics l.jpg
Examples of Logics

  • Propositiona logicA  B  C

  • First-order logic( x)( y) Mother(y,x)

  • Logic of BeliefB(John,Father(Zeus,Cronus))


Symbols of propositional logic l.jpg
Symbols of Propositional Logic

  • Connectives: , , , 

  • Propositional symbols, e.g., P, Q, R, …

  • True, False


Syntax of propositional logic l.jpg
Syntax of Propositional Logic

  • sentence  atomic sentence | complex sentence

  • atomic sentence  Propositional symbol, True, False

  • Complex sentence  sentence | (sentence  sentence) | (sentence  sentence) | (sentence  sentence)

  • Examples:

    • ((P  Q)  R)

    • (A  B)  (C)


Order of precedence l.jpg
Order of Precedence

  • 

  • Examples:

    •  A  B  C is equivalent to ((A)B)C


Models in propositional logic l.jpg
Models in Propositional Logic

  • Assignment of a truth value – true or false – to every atomic sentence

  • Examples:

    • Let A, B, C, and D be the propositional symbols

    • is m = {A=true, B=false, C=false, D=true} a model?

    • is m’ = {A=true, B=false, C=false} a model?

  • How many models can be defined over n propositional symbols?


Semantics of propositional logic l.jpg
Semantics of Propositional Logic

  • It specifies how to determine the truth value of any sentence in a model m

  • The truth value of True is True

  • The truth value of False is False

  • The truth value of each atomic sentence is given by m

  • The truth value of every other sentence is obtained recursively by using truth tables



About l.jpg
About

  • ODD(5)  CAPITAL(Japan,Tokyo)

  • EVEN(5)  SMART(Sam)

  • Read A  B as:“If A IS True, then I claim that B is True, otherwise I make no claim.”


Wumpus world sentences l.jpg
Wumpus world sentences

  • Pij is true if there is a pit in [i,j]

  • Bij is true if there is a breeze in [i,j]P11B11 B21

  • “A square is breezy if and only if there is an adjacent pit” B11  P12 v P21B21  ???


Terminology l.jpg
Terminology

  • A sentence is valid iff its truth value is t in all models (² f)

    Valid sentences: true, :false, P Ç: P

  • A sentence is satisfiable iff its truth value is t in at least one model

    Satisfiable sentences: P, true, : P

  • A sentence is unsatisfiable iff its truth value is f in all models

    Unsatisfiable sentences: P Æ: P, false, :true


Inference45 l.jpg
Inference

  • KB `i a

  • Soundness: Inference procedure i is sound if whenever KB `i a, it is also true that KB ²a

  • Completeness: Inference procedure i is complete if whenever KB ²a, it is also true that KB `i a


Validity and inference l.jpg
Validity and Inference

((P Ç H) Æ:H) ) P

P

H

((P

H)

H) )

P

P

H

(P

H)

H

Ç

Ç

Æ

:

Ç

Æ

:

T

T

T

F

T

T

F

T

T

T

F

T

T

F

T

F

F

F

F

T


Rules of inference l.jpg
Rules of Inference

  • a`b

  • a b

  • Valid Rules of Inference:

    • Modus Ponens

    • And-Elimination

    • And-Introduction

    • Or-Introduction

    • Double Negation

    • Unit Resolution

    • Resolution


Examples in wumpus world l.jpg

a)ba b

a Æba

aÇb:bÇg a Çg

Examples in Wumpus World

  • Modus Ponens: a)b, a`b(WumpusAhead Æ WumpusAlive) ) Shoot, (WumpusAhead Æ WumpusAlive) ` Shoot

  • And-Elimination: aÆb`a(WumpusAhead Æ WumpusAlive) ` WumpusAlive

  • Resolution: aÇb, :bÇg`aÇg(WumpusDead Ç WumpusAhead), (: WumpusAhead Ç Shoot) ` (WumpusDead Ç Shoot)


Proof using rules of inference l.jpg
Proof Using Rules of Inference

Prove A ) B, (A Æ B) ) C, Therefore A ) C

  • A ) B ´: A Ç B

  • A Æ B ) C ´: (A Æ B) Ç C ´: A Ç: B Ç C

  • So : A Ç B resolves with : A Ç: B Ç C deriving : A Ç C

  • This is equivalent to A ) C


Rules of inference continued l.jpg
Rules of Inference (continued)

  • And-Introductiona1, a2, …, an a1Æa2Æ …Æan

  • Or-Introductionai a1 Ça2Ç …ai … Çan

  • Double Negation::a a

  • Unit Resolution (special case of resolution)aÇb Alternatively: :a)b:b :b a a


Wumpus world kb l.jpg
Wumpus World KB

  • Proposition Symbols for each i,j:

    • Let Pi,j be true if there is a pit in square i,j

    • Let Bi,j be true if there is a breeze in square i,j

  • Sentences in KB

    • “There is no pit in square 1,1”R1: : P1,1

    • “A square is breezy iff pit in a neighboring square”R2: B1,1, (P1,2Ç P2,1)R3: B1,2, (P1,1Ç P1,3Ç P2,2)

    • “Square 1,1 has no breeze”, “Square 1,2 has a breeze”R4: : B1,1R5: B1,2


Inference in wumpus world l.jpg
Inference in Wumpus World

  • Apply biconditional elimination to R2:R6: (B1,1) (P1,2Ç P2,1)) Æ ((P1,2Ç P2,1) ) B1,1)

  • Apply AE to R6:R7: ((P1,2Ç P2,1) ) B1,1)

  • Contrapositive of R7:R8: (: B1,1): (P1,2Ç P2,1))

  • Modus Ponens with R8 and R4 (: B1,1):R9: :(P1,2Ç P2,1)

  • de Morgan:R10: : P1,2Æ: P2,1


Searching for proofs l.jpg
Searching for Proofs

  • Finding proofs is exactly like finding solutions to search problems.

  • Can search forward (forward chaining) to derive goal or search backward (backward chaining) from the goal.

  • Searching for proofs is not more efficient than enumerating models, but in many practical cases, it’s more efficient because we can ignore irrelevant propositions


Full resolution rule revisited l.jpg
Full Resolution Rule Revisited

  • Start with Unit Resolution Inference Rule:

  • Full Resolution Rule is a generalization of this rule:

  • For clauses of length two:


Resolution applied to wumpus world l.jpg
Resolution Applied to Wumpus World

  • At some point we determine the absence of a pit in square 2,2:R13: : P2,2

  • Biconditional elimination applied to R3followed by modus ponens with R5:R15: P1,1Ç P1,3Ç P2,2

  • Resolve R15 and R13:R16: P1,1Ç P1,3

  • Resolve R16 and R1:R17: P1,3


Resolution complete inference procedure l.jpg
Resolution: Complete Inference Procedure

  • Any complete search algorithm, applying only the resolution rule, can derive any conclusion entailed by any knowledge base in propositional logic.

  • Refutation completeness: Resolution can always be used to either confirm or refute a sentence, but it cannot be used to enumerate true sentences.


Conjunctive normal form l.jpg

literals

clause

Conjunctive Normal Form

  • Conjunctive Normal Form is a disjunction of literals.

  • Example:(A Ç B Ç: C) Æ (B Ç D) Æ (: A) Æ (B Ç C)


Cnf example l.jpg
CNF Example

Example: (A Ç B) , (C ) D)

  • Eliminate ,

    ((A Ç B) ) (C ) D)) Æ ((C ) D) ) (A Ç B)

  • Eliminate )

    (: (A Ç B) Ç (: C Ç D)) Æ (: (: C Ç D) Ç (A Ç B) )

  • Drive in negations((: A Æ: B) Ç (: C Ç D)) Æ ((C Æ: D) Ç (A Ç B))

  • Distribute(: A Ç: C Ç D) Æ (: B Ç: C Ç D) Æ (C Ç A Ç B) Æ (: D Ç A Ç B)


Resolution algorithm l.jpg
Resolution Algorithm

  • To show KB ²a, we show (KB Æ:a) is unsatisfiable.

  • This is a proof by contradiction.

  • First convert (KB Æ:a) into CNF.

  • Then apply resolution rule to resulting clauses.

  • The process continues until:

    • there are no new clauses that can be added (KB does not entail a)

    • two clauses resolve to yield empty clause (KB entails a)


Simple inference in wumpus world l.jpg
Simple Inference in Wumpus World

  • KB = R2Æ R4 = (B1,1, (P1,2Ç P2,1)) Æ: B1,1

  • Prove : P1,2 by adding the negation P1,2

  • Convert KB Æ P1,2 to CNF

  • PL-RESOLUTION algorithm


Horn clauses l.jpg
Horn Clauses

  • Real World KB’s are often a conjunction of Horn clauses

  • Horn clause =

    • proposition symbol; or

    • (conjunction of symbols) ) symbol

  • Example:C Æ (B ) A) Æ (C Æ D ) B)


Forward chaining l.jpg
Forward Chaining

  • Fire any rule whose premises are satisfied in the KB.

  • Add its conclusion to the KB until query is found.


Forward chaining example l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example64 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example65 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example66 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example67 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example68 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example69 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining example70 l.jpg
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining l.jpg
Backward Chaining

  • Motivation: Need goal-directed reasoning in order to keep from getting overwhelmed with irrelevant consequences

  • Main idea:

    • Work backwards from query q

    • To prove q:

      • Check if q is known already

      • Prove by backward chaining all premises of some rule concluding q


Backward chaining example l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example73 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example74 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example75 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example76 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example77 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example78 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example79 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example80 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example81 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Backward chaining example82 l.jpg
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B


Forward chaining vs backward chaining l.jpg
Forward Chaining vs. Backward Chaining

  • FC is data-driven—it may do lots of work irrelevant to the goal

  • BC is goal-driven—appropriate for problem-solving


ad