0% found this document useful (0 votes)
96 views31 pages

Logical Agents: (AIMA - Chapter 7)

1) Logical agents combine a knowledge base of facts about the world with current percepts to infer hidden aspects of the current state using rules of inference. 2) The knowledge base encodes assertions about the world in a formal knowledge representation language as axioms and rules of inference. 3) Propositional logic provides a simple yet useful formal language for representing facts and rules of inference, where inference problems can be solved tractably.

Uploaded by

Hafidz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views31 pages

Logical Agents: (AIMA - Chapter 7)

1) Logical agents combine a knowledge base of facts about the world with current percepts to infer hidden aspects of the current state using rules of inference. 2) The knowledge base encodes assertions about the world in a formal knowledge representation language as axioms and rules of inference. 3) Propositional logic provides a simple yet useful formal language for representing facts and rules of inference, where inference problems can be solved tractably.

Uploaded by

Hafidz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Logical Agents

(AIMA - Chapter 7)

CIS 391 - Intro to AI 1


Outline
1. Wumpus world
2. Logic-based agents
3. Propositional logic
• Syntax, semantics, inference, validity, equivalence
and satifiability

Next Time:
 Automated Propositional Theorem Provers
• Resolution
• A Practical Method: Walksat

CIS 391 - Intro to AI 2


1. Automating “Hunt the Wumpus”:
A different kind of problem

CIS 391 - Intro to AI 3


The Wumpus World

Wumpus

A Hunt the Wumpus Flash version: http://www.flashrolls.com/puzzle-


games/Hunt-The-Wumpus-Flash-Game.htm
CIS 391 - Intro to AI 4
PEAS description
 Performance measure
• gold: +1000, death: -1000
• -1 per step

 Environment
• Squares adjacent to wumpus are smelly
• Squares adjacent to pit are breezy
• Glitter iff gold is in the same square
• Gold is picked up by reflex, can’t be dropped
• You bump if you walk into a wall

 Actuators: Move <dir>


 Sensors: Stench, Breeze, Glitter, Bump

CIS 391 - Intro to AI 5


Full PEAS description
 Performance measure
• gold: +1000, death: -1000
• -1 per step, -10 for using the arrow

 Environment
• 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. It screams
• Shooting uses up the only arrow
• Grabbing picks up gold if in same square
• Releasing drops the gold in same square
• You bump if you walk into a wall

 Actuators: Face <direction>, Move, Grab, Release, Shoot


 Sensors: Stench, Breeze, Glitter, Bump, Scream
CIS 391 - Intro to AI 6
Wumpus world characterization
 Deterministic Yes – outcomes exactly specified
 Static Yes – Wumpus and Pits do not move
 Discrete Yes
 Single-agent Yes – Wumpus is essentially a natural
