CH 9 Logical Agents

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

Artificial Intelligence

Lecture 9
Logical Agents

The University of Faisalabad 1


Logical Agents
• Why are we talking about “Logical”?
– Are search-based chess programs logical?
• Yes but knowledge is used in a very specific way
– Win the game
– Not useful for extracting strategies or understanding other
aspects of chess
• We want to develop more general-purpose knowledge systems
that support a variety of logical analysis.

The University of Faisalabad 2


Knowledge based Agents

• Agents that 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.

The University of Faisalabad 3


Knowledge based Agents
• Intelligent agents need knowledge about the world to choose
good actions/decisions.
• Knowledge = {sentences} in a knowledge representation
language (formal language).
• A sentence is an assertion about the world.

• A knowledge-based agent is composed of:


1. Knowledge base: domain-specific content.
2. Inference mechanism: domain-independent algorithms

The University of Faisalabad 4


Knowledge based Agents
The agent must be able to:
– Represent states, actions, etc.
– Incorporate new percepts
– Update internal representations of the world
– Deduce hidden properties of the world
– Deduce appropriate actions

Declarative approach to building an agent:


– Add new sentences: Tell it what it needs to know
– Query what is known: Ask itself what to do - answers should follow
from the KB
The University of Faisalabad 5
Knowledge based Agents

The University of Faisalabad 6


Why study knowledge based agents?

• Partially observable environments


– combine available information (percepts) with general knowledge to
select actions
• Natural Language
– Language is too complex and ambiguous. Problem-solving agents
are slow down by high branching factor.
• Flexibility
– Knowledge can be reused for novel tasks. New knowledge can be
added to improve future performance.

The University of Faisalabad 7


Components of knowledge-based agent
• Knowledge Base:
Knowledge base is a set of sentences (sometimes we dignify a sentence with the
name axiom)
– Each sentence is expressed in a language called Knowledge representation
language
– Add Information (Tell)
• TELL: Father of Jhon is Bob
• TELL: Jane is Jhon’s Sister
– Retrieve information (Ask)
• ASK: Who’s Jane’s father?
– Perform Inference
• Drive a new sentences (knowledge) from existing sentences
• Each time the agent program is called, it does three things. First, it TELLs the knowledge base
what it perceives. Second, it ASKs the knowledge base what action it should perform. In the
process of answering this query, extensive reasoning may be done about the current state of the
world, about the outcomes of possible action sequences, and so on. Third, the agent program
TELLs the knowledge base which action was chosen, and the agent executes the action.

The University of Faisalabad 8


The Wumpus World
• A scary world, indeed
– A maze in a cave
– A wumpus who will eat you
– One arrow that can kill the
wumpus
– Pits that can entrap you (but not
the wumpus for it is too large to
fall in)
– A heap of gold somewhere

The University of Faisalabad 9


The Wumpus World
Formulation
• PEAS:
– Performance Measure:
• +1000 for walk out with gold; -1000 for dying; -1 for action; -10 for arrow
– Environment:
• A 4 x4 grid, Agent starts at [1, 1]; gold and pits randomly distributed, etc
– Actuators:
• Agent can turn left or right 90 degrees
• Agent can move forward
• Agent can shoot an arrow in your facing direction
– Sensors:
• wumpus emits a stench in adjacent squares
• pits cause a breeze in adjacent squares
• gold causes glitter you see when in the square
• walking into wall causes a bump
• death of wumpus can be heard everywhere in world
{[Smell, Breeze, Glitter, Bump, Scream]}

The University of Faisalabad 10


An Example

The University of Faisalabad 11


An Example

Our Agent Played Well


