Anda di halaman 1dari 70

Artificial Intelligence

Logical Agents
Outline
Knowledge-based agents
Wumpus world
Logic in general - models and entailment
Propositional (Boolean) logic
Equivalence, validity, satisfiability
Inference rules and theorem proving
Introduction
The representation of knowledge and the
reasoning processes that bring knowledge to life are
central to entire field of artificial intelligence

Knowledge and reasoning are important to artificial


agents because they enable successful behaviors that
would be very hard to achieve otherwise (no piece in
chess can be on two different squares at the same time)

Knowledge and reasoning also play a crucial role in


dealing with partially observable environments (inferring
hidden states in diagnosing diseases, natural language
understanding)

Knowledge also allows flexibility.


Knowledge bases
Knowledge base = set of sentences in a formal language
Each sentence is expressed in a knowledge representation
language and represents some assertions about the world
There should be a way to add new sentences to KB, and to
query what is known

Declarative approach to building an agent (or other system):


TELL it what it needs to know
Then it can ASK itself what to do - answers should follow from the
KB

Both tasks may involve inference deriving new sentences from


old

In logical agents when one ASKs a question to KB, the answer


should follow from what has been TELLed
A simple knowledge-based agent
KB : maintain the background knowledge
Each time the agent program is called it does
three things:
TELLs the KB what it perceives
ASK the KB what action it should perform
TELL the KB that the action is executed
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
Wumpus World PEAS description
Performance measure
gold +1000, death -1000
-1 per step, -10 for using the arrow
Environment 4X4 grid of rooms.
Agent starts in [1,1]
Sensors: Stench, Breeze, Glitter, Bump,
Scream
Squares adjacent to wumpus are smelly
(stench)
Squares adjacent to pit are breezy
Glitter if gold is in the same square
Bump if the agent walks into the wall
Scream when the Wumpus is killed
Actuators: Left turn, Right turn, Forward,
Grab, Shoot
Shooting kills wumpus if you are facing it
Shooting uses up the only arrow
Grabbing picks up gold if in same square
Wumpus world characterization
Fully Observable No only local perception
Deterministic Yes outcomes 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
Exploring a wumpus world
Exploring a wumpus world
Exploring a wumpus world
Exploring a wumpus world
Exploring a wumpus world
Exploring a wumpus world
Exploring a wumpus world
Exploring a wumpus world
Logic in general
Logics are formal languages for representing
information such that conclusions can be drawn
Syntax defines the sentences in the language
Semantics define the "meaning" of sentences;
i.e., define truth of a sentence in a world
E.g., the language of arithmetic
x+2 y is a sentence; x2+y > {} is not a sentence
x+2 y is true iff the number x+2 is no less than the
number y
x+2 y is true in a world where x = 7, y = 1
x+2 y is false in a world where x = 0, y = 6
Possible world model
m is a model of
Entailment
Entailment means that a sentence follows logically from
another sentence ( ):
iff in every model where is true, is also true.
iff M() M()
KB
Knowledge base KB entails sentence iff is true in all
worlds where KB is true

If KB true then must also be true


E.g., the KB containing the Giants won and the Reds won
entails Either the Giants won or the Reds won
Entailment is a relationship between sentences (i.e., syntax)
that is based on semantics
Entailment in the wumpus world
Situation after detecting nothing in [1,1],
moving right, breeze in [2,1]
Wumpus models
3 Boolean choices 8 possible models for the
adjacent squares [1,2], [2,2] and [3,1] to contain pits
Wumpus models
Possible models for the presence of pits in squares [1,2], [2,2],
and [3,1].

[1,2]

The KB corresponding to the observations of nothing in [1,1] and a


breeze in [2,1] is shown by the solid line.
As there is no breeze in [1,1], the KB is false in any model in which
[1,2] contains a pit. Therefore, only three models in which the KB is
true.
Wumpus models
[1,2]

Consider 1= [1,2] is safe = There is no pit in [1,2]


In every model KB is true 1 is also true
KB 1, proved by model checking
We can conclude that there is no pit in [1,2]
Wumpus models

Consider 2 = [2,2] is safe = There is no pit in [2,2]


In some models in which KB is true 2 is false
KB / 2
We cannot conclude that there is no pit in [2,2]
Propositional logic: Syntax
Propositional logic is the simplest logic illustrates basic
ideas

Atomic sentences : consists of proposition symbols P1, P2