feature

 Fully Observable No – only local perception


 Epis`odic No—What was observed before
(breezes, pits, etc) is
very useful.

A New Kind of Problem!


CIS 391 - Intro to AI 7
Exploring the Wumpus World

1. The KB initially contains the rules of the environment.

2. Location: [1,1]
Percept: [Stench, Breeze, Glitter,  Bump]
Action: Move to safe cell e.g. 2,1

3. Location: [2,1]
Percept: [Stench, Breeze, Glitter,  Bump]
INFER: Breeze indicates that there is a pit in [2,2] or [3,1]
Action: Return to [1,1] to try next safe cell
CIS 391 - Intro to AI 8
Exploring the Wumpus World

4. Location: [1,2] (after going through [1,1])


Percept: [Stench, Breeze, Glitter,  Bump]
INFER: Wumpus is in [1,1] or [2,2] or [1,3]
INFER … stench not detected in [2,1], thus not in [2,2]
REMEMBER….Wumpus not in [1,1]
THUS … Wumpus is in [1,3]
THEREFORE [2,2] is safe because of lack of breeze in [1,2]
Action: Move to [2,2]
REMEMBER: Pit in [2,2] or [3,1]
THEREFORE: Pit in [3,1]!
CIS 391 - Intro to AI 9
2. Logic-based Agents

CIS 391 - Intro to AI 10


Logical Agents
 Most useful in non-episodic, partially
observable environments
 Logic (Knowledge-Based) agents combine
1. A knowledge base (KB): a list of facts that are
known to the agent.
2. Current percepts
to infer hidden aspects of the current state using
Rules of inference
 Logic provides a good formal language for both
• Facts encoded as axioms
• Rules of inference
CIS 391 - Intro to AI 11
The Knowledge Base
A set of sentences
 that encodes assertions about the worldi
 in a formal knowledge representation language.

Declarative approach to building an agent:


 Tell it what it needs to know – add fact to KB.
 Ask it what to do – compute using inference
rules also in KB

CIS 391 - Intro to AI 12


Generic KB-Based Agent Pseudocode

 Agent must be able to:


1. Represent states and actions,
2. Incorporate new percepts
3. Update internal representation of the world
4. Deduce hidden properties of the world
5. Deduce appropriate actions – requires some logic of action

CIS 391 - Intro to AI 13


3. Propositional Logic

 Propositional logic is the simplest logic –


illustrates basic ideas
 Inference in propositional logic is also tractable
with reasonable constraints – therefore very useful

CIS 391 - Intro to AI 14


LOGIC: What is a logic?
 A formal language with associated
• Syntax – what expressions are legal (well-formed)
• Semantics – what legal expressions mean
—in logic, meaning is defined by the truth of each sentence with respect to
a set of possible worlds
– Possible world (simplified): an assignment of values to all logical variables

 e.g. the language of arithmetic


• Syntax: X+2  y is a legal sentence, x2+y is not a legal sentence
• Semantics: X+2  y is true in a world where x=7 and y =1
• Semantics: X+2  y is false in a world where x=0 and y =6

CIS 391 - Intro to AI 15


Propositional logic: Syntax
Recursively defined:
Base case:
 The atomic proposition symbols P1, P2 etc are sentences
Recursion:
 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)

CIS 391 - Intro to AI 16


Propositional logic: Semantics
Each model/world specifies true or false for each proposition symbol
E.g. P1,2 P2,2 P3,1
false true false
With these three symbols, 23 possible models (worlds) , can be
enumerated automatically.

Rules for evaluating truth with respect to a model m:

(not) S is true iff S is false


(and) S1  S2 is true iff S1 is true and S2 is true
(or) S1  S2 is true iff S1 is true or S2 is true
(if..then) S1  S2 is true iff S1 is false or S2 is true
i.e., is false iff S1 is true and S2 is false
(if and only if) S1  S2 is true iff S1S2 is true and S2S1 is true

Simple recursive process evaluates an arbitrary sentence, e.g.,

P1,2  (P2,2  P3,1) = true  (true  false) = true  true = true


CIS 391 - Intro to AI 17
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].

start:  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)

CIS 391 - Intro to AI 18


Model Theory
 Logicians often think in terms of models
• Formally structured “worlds” with respect to
which truth can be evaluated

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


m

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


(Usually, logicians are interested in models of
mathematical structures. AI-types are interested in
models of common-sense objects and activities.)

CIS 391 - Intro to AI 19


A key semantic relation: Entailment
 Entailment means that the truth of one sentence
follows from the truth of another:
KB ╞ 
Entails
Knowledge base KB entails sentence 
if and only if
 is true in all worlds where KB is true
• e.g., the KB containing the Giants won and the Reds lost
entails The Giants won
• e.g., the KB containing x+y = 4 entails 4 = x+y

 Entailment is a relationship between sentences


based on semantics
CIS 391 - Intro to AI 20
Models II
 Review:
• m is a model of a sentence  if  is true in m
• M() is the set of all models of 
 Entailment:
• KB ╞  iff M(KB)  M()
• Example:
—KB = Giants won and M()
Reds lost
 = Giants won

CIS 391 - Intro to AI 21


Entailment in the wumpus world
 Consider possible models for KB assuming only pits
and a reduced Wumpus world with only 5 squares and
pits

 Situation after
A. detecting nothing in [1,1],
B. moving right, breeze in [2,1]:

CIS 391 - Intro to AI 22


Wumpus models I

Pit

Breeze
All possible models (exactly 8) in this reduced Wumpus world.

CIS 391 - Intro to AI 23


Wumpus models II

 In Red: all possible wumpus-worlds consistent


with the observations on slide 22 and the
“physics” of the Wumpus world.

CIS 391 - Intro to AI 24


Deciding what to do by model checking I

α1 = "[1,2] is safe", KB ╞ α1, proved by model checking

CIS 391 - Intro to AI 25


Deciding what to do by model checking II

α2 = "[2,2] is safe", KB ╞ α2

CIS 391 - Intro to AI 26


Truth tables for connectives
 Truth tables enumerate all possible propositional
models
 Thus, truth tables are a simple form of model checking

OR: P or Q is true or both are true. Implication is always true


XOR: P or Q is true but not both. when the premises are False!

CIS 391 - Intro to AI 27


Inference Procedures
 KB ├i α : sentence α can be derived from KB by
procedure i
 Soundness: i is sound if whenever KB ├i α, it is
also true that KB╞ α
• No false inferences
• (but all true statements might not be derived)
 Completeness: i is complete if whenever KB╞ α, it
is also true that KB ├i α
• All true sentences can be derived,
• (but some false statements might be derived)

 Desirable: sound and complete

CIS 391 - Intro to AI 28


Inference by enumeration
 Enumeration of all models (truth tables) is sound
and complete.

 For n symbols, time complexity is O(2n)...

 We need a smarter way to do inference!

 One approach: infer new logical sentences from


the data-base and see if they match a query.

CIS 391 - Intro to AI 29


Logical equivalence
 To manipulate logical sentences we need some rewrite rules.
 Two sentences are logically equivalent iff they are true in same models: α
≡ ß iff α╞ β and β╞ α

You need to
know these !

CIS 391 - Intro to AI 30


Validity and satisfiability
A sentence is valid if it is true in all models,
e.g. True, A A, A  A, (A  (A  B))  B

Validity is connected to inference via the Deduction Theorem:


KB ╞ α if and only if (KB  α) is valid

A sentence is satisfiable if it is true in some model


e.g. A B, C

A sentence is unsatisfiable if it is false in all models


e.g. AA

Satisfiability is connected to inference via the following:


KB ╞ α if and only if (KB α) is unsatisfiable
(there is no model for which KB=true and  is false)

CIS 391 - Intro to AI 31

You might also like