CSC 2109 Artificial Intelligence: Knowledge Representation
CSC 2109 Artificial Intelligence: Knowledge Representation
Artificial Intelligence
Lecture 3:
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
Representation, Reasoning and
Logic
• Sentence: Individual piece of • Semantics: Mapping from sentences
knowledge to facts in the world
- English sentence forms one - They define the truth of a sentence
piece of knowledge in English in a “possible world”
language - Add the values of 2 and 3, store
them in the memory location
- Statement in C forms one piece
indicated by variable a
of knowledge in C programming
• In the language of arithmetic:
language
x + 2 >= y is a sentence
• Syntax: Form used to represent
x2 + y > is not a sentence
sentences x + 2 >= y is true in all worlds
- Syntax of C indicates legal where the number x + 2 is
combinations of symbols no less than the number y
- a = 2 + 3; is legal x + 2 >= y is true in a world where
- a = + 2 3 is not legal x = 7, y = 1
- Syntax alone does not indicate x + 2 >= y is false in a world where
meaning x = 0, y = 6
Entailment
• There can exist a relationship between items in the language
– Sentences “entail” sentences (representation level)
– Facts “follow” from facts (real world)
• Entail / Follow mean the new item is true if the old items are true
• A collection of sentences, or knowledge base (KB), entail a sentence
– KB |= sentence
– KB entails the sentence iff the sentence is true in all worlds where the KB is
true
Entail
Senten s Senten
ces
S ce S
e e
Representat m m
a a
ion n n
Worl t t
d i i
c c
s s
Follo
Fac ws Fac
ts t
Entailment Examples
• KB • KB
– The Giants won – CookLectures ->
TodayIsTuesday v
– The Reds won TodayIsThursday
• Entails – - TodayIsThursday
– Either the Giants won or the – TodayIsSaturday -> SleepLate
Reds won – Rainy -> GrassIsWet
– CookLectures v TodayIsSaturday
• KB
– - SleepLate
– To get a perfect score your
• Which of these are correct
program must be turned in
today entailments?
– - Sleeplate
– I always get perfect scores
– GrassIsWet
• Entails – - SleepLate v GrassIsWet
– I turned in my program – TodayIsTuesday
today – True
Models
• Logicians frequently use models, which are
formally structured worlds with respect to
which truth can be evaluated. These are our
“possible worlds”.
• M is a model of a sentence s if s is true in M.
• M(s) is the set of all models of s.
• KB entails s (KB |= s) if and only if M(KB) is a
subset of M(s)
• For example, KB = Giants won and Reds
won, s = Giants won
Inference
In AI inference is the process tha a
trained machine learning model uses
to draw conclusions from brand-new
data.
An AI model capable of making
inferences can do so without examples
of the desired result.
We can say in other words that,
inference is an AI model in action.
Inference
• Use two different ways:
– Generate new sentences that are entailed by
KB
– Determine whether or not sentence is
entailed by KB
• A sound inference procedure generates
only entailed sentences
• Modus ponens is sound A, A B
B
1) FAx,y,z[(American(x)&Weapon(y)&N
ation(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)&N
ation(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)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & – 2 & Existential 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)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 11)Owns(Nono, 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)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 11)Owns(Nono, M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 12)Missile(M1)
Missile(x)) -> Sells(West,
Nono,x)] – 10 & And Elimination
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)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 11)Owns(Nono, M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 12)Missile(M1)
Missile(x)) -> Sells(West, Universal Elimination
Nono,x)] 13)Missile(M1) -> Weapon(M1)
4) FA x [Missile(x) -> FORALL v []
Weapon(x)] – If 4 & for
true Universal
universalElimination
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)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 11)Owns(Nono, M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 12)Missile(M1)
Missile(x)) -> Sells(West,
Nono,x)] 13)Missile(M1) -> Weapon(M1)
4) FA x [Missile(x) ->
Weapon(x)] 14)Weapon(M1)
5) FA x [Enemy(x,America) ->
Hostile(x)] – 12, 13, Modus Ponens
6) American(West)
7) Nation(Nono)
8) Enemy(Nono, America)
9) Nation(America)
Prove: West is a Criminal
1) FAx,y,z[(American(x)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 11)Owns(Nono, M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 12)Missile(M1)
Missile(x)) -> Sells(West,
Nono,x)] 13)Missile(M1) -> Weapon(M1)
4) FA x [Missile(x) ->
Weapon(x)] 14)Weapon(M1)
5) FA x [Enemy(x,America) ->
Hostile(x)] 15)Owns(Nono,M1) &
6) American(West)
7) Nation(Nono) Missile(M1) ->
8) Enemy(Nono, America) Sells(West,Nono,M1)
9) Nation(America)
– 3 & Universal Elimination
Prove: West is a Criminal
1) FAx,y,z[(American(x)&
Weapon(y)&Nation(z)&
10)Owns(Nono,M1) &
Hostile(z)& Sells(x,z,y)) -> Missile(M1)
Criminal(x)]
2) EX x [Owns(Nono,x) & 11)Owns(Nono, M1)
Missile(x)]
3) FA x [Owns(Nono,x) & 12)Missile(M1)
Missile(x)) -> Sells(West,
Nono,x)] 13)Missile(M1) -> Weapon(M1)
4) FA x [Missile(x) ->
Weapon(x)] 14)Weapon(M1)
5) FA x [Enemy(x,America) ->
Hostile(x)] 15)Owns(Nono,M1) &
6) American(West)
7) Nation(Nono) Missile(M1) ->
8) Enemy(Nono, America) Sells(West,Nono,M1)
9) Nation(America)
16)Sells(West,Nono,M1)
– 10, 15, Modus Ponens
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) ->
15)Owns(Nono,M1) & Missile(M1) ->
Weapon(x)] Sells(West,Nono,M1)
5) FA x [Enemy(x,America) ->
Hostile(x)]
16)Sells(West,Nono,M1)
6) American(West) 17)American(West) & Weapon(M1) &
7) Nation(Nono)
Nation(Nono) & Hostile(Nono) &
8) Enemy(Nono, America)
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)] 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) -> Sells(West,Nono,M1)
Weapon(x)]
5) FA x [Enemy(x,America) ->
16)Sells(West,Nono,M1)
Hostile(x)] 17)American(West) & Weapon(M1) &
6) American(West) Nation(Nono) & Hostile(Nono) &
7) Nation(Nono)
8) Enemy(Nono, America)
Sells(West,Nono,M1) ->
9) Nation(America) 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) -> Sells(West,Nono,M1)
Weapon(x)] 16)Sells(West,Nono,M1)
5) FA x [Enemy(x,America) ->
Hostile(x)] 17)American(West) & Weapon(M1) &
6) American(West) Nation(Nono) & Hostile(Nono) &
7) Nation(Nono) Sells(West,Nono,M1) -> Criminal(West)
8) Enemy(Nono, America)
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) -> 16)Sells(West,Nono,M1)
Weapon(x)]
17)American(West) & Weapon(M1) &
5) FA x [Enemy(x,America) ->
Hostile(x)]
Nation(Nono) & Hostile(Nono) &
6) American(West) Sells(West,Nono,M1) -> Criminal(West)
7) Nation(Nono) 18)Enemy(Nono,America) -> Hostile(Nono)
8) Enemy(Nono, America) 19)Hostile(Nono)
9) Nation(America) 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) ->
Missile(x)) -> Sells(West, Sells(West,Nono,M1)
Nono,x)]
16)Sells(West,Nono,M1)
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
•
y Breezy(y) -> x Pit(x) & Adjacent(x,y)
– Causal rule: infer effect from cause
• x,y Pit(x) & Adjacent(x,y) -> Breezy(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) <-> [ Pit(x) & Adjacent(x,y)]
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
– sHaveArrow(s) -> HaveArrow(Result(Grab, s))