Unit 3 Knowledge Representation
Unit 3 Knowledge Representation
KNOWLEDGE
REPRESENTATION
Knowledge in Expert Systems
Conventional
Knowledge-Based
Programming
Systems
Algorithms Knowledge
+ Data Structures + Inference
= Programs = Expert System
A Knowledge-Based Agent
• A knowledge-based agent consists of a knowledge base
(KB) and an inference engine (IE).
• A knowledge-base is a set of representations of what
one knows about the world (objects and classes of
objects, the fact about objects, relationships among
objects, etc.)
• Each individual representation is called a sentence.
• The sentences are expressed in a knowledge
representation language.
• Examples of sentences
– The moon is made of green cheese
– If A is true then B is true
– A is false
– All humans are mortal
– Confucius is a human
3
• The Inference engine derives new sentences from the input
and KB
• The inference mechanism depends on representation in KB
• The agent operates as follows:
1. It receives percepts from environment
2. It computes what action it should perform (by IE and KB)
3. It performs the chosen action (some actions are simply
inserting inferred new facts into KB).
domain independent alg
ASK Learning
(KB update)
Knowledge
TELL
Base
domain specific content
4
A simple knowledge-based agent
7
Representation, Reasoning, and Logic
• The objective of knowledge representation is to express
knowledge in a computer-tractable form, so that agents
can perform well.
• A knowledge representation language is defined by:
– Its syntax which defines all possible sequences of
symbols that constitute sentences of the language
(grammar to form sentences)
– Its semantics determines the facts in the world to
which the sentences refer (meaning of sentences)
• Each sentence makes a claim about the world.
– Its proof theory (inference rules and proof
procedures)
8
LOGIC
• Inference
– Deriving new sentences from old
– e.g., using a set of logical statements to infer new ones
• Environment
– Cave of 4×4
– Agent enters in [1,1]
– 16 rooms
• Wumpus: A deadly beast who kills
anyone entering his room.
• Pits: Bottomless pits that will trap
you forever.
• Gold
Wumpus World
• Agents Sensors:
– Stench next to Wumpus
– Breeze next to pit
– Glitter in square with gold
– Bump when agent moves into a wall
– Scream from wumpus when killed
• Agents actions
– Agent can move forward, turn left or
turn right
– Shoot, one shot
Wumpus World PEAS description
• Performance measure
– gold +1000, death -1000
– -1 per step, -10 for using the arrow
• Environment
– Squares adjacent to wumpus are smell
– 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
• Sensors: Stench, Breeze, Glitter, Bump, Scream
• Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
Wumpus world characterization
entail
Sentences Sentences
represent represent
Conceptualization
World W
hold
Facts Facts
about W about W
hold
What is a logical language?
• A formal language
– KB = set of sentences
• Syntax
– what sentences are legal (well-formed)
– E.g., arithmetic
• X+2 >= y is a wf sentence, +x2y is not a wf sentence
• Semantics
– loose meaning: the interpretation of each sentence
– More precisely:
• Defines the truth of each sentence wrt to each possible world
– e.g,
• X+2 = y is true in a world where x=7 and y =9
• X+2 = y is false in a world where x=7 and y =1
B
B
B
B B
B B
B
Wumpus Models
B
B
B
B B
B B
B
Wumpus Models
B
B
B
B B
B B
B
B
B
B
B B
B B
B
B
B
B
B B
B B
B
B
B
B
B B
B B
B
– Connectives: , , ,
– Propositional symbols, e.g., P, Q, R, …
– True, False
Syntax of Propositional Logic
•
• Examples:
– A B C is equivalent to ((A)B)C
Models in Propositional Logic
• KB `i a
• Soundness: Inference procedure i is sound if whenever KB `i a,
it is also true that
KB ² a
• Completeness: Inference procedure i is complete if whenever
KB ² a, it is also true that KB `i a
Inference by enumeration
Depth-first enumeration of all models is sound and complete
•
•
Validity and satisfiability
A sentence is valid if it is true in all models,
e.g., True, A A, A A, (A (A B)) B
• Modus Ponens: a ) b, a ` b
(WumpusAhead Æ WumpusAlive) ) Shoot,
(WumpusAhead Æ WumpusAlive) a)b
a
` Shoot b
• And-Elimination: a Æ b ` a
(WumpusAhead Æ WumpusAlive) aÆb
` WumpusAlive a
• Resolution: a Ç b, : b Ç g ` a Ç g
(WumpusDead Ç WumpusAhead), aÇ b
(: WumpusAhead Ç Shoot) :bÇg
` (WumpusDead Ç Shoot) aÇ g
Proof Using Rules of Inference
Prove A ) B, (A Æ B) ) C, Therefore A ) C
• A)B´:AÇB
• A Æ B ) C ´ : (A Æ B) Ç C ´ : A Ç : B Ç C
• So : A Ç B resolves with : A Ç : B Ç C deriving : A Ç C
• This is equivalent to A ) C
Rules of Inference (continued)
• And-Introduction
a1, a2, …, an
a1 Æ a2 Æ …Æ an
• Or-Introduction
ai
a1 Ç a2 Ç …ai … Ç an
• Double Negation
::a
a
• Unit Resolution (special case of resolution)
aÇ b Alternatively: : a ) b
:b :b
a a
Wumpus World KB
• Proposition Symbols for each i,j:
– Let Pi,j be true if there is a pit in square i,j
– Let Bi,j be true if there is a breeze in square i,j
• Sentences in KB
– “There is no pit in square 1,1”
R1: : P1,1
– “A square is breezy iff pit in a neighboring square”
R2: B1,1 , (P1,2 Ç P2,1)
R3: B1,2 , (P1,1 Ç P1,3 Ç P2,2)
– “Square 1,1 has no breeze”, “Square 1,2 has a breeze”
R4: : B1,1
R5: B1,2
Inference in Wumpus World
• Apply biconditional elimination to R2:
R6: (B1,1) (P1,2 Ç P2,1)) Æ ((P1,2 Ç P2,1) ) B1,1)
• Apply AE to R6:
R7: ((P1,2 Ç P2,1) ) B1,1)
• Contrapositive of R7:
R8: (: B1,1 ) : (P1,2 Ç P2,1))
• Modus Ponens with R8 and R4 (: B1,1):
R9: :(P1,2 Ç P2,1)
• de Morgan:
R10: : P1,2 Æ : P2,1
Searching for Proofs
• Finding proofs is exactly like finding solutions to
search problems.
• Can search forward (forward chaining) to derive goal
or search backward (backward chaining) from the
goal.
• Searching for proofs is not more efficient than
enumerating models, but in many practical cases, it’s
more efficient because we can ignore irrelevant
propositions
Full Resolution Rule Revisited
• Start with Unit Resolution Inference Rule:
• Example:
(A Ç B Ç : C) Æ (B Ç D) Æ (: A) Æ (B Ç C)
clause
CNF Example
Example: (A Ç B) , (C ) D)
• Eliminate ,
((A Ç B) ) (C ) D)) Æ ((C ) D) ) (A Ç B)
• Eliminate )
(: (A Ç B) Ç (: C Ç D)) Æ (: (: C Ç D) Ç (A Ç B) )
• Drive in negations
((: A Æ : B) Ç (: C Ç D)) Æ ((C Æ : D) Ç (A Ç B))
• Distribute
(: A Ç : C Ç D) Æ (: B Ç : C Ç D) Æ (C Ç A Ç B) Æ (: D Ç A Ç B)
Resolution
Conjunctive Normal Form (CNF)
conjunction of disjunctions of literals
clauses
E.g., (A B) (B C D)
P1,3
– 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 β
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Proof of completeness
5. Hence m is a model of KB
6. If KB╞ q, q is true in every model of KB, including m
Backward chaining
Idea: work backwards from the query q:
to prove q by BC,
check if q is known already, or
prove by BC all premises of some rule concluding q
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Backward Chaining Example
P) Q
LÆ M ) P
BÆL)M
AÆ P) L
AÆ B ) L
A
B
Forward Chaining vs. Backward Chaining
P1,1
W1,1
Bx,y (Px,y+1 Px,y-1 Px+1,y Px-1,y)
Sx,y (Wx,y+1 Wx,y-1 Wx+1,y Wx-1,y)
W1,1 W1,2 … W4,4
W1,1 W1,2
W1,1 W1,3
…
t t
• Rapid proliferation of clauses
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 model
– entailment: necessary truth of one 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.
• Resolution is complete for propositional logic
Forward, backward chaining are linear-time, complete for Horn
clauses
• Propositional logic lacks expressive power