Agents that Reason Logically

Download Report

Transcript Agents that Reason Logically

Class Project




Due at end of finals week
Essentially anything you want, so long
as its AI related and I approve
Any programming language you want
In pairs or individual
Class Project

Examples:





Implement a game player
Implement supervised learning algorithms
Use a series of learning methods to classify
existing data
....?
Email me by Monday to tell me what
you’re doing, and who you’re working
with
Agents that Reason Logically

Logical agents have a knowledge base, from
which they draw conclusions about how to
act



Can perceive agent at different levels:



TELL: provide new facts to the agent
ASK: decide on appropriate action
Knowledge level (logical): What the agent “knows”
Implementation level: How the information is
actually stored internally in the computer
We will concentrate on the logical level
Sample: Wumpus World

Show sample wumpus game



goal is to shoot wumpus
example of logical reasoning
Textbook example


http://baldur.mm.rpi.edu/otter/wumpus/W
umpus.html
goal is to find gold and avoid wumpus, and
climb back out of cave
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
The use of logic

A logic is a formal language for
representing information, and rules for
drawing conclusions


Syntax: what “sentences” are legal
Semantics: what the sentences “mean”


What is true in a particular world and what isn’t
Arithmetic examples:

x+2 >= y is a sentence, x+2 > isn’t
Two kinds of logics we’ll
consider

Propositional Logic (Chap 6)


Represents facts
P Q  R
First Order Logic (Chap 7)

Represents facts, objects, and relations
x Cat( x)  Mammal( x)
Entailment

At any given time, we have a knowledge base
of information




If I were a train, I’d be late
If I were a rule, I would bend
I am a rule
The knowledge base KB entails a means a is
true in all worlds where KB is true


e.g. if a = “I would bend”
KB
a
Models and soundness

A world m is a model of a sentence a if a is
true in m



Rules of inference allow us to derive new
sentences entailed by a knowledge base


a = It is raining today
a = The wumpus is not in (2,2)
Rules of inference must be sound: sentences
inferred by a KB should be entailed by that KB
What is a non-sound inference?

Video
Propositional Logic: Syntax
Propositional Logic: Semantics
Inference by Enumeration
Enumeration Solution: is a
entailed by KB?
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
Common inference rules for
propositional logic

Modus Ponens (Implication-Elimination)
a  , a

And-Elimination

a1  a2  a3   an

 ai
And-Introduction
a1, a 2 , a3 ,, an
 a1  a 2  a3  a n
 “Or Introduction”
ai
 a1  a 2  a3   a n
Common inference rules for
propositional logic



Double-Negation Elimination
 a
 a
Unit Resolution
a   , 
 a
Resolution
a   ,   
a   ,   

a  
 a 
A propositional logic agent in
Wumpus World


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
Glitter – gold is here
Bump – agent has just bumped against a wall
Scream – agent has heard another player die
Wumpus Agent

Actions



Forward, Turn Left, Turn Right
Grab (gold)
Shoot (shoots arrow forward until hits
wumpus or wall)


agent only has one arrow
Climb (exit the cave)
Wumpus Agent

Death


Agent dies if it enters a pit or square with
wumpus
Goal: get gold and climb back out.
Don’t die.



1000 points for climbing out of cave with
gold
1 point penalty for each action taken
10,000 point penalty for death
Example of using logic in
Wumpus World

Stench
Agent
Start Breeze
KB contains:
 S1,1
 B1,1
 S 2 ,1
B2 ,1
S1, 2
 B1, 2
S 2, 2
 B2 , 2
KB also contains knowledge of
environment

No stench  no wumpus nearby
R1 : S1,1  W1,1  W1, 2  W2,1
R2 : S 2,1  W1,1  W2,1  W2, 2  W3,1
R3 : S1, 2  W1,1  W1, 2  W2, 2  W1,3

Stench  wumpus nearby
R4 : S1,2  W1,1  W1,2  W2,2  W1,3
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!
We can determine where
wumpus is!

Method 2: Inference

Modus Ponens
R1 : S1,1  W1,1  W1, 2  W2,1
W1,1  W1, 2  W2,1

And-Elimination
W1,1 W1,2 W2,1
Inference continued...

Modus Ponens and And-Elimination again:
R2 : S 2,1  W1,1  W2,1  W2, 2  W3,1
W1,1 W2,1 W2, 2 W3,1

One more Modus Ponens:
R4 : S1, 2  W1,1  W1, 2  W2, 2  W1,3
W1,1  W1, 2  W2, 2  W1,3
Inference continued...

Unit Resolution:
W1,1  W1, 2  W2, 2  W1,3
W1,1
W1, 2  W2, 2  W1,3
W2, 2
W1, 2  W1,3
W1, 2
W1,3
Wumpus is in (1,3)!!!
Shoot it. Shoot where?
Determining action based on
knowledge
A1, 2  W1,3  ForwardA  Shoot
A1, 2  P1,3  ForwardA  Forward


Propositional logic cannot answer
question “What action should I take?”
It only answers “Should I take action
X?”
Propositional logic doesn’t cut
the mustard in this application

Rule: “Shoot if the wumpus is in front
of you”


Agent needs to know where it was, to
backtrack



16 x 4 = 64 rules for the 4x4 grid
A1,1  A11,1 , A21,1 , A31,1, etc.
superscript is time index
64 rules over 100 time units :

6400 rules  explodes wide open
First-order logic to the rescue



Uses variables to represent generalities
Can reduce those 6400 rules down to 1
 on to Chapter 7