Professional Documents
Culture Documents
Cpts 440 / 540 Artificial Intelligence: Knowledge Representation
Cpts 440 / 540 Artificial Intelligence: Knowledge Representation
Artificial Intelligence
Knowledge Representation
Knowledge Representation
Knowledge Representation
• When we use search to solve a problem we
must
– Capture the knowledge needed to formalize the
problem
– Apply a search technique to solve problem
– Execute the problem solution
Role of KR
• The first step is the role of “knowledge
representation” in AI.
• Formally,
– The intended role of knowledge representation in artificial
intelligence is to reduce problems of intelligent action to
search problems.
• A good description, developed within the conventions
of a good KR, is an open door to problem solving
• A bad description, using a bad representation, is a
brick wall preventing problem solving
A Knowledge-Based Agent
• We previously talked about applications of search but not about
methods of formalizing the problem.
• Now we look at extended capabilities to general logical reasoning.
• Here is one knowledge representation: logical expressions.
• A knowledge-based agent must be able to
– Represent states, actions, etc.
– Incorporate new percepts
– Update internal representations of the world
– Deduce hidden properties about the world
– Deduce appropriate actions
• We will
– Describe properties of languages to use for logical reasoning
– Describe techniques for deducing new information from current information
– Apply search to deduce (or learn) specifically needed information
The Wumpus World Environment
Percepts
WW Agent Description
• Performance measure
– gold +1000, death -1000
– -1 per step, -10 for using arrow
• Environment
– Squares adjacent to wumpus are smelly
– Squares adjacent to pit are breezy
– Glitter iff gold is in same square
– Shooting kills wumpus if agent facing it
– Shooting uses up only arrow
– Grabbing picks up gold if in same square
– Releasing drops gold in same square
• Actuators
– Left turn, right turn, forward, grab,
release, shoot
• Sensors
– Breeze, glitter, smell, bump, scream
WW Environment Properties
• Observable? • Static?
– Partial – Yes (for now), wumpus
• Deterministic? and pits do not move
– Yes • Discrete?
• Episodic? – Yes
– Sequential • Single agent?
– Multi (wumpus,
eventually other agents)
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Now we look at
B, A B
• Abduction is not sound A
a, b[City(a) cDogCatcher (c) ( Dog (b) Lives(b, a) Bit (b, c))]
Examples
• No human enjoys golf
Examples
• No human enjoys golf
x[ Human ( x ) Enjoys ( x , Golf )
• Some professor that is not a historian writes
programs
Examples
• No human enjoys golf
x[ Human ( x ) Enjoys ( x , Golf )
• Some professor that is not a historian writes
programs
x[Pr ofessor ( x) Historian( x) Writes ( x, Pr ograms)]
• Every boy owns a dog
Examples
• No human enjoys golf
x[ Human ( x ) Enjoys ( x , Golf )
• Some professor that is not a historian writes programs
x[Pr ofessor ( x) Historian( x) Writes ( x, Pr ograms)]
• Every boy owns a dog
xy[ Boy ( x ) Owns ( x, y )]
yx[ Boy ( x ) Owns ( x, y )]
– Do these mean the same thing?
– Brothers are siblings
– “Sibling” is reflexive and symmetric
– One’s mother is one’s female parent
– A first cousin is a child of a parent’s sibling
Higher-Order Logic
• FOPC quantifies over objects in the universe.
• Higher-order logic quantifies over relations and
functions as well as objects.
– All functions with a single argument return a value of 1
• x, y [Equal(x(y), 1)]
– Two objects are equal iff all properties applied to them
are
equivalent
• x, y [(x=y) <-> ( p [p(x) <-> p(y)])]
– Note that we use “=“ as a shorthand for equal, meaning
they are in fact the same object
Additional Operators
• Existential Elimination
– v [..v..]
– Substitute k for v anywhere in sentence, where k is a constant (term
with no arguments) and does not already appear in the sentence
(Skolemization)
• Existential Introduction
– If [..g..] true (where g is ground term)
– then v[..v..] true (v is substituted for g)
• Universal Elimination
– x [..x..]
– Substitute M for x throughout entire sentence, where M is a constant
and does not already appear in the sentence
Example Proof
Known: Prove: Lulu is older than Fifi
1. If x is a parent of y, then x is (Older(Lulu, Fifi))
older than y 4. Parent(Lulu, Fifi)
– x,y [Parent(x,y) -> Older(x,y)] – 2,3, Universal Elimination,
2. If x is the mother of y, then x is Modus Ponens
a parent of y 5. Older(Lulu, Fifi)
– x,y [Mother(x,y) -> Parent(x,y)] – 1,4, Universal Elimination,
Modus Ponens
3. Lulu is the mother of Fifi
– We “bind” the variable to a
– Mother(Lulu, Fifi)
constant
Example Proof
The law says that it is a crime for an American to
sell weapons to hostile nations.
1) FAx,y,z[(American(x)&Weapon(y)&Nation(z)&
Hostile(z)&Sells(x,z,y)) -> Criminal(x)]
Example Proof
The law says that it is a crime for an American to
sell weapons to hostile nations. The country
Nono, an enemy of America, has some missiles,
and all of its missiles were sold to it by Colonel
West, who is an American.
1) FAx,y,z[(American(x)&Weapon(y)&Nation(z)&
Hostile(z)&Sells(x,z,y)) -> Criminal(x)]
2) EX x [Owns(Nono,x) & Missile(x)]
Example Proof
The law says that it is a crime for an American to sell weapons to
hostile nations. The country Nono, an enemy of America, has some
missiles, and all of its missiles were sold to it by Colonel West, who is
an American.
1) FAx,y,z[(American(x)&Weapon(y)&Nation(z)&Hostile(z)&
Sells(x,z,y)) -> Criminal(x)]
2) EX x [Owns(Nono,x) & Missile(x)]
3) FA x [Owns(Nono,x) & Missile(x)) -> Sells(West, Nono,x)]
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) -> Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a criminal.
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> – 2 & Existential Elimination
Criminal(x)]
2) EX x [Owns(Nono,x) &
Missile(x)]
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
Nono,x)]
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & – 10 & And Elimination
Missile(x)]
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
Nono,x)]
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 12) Missile(M1)
Missile(x)]
3) FA x [Owns(Nono,x) &
– 10 & And Elimination
Missile(x)) -> Sells(West,
Nono,x)]
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 12) Missile(M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Universal Elimination
Missile(x)) -> Sells(West,
Nono,x)]
– 4 & Universal Elimination
FORALL v []
4) FA x [Missile(x) -> Weapon(x)]
If true for universal variable v,
5) FA x [Enemy(x,America) ->
then true for a ground term
Hostile(x)]
(term with no variables)
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 12) Missile(M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)) -> Sells(West,
Nono,x)] 14) Weapon(M1)
4) FA x [Missile(x) -> Weapon(x)] – 12, 13, Modus Ponens
5) FA x [Enemy(x,America) ->
Hostile(x)]
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 12) Missile(M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)) -> Sells(West,
Nono,x)] 14) Weapon(M1)
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) ->
15) Owns(Nono,M1) & Missile(M1) ->
Hostile(x)] Sells(West,Nono,M1)
6) American(West)
7) Nation(Nono)
– 3 & Universal Elimination
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 12) Missile(M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)) -> Sells(West,
Nono,x)] 14) Weapon(M1)
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) ->
15) Owns(Nono,M1) & Missile(M1) ->
Hostile(x)] Sells(West,Nono,M1)
6) American(West)
7) Nation(Nono) 16) Sells(West,Nono,M1)
8) Enemy(Nono, America) – 10, 15, Modus Ponens
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West, 14) Weapon(M1)
Nono,x)]
4) FA x [Missile(x) -> Weapon(x)]
15) Owns(Nono,M1) & Missile(M1) ->
5) FA x [Enemy(x,America) -> Sells(West,Nono,M1)
Hostile(x)]
6) American(West)
16) Sells(West,Nono,M1)
7) Nation(Nono) 17) American(West) & Weapon(M1) &
8) Enemy(Nono, America)
Nation(Nono) & Hostile(Nono) &
9) Nation(America)
Sells(West,Nono,M1) -> Criminal(West)
– 1, Universal Elimination (x West) (y M1) (z
Nono)
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)]
2) EX x [Owns(Nono,x) &
12) Missile(M1)
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West, 14) Weapon(M1)
Nono,x)]
15) Owns(Nono,M1) & Missile(M1) ->
4) FA x [Missile(x) -> Weapon(x)]
5) FA x [Enemy(x,America) -> Sells(West,Nono,M1)
Hostile(x)] 16) Sells(West,Nono,M1)
6) American(West)
7) Nation(Nono) 17) American(West) & Weapon(M1) &
8) Enemy(Nono, America) Nation(Nono) & Hostile(Nono) &
9) Nation(America)
Sells(West,Nono,M1) -> Criminal(West)
18) Enemy(Nono,America) -> Hostile(Nono)
– 5, Universal Elimination
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)&
Hostile(z)& Sells(x,z,y)) -> 11) Owns(Nono, M1)
Criminal(x)] 12) Missile(M1)
2) EX x [Owns(Nono,x) &
Missile(x)] 13) Missile(M1) -> Weapon(M1)
3) FA x [Owns(Nono,x) & 14) Weapon(M1)
Missile(x)) -> Sells(West,
Nono,x)] 15) Owns(Nono,M1) & Missile(M1) ->
4) FA x [Missile(x) -> Weapon(x)] Sells(West,Nono,M1)
5) FA x [Enemy(x,America) -> 16) Sells(West,Nono,M1)
Hostile(x)]
6) American(West) 17) American(West) & Weapon(M1) &
7) Nation(Nono) Nation(Nono) & Hostile(Nono) &
8) Enemy(Nono, America) Sells(West,Nono,M1) -> Criminal(West)
9) Nation(America)
18) Enemy(Nono,America) -> Hostile(Nono)
19) Hostile(Nono)
– 8, 18, Modus Ponens
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)& 11) Owns(Nono, M1)
Hostile(z)& Sells(x,z,y)) ->
Criminal(x)] 12) Missile(M1)
2) EX x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)] 14) Weapon(M1)
3) FA x [Owns(Nono,x) &
Missile(x)) -> Sells(West,
15) Owns(Nono,M1) & Missile(M1) ->
Nono,x)] Sells(West,Nono,M1)
4) FA x [Missile(x) -> Weapon(x)] 16) Sells(West,Nono,M1)
5) FA x [Enemy(x,America) -> 17) American(West) & Weapon(M1) & Nation(Nono) &
Hostile(x)]
Hostile(Nono) & Sells(West,Nono,M1) ->
6) American(West)
Criminal(West)
7) Nation(Nono)
8) Enemy(Nono, America)
18) Enemy(Nono,America) -> Hostile(Nono)
9) Nation(America) 19) Hostile(Nono)
20) American(West) & Weapon(M1) & Nation(Nono) &
Hostile(Nono) & Sells(West,Nono,M1)
– 6, 7, 14, 16, 19, And Introduction
Prove: West is a Criminal
1) FAx,y,z[(American(x)& 10) Owns(Nono,M1) & Missile(M1)
Weapon(y)&Nation(z)& 11) Owns(Nono, M1)
Hostile(z)& Sells(x,z,y)) ->
12) Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 13) Missile(M1) -> Weapon(M1)
Missile(x)] 14) Weapon(M1)
3) FA x [Owns(Nono,x) & 15) Owns(Nono,M1) & Missile(M1) -> Sells(West,Nono,M1)
Missile(x)) -> Sells(West,
16) Sells(West,Nono,M1)
Nono,x)]
4) FA x [Missile(x) -> Weapon(x)] 17) American(West) & Weapon(M1) & Nation(Nono) &
5) FA x [Enemy(x,America) ->
Hostile(Nono) & Sells(West,Nono,M1) ->
Hostile(x)] Criminal(West)
6) American(West) 18) Enemy(Nono,America) -> Hostile(Nono)
7) Nation(Nono) 19) Hostile(Nono)
8) Enemy(Nono, America) 20) American(West) & Weapon(M1) & Nation(Nono) &
9) Nation(America) Hostile(Nono) & Sells(West,Nono,M1)
21) Criminal(West)
– 17, 20, Modus Ponens
FOPC and the Wumpus World
• Perception rules
– b,g,t Percept([Smell,b,g],t) -> Smelled(t)
– Here we are indicating a Percept occurring at time t
– s,b,t Percept([s,b,Glitter],t) -> AtGold(t)
• We can use FOPC
to write rules for selecting actions:
– Reflex agent: t AtGold(t) -> Action(Grab, t)
– Reflex agent with internal state:
t AtGold(t) & -Holding(Gold,t) -> Action(Grab, t)
– Holding(Gold,t) cannot be observed, so keeping track of
change is essential
Deducing Hidden Properties
• Properties of locations:
• Squares are breezy near a pit
– Diagnostic rule: infer cause from effect
& Adjacent(x,y)
• yBreezy(y) -> x Pit(x)
– Causal rule: infer effect from cause
• Pit(x) & Adjacent(x,y) -> Breezy(y)
x,y
• Neither of these is complete
• For example, causal rule doesn’t say whether squares far
away from pits can be breezy
• Definition for Breezy predicate
– Breezy(y) & Adjacent(x,y)]
<-> [ Pit(x)
Inference As Search
• Operators are inference rules
• States are sets of sentences
• Goal test checks state to see if it contains query sentence
• AI, UE, MP a common inference pattern, but generate a huge
branching factor
• We need a single, more powerful inference rule
Generalized Modus Ponens
• If we have a rule
– p1(x) & p2(x) & p3(x,y) & p4(y) & p5(x,y) -> q(x,y)
• Each p involves universal / existential quantifiers
• Assume each antecedent appears in KB
– p1(WSU)
– p2(WSU)
– p3(WSU, Washington)
– p4(Washington)
– p5(WSU, Washington)
• If we find a way to “match” the variables
• Then we can infer q(WSU, Washington)
GMP Example
• Rule: Missile(x) & Owns(Nono, x) ->
Sells(West, Nono,x)
• KB contains
– Missile(M1)
– Owns(Nono,M1)
• To apply, GMP, make sure instantiations of x
are the same
• Variable matching process is called unification
Keeping Track Of Change
• Facts hold in situations, rather than forever
– Example, Holding(Gold,Now) rather than Holding(Gold)
• Situation calculus is one way to represent change in FOPC
– Adds a situation argument to each time-dependent predicate
– Example, Now in Holding(Gold,Now) denotes a situation
• Situations are connected by the Result function
– Result(a,s) is the situation that results from applying action a in s
Describing Actions
• Effect axiom: describe changes due to action
– sAtGold(s) -> Holding(Gold, Result(Grab, s))
• Frame axiom--describe non-changes due to action
– s HaveArrow(s) -> HaveArrow(Result(Grab, s))