Logical Agents Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Logical Agents

Chapter 7
Outline
• Knowledge-based agents
• Wumpus world
• Logic in general - models and entailment
• Propositional (Boolean) logic
Knowledge bases
• Central component of a Knowledge-Based
Agent is a Knowledge-Base
– A set of sentences in a formal language
• Sentences are expressed using a knowledge representation
language

• Two generic functions:


– TELL - add new sentences (facts) to the KB
• “Tell it what it needs to know”
– ASK - query what is known from the KB
• “Ask what to do next”

Both operations may involve Inference i.e deriving new


sentences from old.
Logical Agents
“Logical AI:

• The idea is that an agent can represent knowledge of its


world, its goals and the current situation by sentences in
logic and decide what to do by inferring that a certain
action or course of action is appropriate to achieve its
goals.”
Knowledge bases

• The agent must be able Domain-


Independent
Algorithms
to: Inference Engine
– Represent states and
Knowledge-Base
actions
– Incorporate new percepts
Domain-
– Update internal Specific
Content
representations of the world
– Deduce hidden properties
of the world
– Deduce appropriate actions
A simple knowledge-based agent
Three functions which are executed Every time when
the agent program is called:

1. MAKE_PERCEPT_SENTENCE

constructs a sentence asserting that the agent


perceived the given percept at a given time

2. MAKE_ACTION_QUERY

constructs a sentence that asks what actions should


be done at the current time.

3. MAKE_ACTION_SENTENCE

constructs a sentence asserting that the chosen


action was executed.
Knowledge-Based Agents
• Declarative
– You can build a knowledge-based agent simply by
“TELLing” it what it needs to know.

– Starting with an empty knowledge base, the agent


designer can TELL sentences one by one until the
agent knows how to operate in its environment.
• Procedural
– Encode desired behaviors directly as program
code
• Minimizing the role of explicit representation and
reasoning can result in a much more efficient
system
Wumpus World
We now describe an environment in which knowledge-based
agents can show their
worth.
• The Wumpus World is a cave consisting of rooms
connected by passageways. Lurking somewhere in the
cave is the terrible wumpus, a beast that eats anyone who
enters its room.

• The wumpus can be shot by an agent, but the agent has


only one arrow. Some rooms contain bottomless pits that
will trap anyone who wanders into these rooms (except
for the wumpus,which is too big to fall in).

• The only mitigating feature of this bleak environment is


the possibility of finding a heap of gold.
Wumpus World PEAS description
• Performance measure
– +1000 for climbing out of the cave with the gold,
– –1000 for falling into a pit or being eaten by the wumpus,
– –1 for each action taken and –10 for using up the arrow.
– The game ends either when the agent dies or when the agent climbs
out of the cave.
• Environment
• 4*4 grid of rooms. Agent starts in square labeled [1,1] .
– Squares adjacent to wumpus are smelly
– Squares adjacent to pit are breezy
– Glitter iff gold is in the same square
– Shooting kills wumpus if you are facing it
– Shooting uses up the only arrow
– Grabbing picks up gold if in same square
– Releasing drops the gold in same square
Continue…..

Sensors: Stench, Breeze, Glitter, Bump (when walks into the wall),
Scream (when the Wumpus is killed)

Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot


Wumpus world characterization
• Fully Observable No – only local perception
• Deterministic Yes – the next state of the environment is
completely determined by the current state of the environment and the
action of the agent;

• Episodic No it’s sequential at the level of actions


• Static Yes – Wumpus and Pits do not change
while thinking
• Discrete Yes - number of distinct percepts and
actions is limited
• Single-agent? Yes – Wumpus is essentially a
natural feature
Exploring a wumpus world