• Used inference to relate two different percepts observed from different locations
• Agent is guaranteed to draw correct conclusions
The University if
of percepts
Faisalabad are correct 12
LOGIC
• Now we will describe how to build logical agents that can represent
information and draw conclusions
• KB consists of sentences. These sentences are expressed according to the
syntax of representation language
– Syntax
• The formal specification of how information is stored
– a+ 2 = c (typical mathematical syntax)
– A2y+= (not leagal syntax)
• A logic must also define the semantics or meaning of sentences. The
semantics defines TRUTH the truth of each sentence with respect to
each possible world (or model).
– Semantics
• a + 2 = c (c must be two more than a)
• x + y = 4, is true in a world where x is 2 and y is 2

The University of Faisalabad 13


LOGIC
• If a sentence α is true in model m, we say that m satisfies α or some times
m is a model of α. We use the notation M(α) to mean the set of all models
of α.
• Entailment: one sentence follows logically from another
– α  β or α ⊧ β
the sentence α entails the sentence β
– α ⊧ β if and only if M(α) ⊆ M(β)
• α entails β if and only if every model in which a is true, b is also
true
Examples
x=0 ⊧ xy=0
p = true ⊧ (p ∨ q)
(p ∧ q) ⊧ (p ∨ q)

The University of Faisalabad 14


An Example
• After one step in wumpus world
– Knowledge base is
• rules of game
• percepts (a breeze in 2, 1)
– Ask the KB if there is a pit in
adjacent squares
• 1, 2 = pit?
• 2, 2 = pit?
• 3, 1 = pit?

The University of Faisalabad 15


Model Checking
• The agent wishes to check all models of the game in which a
pit is in the three candidate spots
– Enumerate all models
where three candidate
spots may have pits
– 3 pits, two conditions each
– 23 = Eight models

The University of Faisalabad 16


Model Checking
Checking entailment
• Can “There is no pit in (1,2)”
be true?

– Is α1 true?
– For all models where KB is true,
α1 is true also.
– KB  α1 (KB entails α1)

The University of Faisalabad 17


Model Checking
Checking entailment
• Can “There is no pit in (2,2)”
be true?

– Is α2 true?
– For all models where KB is true,
α2 is not always true also.
– KB does not entail α2

The University of Faisalabad 18


Logical Inference
• Entailment permitted logic
– we inferred new knowledge from entailments

• Model Checking
– We enumerated all possibilities to ensure inference was complete

The University of Faisalabad 19


Propositional (Boolean) Logic

The University of Faisalabad 20


Propositional (Boolean) Logic
• Syntax of allowable sentences
– Atomic Sentences
• Indivisible syntactic elements
• One propositional symbol
• Use uppercase letters as representation
• True and False are predefined proposition symbols

The University of Faisalabad 21


Propositional (Boolean) Logic
• Complex Sentences
– ~ (not): the negation
– ^ (and): the conjunction
– V (or): the disjunction

– => (implies): the implication


–  (if and only if): the biconditional

The University of Faisalabad 22


Propositional (Boolean) Logic
• BNF (Backus-Naur Form)

The University of Faisalabad 23


Propositional (Boolean) Logic
• Semantics
– given a particular model (situation), what are the rules
that determine the truth of a sentence?
– use a truth table to compute the value of any sentence
with respect to a model by recursive evaluation

The University of Faisalabad 24


Propositional (Boolean) Logic
• Truth Table

The University of Faisalabad 25


Propositional (Boolean) Logic
• Example from wumpus
– A square is breezy if and only if a neighboring square
has a pit.
• B1,1  (P1,2 V P2,1)
– A square is breezy if a neighboring square has a pit.
• (P1,2 V P2,1) => B1,1

– First one is more powerful and true to wumpus

The University of Faisalabad 26


Inference
Truth Table

The University of Faisalabad 27


Concepts related to entailment
• logical equivalence
– a and b are logically equivalent if they are true in the same
set of models… a b
• Validity
– a sentence that is valid in all models
• P V ~P
• deduction theorem: a entails b if and only if a implies b
• satisfiability
– a sentence that is true in some model
– a entails b  (a ^ ~b) is unsatisfiable

The University of Faisalabad 28

You might also like