Complex sentences : constructed from atomic sentences
using logical connectives
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)
Precedence
Use parentheses to specify the precedence
Otherwise the precedence from highest to
lowest is: , , , ,
A C is not allowed
Propositional logic: Semantics
Semantics defines the rules for determining the
truth of a sentence with respect to a particular
model
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 S1S2 is true and S2S1 is
true
Important shorthand
S1 S2 S1 S2
S1 S2 (S1 S2) (S2 S1)
Truth tables for connectives

Simple recursive process evaluates an arbitrary sentence,


e.g., P1,2 (P2,2 P3,1) = true (true false) = true true = true

Implication: The sentence is true when P is False or the both


symbols are True. Otherwise it is False.
(e.g. It is rainy => It is cloudy)

Biconditional: True whenever both P=>Q and Q=>P is true


(e.g. a square is breezy if and only if adjacent square has a pit: implication
requires the presence of pit if there is a breeze, biconditional also
requires the absence of pit if there is no breeze)
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].
Knowledge base includes:
R1: P1,1 No pit in [1,1]
R2: B1,1 No breeze in [1.1]
R3: B2,1 Breeze in [2,1]

"Pits cause breezes in adjacent squares"


R4: B1,1 (P1,2 P2,1)
R5: B2,1 (P1,1 P2,2 P3,1)

KB = R1 R2 R3 R4 R5
Inference
Decide whether KB
First method: enumerate the models and
check that is true in every model in
which KB is true
B1,1 B2,1, P1,1 , P1,2, P2,1, P2,2 ,P3,1
7 symbols : 27 = 128 possible models
Truth tables for inference
Logical equivalence
Two sentences are logically equivalent iff they are true in
same models:
iff and
Logical Agents
Propositional logic: (Exapmle)
Simplify the following sentence: ( )
to determine the following desired model

A B C (D C)
Implication Elimination

A B C (D C)
De Morgan
( A B C) (D C)
Not (Not()) =
((A B) C) (D C)
Distributivity
( A B D) C
Logical Agents
Propositional logic: (Exapmle)
Convert the following sentence: AB D (C D) E

To obtain the following desired sentence A B C D E

A B D (C D) E
De Morgan
A B D (C D) E
Distributivity
AB C D E
De Morgan
AB C D E
De Morgan
AB C D E
Inverse(Implication Elimination)
A B C D E
Validity and satisfiability

Tautology:
Statement composed of simpler statements in
a manner that makes it logically true
whether the simpler statements are factually
true or false

Example

Proof
Truth tables for inference
Example:
|= if and only if the sentence ( ) is valid.

KB=>
Truth tables for inference
Proof:
|= if and only if the sentence ( ) is valid.

We need to prove KB=> is valid


KB
KB
KB
KB
KB
We need to prove ( KB ) is valid

We need to prove ( KB ) is unsatisfiable


Examples
Natural deduction
Natural deduction
Propositional logic: (Reasoning patterns)
The first rule is called Modus Ponens:

The notation means that, whenever any sentences of the form and is given,
then the sentence can be inferred.

For example, (WumpusAhead WumpusAlive) Shoot


And (WumpusAhead WumpusAlive) is given :
then Shoot can be inferred.

The second rule is called And-Elimination

Which says that, from a conjunction any of the conjuncts can be inferred

For example, from (French English)


French speaker is given
English speaker will be inferred.
Natural deduction

Propositional logic (Unit Resolution, Complementary Resolution & Factoring)

Unit Resolution
The unit resolution rule takes a clause (disjunction of
literals) and produces a new clause. : You can walk
: You can take a bus
Complementary Resolution
Takes two clauses and produces a new clause containing all the
literals of the two original clauses except the two complementary
literals. For example, we have

Example:

: The weather is dry


: The weather is rainy
: I carry an umbrella

Factoring :
If we resolve (A B) with (A B),
we obtain (A A), which is reduced to just A.
Logical Agents
P1,1 P1,2
Propositional logic: (Inference and proofs)
Example (1):
P2,1 P2,2
B ( P1, 2 P2,1 )
If the alert B is ON, parking P1,2 or P2,1 is occupied .
No alert B. Are given

B ( P1, 2 P2,1 ) Biconditional elimination


( B ( P1, 2 P2,1 )) (( P1, 2 P2,1 ) B) And elimination

( P1, 2 P2,1 ) B Contraposition