[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


Exploring a wumpus world

[2,1] = breeze

indicates that there is a pit in [2,2] or [3,1],

return to [1,1] to try next safe cell


Exploring a wumpus world

[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]
(this is relatively sophisticated reasoning!)
Exploring a wumpus world

[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]
(this is relatively sophisticated reasoning!)
THUS … wumpus is in [1,3]
THUS [2,2] is safe because of lack of breeze in [1,2]
THUS pit in [1,3] (again a clever inference)
move to next safe cell [2,2]
Exploring a wumpus world

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

[2,3] detect glitter , smell, breeze


THUS pick up gold
THUS pit in [3,3] or [2,4]
Logic in general
• Logics are formal languages for representing information
such that conclusions can be drawn

• Knowledge bases consist of sentences in a formal


language

– Syntax defines the sentences in the language

– Semantics define the "meaning" of sentences;


• i.e., The truth of each sentence with respect to
each possible world (model)
Logic in general
• Example:

x + 2 >= y is a sentence

x2 + y > is not a sentence

x + 2 >= y is true iff x + 2 is no less than y

x + 2 >= y is true in a world where x = 7, y=1

x + 2 >= y is false in world where x = 0, y =6

Formally, the possible models are just all possible assignments of


real numbers to the variables x and y. Each such assignment fixes
the truth of any sentence of arithmetic whose variables are x and y.
If a sentence α is true in SATISFACTION model m, we say that m
satisfies α or sometimes m is a model of α.
Logic in general
• Now that we have a notion of truth, we are ready to talk about
logical reasoning.

• This involves the relation of logical ENTAILMENT between


sentences—the idea that a sentence follows logically from another
sentence.
• In mathematical notation, we write,
α |= β
to mean that the sentence α entails the sentence β.
Logic
• Entailment means that one thing (sentence)
follows logically from another sentence.
 |= 

•  |=  if in every model in which  is true,  is


also true

• if  is true, then  must be true

• the truth of  is “contained” in the truth of 


Logic
• A model is a formally
structured world with M()
respect to which truth can x x x x x xx xx xxx
be evaluated x xx x x xx xxx
– M is a model of sentence  x x x x x x x x xxxxx xxx
xxx x x xx x x x xxx
if  is true in m
xxx x x x x x x x xxx
x xxx xxx x xxxx
• Then KB |=  if M(KB) 
M()

Entailment is a relationship between sentences (i.e.,


syntax) that is based on semantics
Logic
Entailment in the wumpus world
Situation after detecting
nothing in [1,1], moving
right, breeze in [2,1]

Consider possible models for


KB assuming only pits

3 Boolean choices  8
possible models
Wumpus models

Each of the three squares might or might not contain a pit, so (for the
purposes of this example) there are 23 = 8 possible models.
Wumpus models

• KB = wumpus-world rules + observations


• The KB is false in models that contradict what the agent knows—
for example, the KB is false in any model in which [1,2] contains a pit,
because there is no breeze in [1,1].
• There are in fact just three models in which the KB is true, and
these are shown surrounded by a solid line
Wumpus models

• KB = wumpus-world rules + observations

Now let us consider first possible conclusion:


• α1 = "[1,2] is safe",
• in every model in which KB is true, α1 is also true, hence
KB ╞ α1, proved by model checking - there is no pit in
[1,2].
Wumpus models

• KB = wumpus-world rules + observations


Wumpus models

• KB = wumpus-world rules + observations


• let us consider another possible conclusions:
• α2 = "[2,2] is safe",
• We can also see that in some models in which
KB is true, α2 is false, hence KB ╞ α2
• the agent cannot conclude that there is no pit in [2,2].
(Nor can it conclude that there is a pit in [2,2].)
Inference
• Inference is the process of deriving a
specific sentence from a KB (where the
sentence must be entailed by the KB)
– KB |-i  = sentence  can be derived from KB
by procedure i
• “KB’s are a haystack”
– Entailment = needle in haystack
– Inference = finding it
Inference
• Soundness
– i is sound if…
– whenever KB |-i  is true, KB |=  is true

• Completeness
– i is complete if
– whenever KB |=  is true, KB |-i  is true

• If KB is true in the real world, then any sentence


 derived from KB by a sound inference
procedure is also true in the real world
Inference
Sound and Truth Preserving Inference

• An inference algorithm that derives only entailed


sentences is called sound or truth preserving.
• Soundness is a highly desirable property.
• An unsound inference procedure essentially makes
things up as it goes along—it announces the discovery
of nonexistent needles.
• It is easy to see that model checking, when it is
applicable is a sound procedure.
• The property of completeness is also desirable: an
inference algorithm is complete if it can derive any
sentence that is entailed
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)
Propositional logic: Semantics
• Having specified the syntax of propositional logic, we now specify its
semantics

• The semantics define the rules for determining the truth of a sentence wrt a
particular model

Each model specifies true/false for each proposition symbol

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


false true false

With these symbols, 8 possible models, can be enumerated automatically.

Rules for evaluating truth with respect to a model m:

S is true iff S is false


S1  S2 is true iff S1 is true and S2 is true
S1  S2 is true iff S1is true or S2 is true
S1  S2 is true iff S1 is false or S2 is true
i.e., is false iff S1 is true and S2 is false
S1  S2 is true iff S1S2 is true andS2S1 is true
Truth tables for connectives
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)
Wumpus world sentences
Wumpus world sentences

You might also like