Professional Documents
Culture Documents
Logical Agents
Marco Chiarandini
Department of Mathematics & Computer Science
University of Southern Denmark
Knowledge-based Agents
Logic in General
Course Overview
4 Introduction
4 Learning
4 Supervised
Decision Trees, Neural
Networks
Learning Bayesian Networks
4 Unsupervised
EM Algorithm
4 Artificial Intelligence
4 Intelligent Agents
4 Search
4 Uninformed Search
4 Heuristic Search
4 Reinforcement Learning
4 Games and Adversarial Search
4 Minimax search and
Alpha-beta pruning
4 Multiagent search
I
Propositional logic
First order logic
Inference
Plannning
2
Outline
Knowledge-based Agents
Logic in General
1. Knowledge-based Agents
Wumpus Example
2. Logic in General
Knowledge-based Agents
Logic in General
Knowledge bases
Knowledge base = set of sentences in a formal language
Inference engine
domainindependent algorithms
Knowledge base
domainspecific content
Knowledge-based Agents
Logic in General
Knowledge-based Agents
Logic in General
Breeze
Stench
Breeze
Stench
PIT
Breeze
PIT
Gold
Breeze
Stench
Breeze
Breeze
PIT
START
Knowledge-based Agents
Logic in General
Breeze
Stench
Breeze
Stench
PIT
Breeze
PIT
Gold
Breeze
Stench
Breeze
Breeze
PIT
START
P?
Knowledge-based Agents
Logic in General
OK
P
B
OK
A
P? BGS OK
OK
A
A
OK S
A
OK
A
W
9
Outline
Knowledge-based Agents
Logic in General
1. Knowledge-based Agents
Wumpus Example
2. Logic in General
11
Logic in general
Knowledge-based Agents
Logic in General
12
Entailment
Knowledge-based Agents
Logic in General
13
Knowledge-based Agents
Logic in General
Models
M(
x
x
x
xx
x x
x
x
x
x
x
x
x
xx
x
x
M(KB)
x
x
x
x
x
x
x
x
x
x
14
Knowledge-based Agents
Logic in General
? ?
B
15
Inference
Knowledge-based Agents
Logic in General
21
Propositional Logic
Inference in PL
Part I
22
Outline
Propositional Logic
Inference in PL
3. Propositional Logic
Introduction
Equivalence and Validity
4. Inference in PL
Proof by Resolution
Proof by Model Checking
23
Outline
Propositional Logic
Inference in PL
3. Propositional Logic
Introduction
Equivalence and Validity
4. Inference in PL
Proof by Resolution
Proof by Model Checking
24
Propositional Logic
Inference in PL
26
Propositional Logic
Inference in PL
S2
S2
S2
S2
= S1
is
is
is
is
is
true
true
true
false
true
27
Propositional Logic
Inference in PL
P
false
false
true
true
Q
false
true
false
true
P
true
true
false
false
P Q
false
false
false
true
P Q
false
true
true
true
PQ
true
true
false
true
PQ
true
false
false
true
28
Propositional Logic
Inference in PL
B2,1
(P1,2 P2,1 )
R5 : B2,1
29
Propositional Logic
Inference in PL
KB `
B1,1 B2,1
false false
false false
..
..
.
.
false true
false true
false true
false true
false true
..
..
.
.
P1,1 P1,2
false false
false false
..
..
.
.
false false
false false
false false
false false
false false
..
..
.
.
P2,1 P2,2
false false
false false
..
..
.
.
false false
false false
false true
false true
true false
..
..
.
.
P3,1 R1 R2
false true true
true true true
..
..
..
.
.
.
false true true
true true true
false true true
true true true
false true false
..
..
..
.
.
.
R3 R4 R5
true true false
false true false
..
..
..
.
.
.
false true true
true true true
true true true
true true true
false true true
..
..
..
.
.
.
KB
false
false
..
.
false
true
true
true
false
..
.
true true true true true true true false true true false true false
Enumerate rows (different assignments to symbols),
if KB is true in row, check that is too
30
Inference by enumeration
Propositional Logic
Inference in PL
31
Logical equivalence
Propositional Logic
Inference in PL
( ) commutativity of
( ) commutativity of
( ( )) associativity of
( ( )) associativity of
double-negation elimination
( = ) contraposition
( ) implication elimination
(( = ) ( = )) bicond. elimination
( ) De Morgan
( ) De Morgan
(( ) ( )) distributivity of over
(( ) ( )) distributivity of over
33
Propositional Logic
Inference in PL
34
Outline
Propositional Logic
Inference in PL
3. Propositional Logic
Introduction
Equivalence and Validity
4. Inference in PL
Proof by Resolution
Proof by Model Checking
35
Proof methods
Propositional Logic
Inference in PL
36
Propositional Logic
Inference in PL
Resolution
Conjunctive Normal Form (CNFuniversal)
conjunction of disjunctions of literals
|
{z
}
clauses
E.g., (A B) (B C D)
P?
P
B
OK
A
P?
OK
A
OK S
A
P2,2
OK
A
Conversion to CNF
Propositional Logic
Inference in PL
Resolution algorithm
Propositional Logic
Inference in PL
40
Propositional Logic
Inference in PL
Resolution example
P2,1 B1,1
P1,2
P1,2 B1,1
P2,1
B1,1
P2,1
P1,2
P1,2
41
Completeness of Resolution
Propositional Logic
Inference in PL
Theorem
Ground Resolution Theorem
If a set of clauses is unsatisfiable, then the resolution closure of those clauses
contains the empty clauses
Proof. by contraposition RC (S) does not contain empty clause = S is
satisfiable.
Construct a model for S with sutiable ttruth values for P1 , . . . , Pk as follows
I
42
Model Checking
Propositional Logic
Inference in PL
KB |=
Forward and backward chaining
Horn Form (restricted)
KB = conjunction of Horn clauses
Horn clause =
proposition symbol; or
(conjunction of symbols) = symbol
E.g., C (B = A) (C D = B)
Modus Ponens (for Horn Form): complete for Horn KBs
1 , . . . , n ,
1 n =
Propositional Logic
Inference in PL
Forward chaining
Idea: fire any rule whose premises are satisfied in the KB,
add its conclusion to the KB, until query is found
P = Q
L M = P
B L = M
A P = L
A B = L
A
B
45
Propositional Logic
Inference in PL
L M = P
B L = M
A P = L
A B = L
A
B
M
0
L
0
0
A
B
47
Proof of completeness
Propositional Logic
Inference in PL
Hence m is a model of KB
Backward chaining
Propositional Logic
Inference in PL
49
Propositional Logic
Inference in PL
M
L
B
50
Propositional Logic
Inference in PL
51
Model Checking
Propositional Logic
Inference in PL
KB |=
General case:
KB |= KB is unsatisfiable hence find a counter example to KB
52
Propositional Logic
Inference in PL
Propositional Logic
Inference in PL
Walksat
function WalkSAT(clauses, p, max-flips) returns a satisfying model or failure
inputs: clauses, a set of clauses in propositional logic
p, the probability of choosing to do a random walk move, typically
around 0.5
max-flips, number of flips allowed before giving up
model a random assignment of true/false to the symbols in clauses
for i = 1 to max-flips do
if model satisfies clauses then return model
clause a randomly selected clause from clauses that is false in model
with probability p flip the value in model of a randomly selected symbol
from clause
else flip whichever symbol in clause maximizes the number of satisfied
clauses
return failure
54
Summary
Propositional Logic
Inference in PL
55
Part II
56
Outline
6. Situation calculus
57
Outline
6. Situation calculus
58
Outline
6. Situation calculus
60
Outline
Why FOL?
Syntax and semantics of FOL
Fun with sentences
Wumpus world in FOL
61
62
First-order logic
Functions: father of, best friend, successor, one more than, times, end of
...
63
Logics in general
Language
Propositional logic
First-order logic
Temporal logic
Probability theory
Fuzzy logic
Ontological
Commitment
facts
facts, objects, relations
facts, objects, relations, times
facts
facts + degree of truth
Epistemological
Commitment
true/false/unknown
true/false/unknown
true/false/unknown
degree of belief
known interval value
64
Constants
Variables
Functions
Predicates
Connectives
Equality
Quantifiers
KingJohn, 2, UCB, . . .
x, y , a, b, . . .
Sqrt, Father . . .
BrotherOf , >, . . .
=
=
65
Atomic sentences
Atomic sentence
predicate(term1 , . . . , termn )
or term1 = term2
Term
function(term1 , . . . , termn )
or constant or variable
E.g.,
But:
E.g.,
66
Complex sentences
S1 S2 ,
S1 S2 ,
S1 = S2 ,
S1 S2
E.g.,
67
68
Symbols in FOL are assigned values from the domain D as determined by the
interpretation. Each precise assignment is a model
An atomic sentence predicate(term1 , . . . , termn ) is true
iff the objects referred to by term1 , . . . , termn
are in the relation referred to by predicate in the interpretation
Example:
Consider the interpretation in which
Richard Richard the Lionheart
John the evil King John
Brother the brotherhood relation
Under this interpretation, Brother (Richard , John) is true
just in case Richard the Lionheart and the evil King John
are in the brotherhood relation in the model (the assignment of values of the
world to objects according to the interpretation)
69
71
Universal quantification
hvariablesi hsentencei
Everyone at Berkeley is smart:
x At(x, Berkeley ) = Smart(x)
x P is true in a model iff P is true with x being
each possible object in the model
(Roughly speaking, equivalent to the conjunction of instantiations of P)
(At(KingJohn, Berkeley ) = Smart(KingJohn))
(At(Richard , Berkeley ) = Smart(Richard ))
(At(Berkeley , Berkeley ) = Smart(Berkeley ))
...
Note: quantifiers are only on objects and variables, not on predicates and
functions. This is done in higher order logic.
Eg.: (Likes)Likes(Geroge, Kate)
72
73
Existential quantification
hvariablesi hsentencei
Someone at Stanford is smart:
x At(x, Stanford ) Smart(x)
x P is true in a model iff P is true with x being
some possible object in the model
(Roughly speaking, equivalent to the disjunction of instantiations of P)
(At(KingJohn, Stanford ) Smart(KingJohn))
(At(Richard , Stanford ) Smart(Richard ))
(At(Stanford , Stanford ) Smart(Stanford ))
...
74
75
Properties of quantifiers
x y is the same as y x
x y is the same as y x
x y Loves(x, y )
There is a person who loves everyone in the world
y x Loves(x, y )
Everyone in the world is loved by at least one person
76
Exercise
Equality
78
79
Properties of locations:
x, t At(Agent, x, t) Smelt(t) = Smelly (x)
x, t At(Agent, x, t) Breeze(t) = Breezy (x)
Squares are breezy near a pit:
Diagnostic ruleinfer cause from effect
y Breezy (y ) = x Pit(x) Adjacent(x, y )
Causal ruleinfer effect from cause
x, y Pit(x) Adjacent(x, y ) = Breezy (y )
Neither of these is completee.g., the causal rule doesnt say whether
squares far away from pits can be breezy
Definition for the Breezy predicate:
y Breezy (y ) [ x Pit(x) Adjacent(x, y )]
80
Outline
6. Situation calculus
81
Perception
b, g , t Percept([Smell , b, g ], t) = Smelt(t)
s, b, t Percept([s, b, Glitter ], t) = AtGold (t)
Reflex: t AtGold (t) = Action(Grab, t)
Reflex with internal state: do we have the gold already?
t AtGold (t) Holding (Gold , t) = Action(Grab, t)
Holding (Gold , t) cannot be observed
keeping track of change is essential
82
PIT
Gold
PIT
PIT
PIT
Gold
PIT
S1
PIT
S0
Forward
83
Describing actions I
84
Describing actions II
85
Making plans
86
87
Knowledge Engineer
Summary
First-order logic:
objects and relations are semantic primitives
syntax: constants, functions, predicates, equality, quantifiers
Increased expressive power: sufficient to define wumpus world
Situation calculus:
conventions for describing actions and change in FOL
can formulate planning as inference on a situation calculus KB
89