Proof

B ( P1, 2 P2,1 ) Modus Ponens


( P1, 2 P2,1 ) de Morgan

P1, 2 P2,1
From the original sentence we can arrive to the last sentence which means :
If no alert case is already given thus the two parking cells are free
Logical Agents
P1,1 P1,2
Propositional logic: (Inference and proofs)
Example (1):
P2,1 P2,2

In the program, we may have this line..

If (P1, 2 P2,1 ) (Gate Open) Announce( Parking is free)

P1, 2 P2,1 Was already inferred true from the last step
(Not given data)

Therefore, if the parking Gate is opens this command will be activated


directly. And the system can improve its performance by adding the
following line to its own program:

If (B) (Gate Open) Announce( Parking is free)


Logical Agents
Propositional logic: (Inference and proofs) Example (2):
In the KB of one auto-piloted smart car we may have : stop the motor G, implicates
that at least one of two stoplights (Red Right, Red Left) for the car which is just in
face was turned On. Give the logic sentence that describe the last experience. If,
nonstop motor state was given make the possible inference on your sentence.

G ( RR RL )
(G ( RR RL )) (( RR RL ) G )
( RR RL ) G
G ( RR RL )
( RR RL )
RR RL

Logical agents apply inference to a knowledge base to derive new


information and make decisions
Example from Wumpus World
Example from Wumpus World
Example from Wumpus World
Example from Wumpus World
Example from Wumpus World
Example from Wumpus World
Resolution

Using the same process that led to R10 we can derive

We can also apply biconditional elimination to R5, followed by Modus


Ponens with R3
P2,2 in R13 resolves with the literal P2,2 in R15
Resolution Are given
12 (13 22 )
(21 (31 22 ))
21 , 12
How we think & how the machine has to do :
21 31 22
(21 (31 22 )) ((31 22 ) 21 )
(31 22 ) 21
21 (31 22 )
13 22

12 (13 22 ) TRUE
12 13 22
We may
F F
Resolve 22 , 12 think
F T
13 T T
12 is already TRUE
13 22 has to be TRUE
13 is TRUE
T F
Wumpus is located in the
F T
cell [1,3]
T T

We know a priori 22 is FALSE


Conjunctive Normal form
Every sentence of propositional logic is logically
equivalent to a conjunction of disjunctions of
literals.
Converting to CNF
CNF Conversion Example
Conversion to CNF Example
Logical Agents
Propositional logic: (Resolution Algorithm)

To prove KB , assume KB and derive a contradiction


Rewrite KB as a conjunction of clauses, or disjunctions of
or disjunctions of literals
Conjunctive normal form (CNF)
Keep applying resolution to clauses that contain complementary
literals and adding resulting clauses to the list
If there are no new clauses to be added,
then KB does not entail
If two clauses resolve to form an empty clause,
we have a contradiction and KB
Example - 1
KB

Prove KB=> R
Example - 1

KB

Prove KBI= R
Example - 2

KB

Prove: KBI= R
Example - 2
Logical Agents
Propositional logic: (Resolution Algorithm) Example 3
If we have the knowledge base:

KB =
and we wish to prove which is, say, P1,2.

We know a priori, to show that KB |= we have to


prove that (KB ) is unsatisfiable

We convert (KB ) into CNF,


Logical Agents (Horn clause)

Horn clause, is a disjunction of literals of which at most one is positive.


Can be used with forward chaining.

Example :

Example : Simplify the following sentence to horn clause form


( A B) (C D) if (A B)
(( A B) (C D)) ((C D) ( A B)) (( A B) (C D))
(C D) ( A B) Are given
( A B) (C D)
( A B ) ( C D )
if (A B) is given
(C D) ( Horn clause)
Forward chaining
Idea: fire any rule whose premises are satisfied in the KB,
add its conclusion to the KB, until query is found

Knowledge base of And - Or graph


In ANDOR graphs;
Horn clauses
Multiple links joined
by an arc indicate a
conjunction
Multiple links without
an arc indicate a
disjunction
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining example
Forward chaining is an
example of the general
concept of data-driven
reasoning in which the
focus of attention starts with
the known data (e.g.
incoming percepts) in order
The picnic
to derive conclusions.
will be
canceled.
In other words: It is an
incremental algorithm in
which new facts can be
added to initiate new
inferences.

I am indoors I hear rain


starting to fall

Anda mungkin juga menyukai