logical agents
Download
Skip this Video
Download Presentation
Logical Agents

Loading in 2 Seconds...

play fullscreen
1 / 84

Logical Agents - PowerPoint PPT Presentation


  • 96 Views
  • Uploaded 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.

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

Logical Agents

Russell and Norvig: Chapter 7CMSC 421 – Fall 2006

thinking rationally
“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
sensors

environment

?

agent

actuators

Knowledge base

Inference Engine

Domain-independent algorithms

Knowledge-Based Agent

Domain-specific content

logical agents4
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
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
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
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
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
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
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
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
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
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
Wumpus World Characteristics
  • Observable?
  • Deterministic?
  • Episodic or Sequential?
  • Static?
  • Discrete?
  • Single-agent?
wumpus world characterization
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
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
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
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
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
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
entail

Sentences

Sentences

represent

represent

Conceptualization

World W

Facts about W

Facts about W

hold

hold

Connection World-Representation
entailment
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
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
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 models29
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

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

KB |=1

wumpus models30
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

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

KB |=2 ??

wumpus models31
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

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

KB |=2 ??

wumpus models32
Wumpus Models

B

B

B

B

B

B

B

B

KB = wumpus world + observations

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

KB |=2 NOT!

logical inference
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
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
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
Symbols of Propositional Logic
  • Connectives: , , , 
  • Propositional symbols, e.g., P, Q, R, …
  • True, False
syntax of propositional logic
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
Order of Precedence
  • 
  • Examples:
    •  A  B  C is equivalent to ((A)B)C
models in propositional logic
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
literals

clause

Conjunctive Normal Form
  • Conjunctive Normal Form is a disjunction of literals.
  • Example:(A Ç B Ç: C) Æ (B Ç D) Æ (: A) Æ (B Ç C)
cnf example
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
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
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
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
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
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example64
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example65
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example66
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example67
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example68
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example69
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining example70
Forward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining
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
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example73
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example74
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example75
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example76
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example77
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example78
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example79
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example80
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example81
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

backward chaining example82
Backward Chaining Example

P ) Q

L Æ M ) P

B Æ L ) M

A Æ P ) L

A Æ B ) L

A

B

forward chaining vs backward chaining
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