Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Outline
Knowledge-based agents The wumpus world Logic Propositional logic: A very simple logic Reasoning patterns in propositional logic Effective propositional inference Agents based on propositional logic
Knowledge Bases
Inference engine Knowledge base domainindependent algorithms domainspecific content
Knowledge base = set of sentences in a formal language Declarative approach to building an agent (or other system): T ELL it what it needs to know Then it can A SK itself what to doanswers should follow from the KB Agents can be viewed at the knowledge level, i.e. what they know, regardless of how implemented Or at the implementation level, i.e. data structures in KB and algorithms that manipulate them
Articial Intelligence 07, 2004 3
Knowledge-Based Agents
function KB-AGENT ( percept) returns an action static: KB, a knowledge base t, a counter, initially 0, indicating time T ELL (KB, M AKE -P ERCEPT-S ENTENCE ( percept, t)) action A SK (KB, M AKE -ACTION -Q UERY (t)) T ELL (KB, M AKE -ACTION -S ENTENCE (action, t)) t t+1 return action
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
Articial Intelligence 07, 2004 4
Stench
Bree z e
PIT
Bree z e
Stench Gold
PIT
Bree z e
Performance measure gold +1000, death -1000, -1 per step, -10 for using arrow
2 1
Stench
Bree z e
Bree z e
PIT
Bree z e
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 Shooting uses up the only arrow Grabbing picks up gold if in same square Releasing drops the gold in same square
1
START
Sensors Breeze, Glitter, Smell Actuators Left turn, Right turn, Forward, Grab, Release, Shoot
Articial Intelligence 07, 2004 5
Single-agent??
Single-agent?? feature
OK
OK
A
OK
B
A
OK
OK
A
OK
P?
B
A
OK
P?
OK
A
OK
P?
B
A
OK
P?
OK S
A A
OK
P?
P
B
A
OK
P? OK
OK S
A A
OK
W
Articial Intelligence 07, 2004 7
P?
P
B
A
OK
A
P? OK
OK S
A A
OK
W
Articial Intelligence 07, 2004 7
P?
OK
P
B
A
OK
A
P? OK
OK
OK S
A A
OK
W
Articial Intelligence 07, 2004 7
P?
OK
P
B
A
OK
P? BGS OK OK A A OK
A
OK S
A
W
Articial Intelligence 07, 2004 7
1,2
2,2
3,2
4,2
1,2
2,2
P?
3,2
4,2
(a)
(b)
The rst step taken by the agent in the wumpus world (a) The initial situation, after percept [None,None,None,None,None] (b) After one move, with percept [None,Breeze,None,None,None]
Articial Intelligence 07, 2004 8
W!
A S G B
1,2
A S OK
2,2
3,2
4,2
1,2
S V OK
2,2 V OK 2,1 B V OK
3,2
4,2
1,1 V OK
3,1
P!
4,1
V OK
(a)
(b)
Two later stages in the progress of the agent (a) After the third move, with percept [Stench,None,None,None,None] (b) After the fth move, with percept [Stench,Breeze,Glitter,None,None]
Articial Intelligence 07, 2004 9
OK
P? P?
Breeze in (1,2) and (2,1) no safe actions Assuming pits uniformly distributed, (2,2) has pit w/ prob 0.86, vs. 0.31
OK B
A A
OK P?
Smell in (1,1)
cannot move
S
A
Can use a strategy of coercion: shoot straight ahead wumpus was there dead safe wumpus wasnt there safe
Logic in General
Logics are formal languages for representing information such that conclusions can be drawn Syntax denes the sentences in the language Semantics dene the meaning of sentences; i.e., dene truth of a sentence in a world E.g., the language of arithmetic is a sentence; is not a sentence is true iff the number is no less than the number is true in a world where is false in a world where
Entailment
Entailment means that one thing follows from another:
if and only if
E.g., the KB containing the Giants won and the Reds won entails Either the Giants won or the Reds won E.g., entails
Entailment is a relationship between sentences (i.e., syntax) that is based on semantics Note: brains process syntax (of some sort)
Models
Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated We say is a model of a sentence if is true in
"
#$"
"
x x x x x x x x xx x x x x x x x x x x x x x x x x x x xx x x x x x x x x x x x x x x x
Then
if and only if
M(
!
x
M(KB)
x
Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for ?s assuming only pits 3 Boolean choices
? ?
B
A A
8 possible models
Wumpus Models
2 2
Breeze Breeze
PIT
PIT
1 2 3 3
2 2
PIT
PIT
2
Breeze Breeze
1
Breeze
PIT
3
1 1 1 2 3 1
1 2 3
2 2
PIT
PIT
PIT
Breeze Breeze
PIT
3
PIT
PIT
1 2 3
Breeze
PIT
3
Wumpus Models
2 2
Breeze Breeze
PIT
PIT
1 2 3 3
KB
2
PIT
PIT
2
Breeze Breeze
1
Breeze
PIT
3
1 1 1 2 3 1
1 2 3
2 2
PIT
PIT
PIT
Breeze Breeze
PIT
3
PIT
PIT
1 2 3
Breeze
PIT
3
Wumpus Models
2 2
Breeze Breeze
PIT
PIT
1 2 3 3
KB
2
1
2
PIT
PIT
2
Breeze Breeze
1
Breeze
PIT
3
1 1 1 2 3 1
1 2 3
2 2
PIT
PIT
PIT
Breeze Breeze
PIT
3
PIT
PIT
1 2 3
Breeze
PIT
3
%
%
Wumpus Models
2 2
Breeze Breeze
PIT
PIT
1 2 3 3
KB
2
PIT
PIT
2
Breeze Breeze
1
Breeze
PIT
3
1 1 1 2 3 1
1 2 3
2 2
PIT
PIT
PIT
Breeze Breeze
PIT
3
PIT
PIT
1 2 3
Breeze
PIT
3
Wumpus Models
2 2
Breeze Breeze
PIT
PIT
1 2 3 3
KB
2
PIT
PIT
2
Breeze Breeze
1
Breeze
PIT
3
1 1 1 2 3 1
1 2 3
2 2
PIT
PIT
PIT
Breeze Breeze
PIT
3
PIT
PIT
1 2 3
Breeze
PIT
3
' &
&
Inference
= sentence procedure can be derived from by
)0(
1
Preview: we will dene a logic (rst-order logic) which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure. That is, the procedure will answer any question whose answer follows from what is known by the .
)2(
)2(
, it is also , it is
Sentence Entails
Semantics
Representation
World
Follows
%5
&5
%5
&5
%5
&5
%5 %5
%5 8
%5
&5
&5
&5
&5
%5 7
%4
&5
&4
FEGD A% 4 @ H &
(8 possible models, can be enumerated) Rules for evaluating truth with respect to a model is true iff is false is true iff is true and is true iff is true or is true iff is false or i.e., is false iff is true and is true iff is true and : is true is true is true is false is true
P B QI @ C4 S TR % H %5 %5 %5 %5 5
%5
&5
%5
&5
&5
"
7! PI STR
FEGD
8EGFD
%5
%5
G DE H G DE H U FEGD H G DE H G DE H G DE H H G DE H H P I G DE S TR H G DE H 9 U
Articial Intelligence 07, 2004 20
G DE 4
6 6 @A& A% A% 4 @ @ % % %
1W XY
.
Articial Intelligence 07, 2004 21
1W XY
.
@ @ A& A% % %
6 6 @A& A% A% 4 @ @ % % %
1W XY
.
1W XY
.
FEGD
. . . . . .
H H FEGD
. . . . . .
P QI STR H FEGD H
. . .
P QI STR
FEGD H G DE
. . .
H G DE
. . .
H FEGD
. . .
. . .
H FEGD
. . .
. . .
H G DE H PI STR H H
Articial Intelligence 07, 2004 22
G DE
. . .
. . .
P QI STR H
. . .
H FEGD H G DE
. . .
PI PI STR TR S H H PQI QI P STR TR S H H PI PI STR TR S H H EGFD P I S TR H H PQI G DE STR H H P QI STR H FEGD H G DE H H H PI STR H G DE H H G DE H FEGD H G DE G DE
. . . . . .
PI STR
PI STR
Inference by Enumeration
a !
"
for symbols; problem is co-NP-complete
Logical Equivalence
Two sentences are logically equivalent iff true in same if and only if and models:
d
d" ! ! 66 ! fe8 fe7 8 7 d" d" " " " d" d" c c c c c c c ! ! ! ! ! ! d d 6 6 d 8 7 8 7 ! ! " " 8 d d d" 8e 7e 6 " "" ""
commutativity of commutativity of associativity of associativity of double-negation elimination contraposition implication elimination biconditional elimina de Morgan de Morgan distributivity of over distributivity of over
!!
!!
d"
"
""
!!
d"
fe8
""
7e
""
Articial Intelligence 07, 2004 25
EG g
Validity is connected to inference via the Deduction Theorem: if and only if is valid
Satisability is connected to inference via the following: if and only if is unsatisable i.e., prove by reductio ad absurdum
8
"
"
Proof Methods
Application of inference rules Legitimate (sound) generation of new sentences from old Proof = a sequence of inference rule applications Can use inference rules as operators in a standard search alg. Typically require translation of sentences into a normal form Model checking truth table enumeration (always exponential in ) improved backtracking, e.g., DavisPutnamLogemannLoveland heuristic search in model space (sound but incomplete) e.g., min-conicts-like hill-climbing algorithms
Resolution
1. Conjunctive Normal Form (CNFuniversal) conjunction of disjunctions of literals
P?
P
B
A
OK
A
P? OK
qr
OK S
OK
A
clauses
"
!
E.g.,
6
t" 8
%u vv 8
) u % 8 ) u % vv 8 v 8 x u 8 % vv 8 v
8 a
where
and
)u
@ A& 4 &
@ A% % 9 !
2. Eliminate
1. Eliminate
@ A% % 8 % 8
, replacing
! 6 6 % ! ! 6 ! @ A% !
@ A% 4 & 8 9 @A&% 4
, replacing
"
Conversion to CNF
""
with
@ A% 4 & 8 @A& 4 % " 7 !! 6 @A% 4 & 7 6 @A& 4 % @ A% 4 & 8 @A& 4 % " 7 ! 6! @A% 4 & 8 @A& 4 % " 8 @A% %
" @ A% % "
! d" 7 d
.
! "
PL Resolution
Proof by contradiction, i.e., show unsatisable
7 6
Resolution Example
@ A% 4 ! & A% @ % ! @ A% 4 & 8 @A& 4 % ""
P2,1 B1,1
@ A%
P1,2 B1,1
6
B1,1
P1,2
P2,1
P1,2
!
h"
"
d % vv 7 v
7 % a
Can be used with forward chaining or backward chaining. These algorithms are very natural and run in linear time
Articial Intelligence 07, 2004 31
a
Forward Chaining
Q P M L
A
B
Idea: re any rule whose premises are satised in the , add its conclusion to the , until query is found
Articial Intelligence 07, 2004 32
PL Forward Chaining
Proof of Completeness
FC derives every atomic sentence that is entailed by 1. FC reaches a xed point where no new atomic sentences are derived 2. Consider the nal state as a model true/false to symbols , assigning
3. Every clause in the original is true in Proof: Suppose a clause is false in Then is true in and is false in Therefore the algorithm has not reached a xed point!
4. Hence 5. If
is a model of ,
Px 7
%P
xP 7
%P
, including
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
M L
B
Articial Intelligence 07, 2004 36
Circuit-Based Agent
Breeze Forward
Stench
TurnLeft
Glitter
TurnRight
Bump
Grab
Scream
Alive Shoot
Part of circuit-based agent for wumpus world, inputs, outputs, circuit grabbing gold, and circuit for determining whether wumpus is alive. Registers are shown as rectangles and one-step delays as small triangles.
Articial Intelligence 07, 2004 42
Circuit-Based Agent 2
Breeze
Forward
Stench
L2,1
FacingLeft
TurnLeft
Glitter
L1,1
TurnRight Grab
Bump
Shoot
Scream
L1,2
FacingDown
The circuit for determining whether the agent is at [1.1]. Every location and orientation has a similar circuit attached.
Articial Intelligence 07, 2004 43
Knowledge Propositions
Summary
Logical agents apply inference to a knowledge base to derive new information and make decisions Basic concepts of logic: syntax: formal structure of sentences semantics: truth of sentences wrt models entailment: necessary truth of a sentence given another inference: deriving sentences from other sentences soundness: derivations produce only entailed sentences completeness: derivations can produce all entailed sentences Wumpus world requires the ability to represent partial and negated information, reason by cases, etc. Forward, backward chaining are linear-time, complete for Horn clauses; Resolution is complete for propositional logic Propositional logic lacks expressive power
Articial Intelligence 07, 2004 45