Lecture 7: Knowledge Representation (part 1/2)

Download Report

Transcript Lecture 7: Knowledge Representation (part 1/2)

Intro to AI
Knowledge Representation &
Reasoning
Ruth Bergman
Fall 2002
Logic & AI
• One of the original problem areas in AI was
mathematical theorem proving: logic theorist, GPS
– first complete inference procedure was computational
• Early on many researchers realized that it was
essential to have a “formal” language for talking
about knowledge
– logic seems like the obvious language
• These two facts have led logic and logical inference
to be generally viewed as essential to symbolic AI
– explicit language for expressing “knowledge”
– formal inference procedures
– nothing “hidden” in the code --- a fully declarative approach
Knowledge-Based
Agent
Sensors
Inference
Agent
Effectors
Environment
Knowledge
Knowledge-Based
Agent
1. Knowledge or epistemological level
“What the agent can know about”
The Golden Gate Bridge links San Francisco and Marin
County
2. Logical level
representation of facts as sentences in a formal language
Links(GGBridge, SF, Marin)
3. Implementation level
how inference is implemented on the agent architecture
Building KB Agent
• Initially input designer’s knowledge in
the form of sentences - declarative
approach
• Design learning mechanism autonomous agent
Representation &
Reasoning
• Knowledge representation : express
knowledge in computer-tractable form
– Syntax : the written form of sentences
– Semantics : facts in the world to which the
sentences refer
• Reasoning : a process of constructing new
physical configurations from old ones
Representation
• Programming language
– good for describing algorithms and concrete data
structures
– hard to represent “there is a blue flower”
• Natural language
– expressive
– ambiguous, depend on context “small dog and cat”
• Good KB representation language
– expressive, concise, unambiguous, effective
– first-order predicate calculus (first order logic)
Syntax of First Order Logic
• Term:
– Constant
p, q, AI
– Variable
x
– Predicate of n arguments (Pn : Un  {True,False})
brother, LeftLegOf
– Function of n arguments (fn : Un  U)
Before, HasColor, Raining
• connective: ^ | v |  |  | 
• quantifier:  | 
Well-Formed Formulae
• AtomicSentence: pred (term1, term2, .. termn)
Brother(Joseph, Reuven)
• Sentence:
– AtomicSentence
–  Sentence
 Brother(Joseph,Jacob)
– Sentence connective Sentence
Brother(Joseph, Reuven) ^ Brother(Joseph, Judea)
– quantifier Sentence
x Brother(Joseph,x) -> Son(x, Jacob)
– (Sentence)
Semantics
• Semantics is the link between what we write
(syntax) and what it means (semantics)
• We must define an interpretation for the
sentences we write. The interpretation gives
the sentence meaning in the world.
• We will assume all of our languages of
compositional: we can recursively define the
meaning of sentences in terms of their
components
Models
• A model of a sentence is any world in which a sentence is true
under a particular interpretation
Example: any world where {p=False, q = False} is a model for
p -> q
• The more claims, the fewer the models
• Models of complex sentences are described by the models of
their component, and can be viewed as sets
Example: Let the set P be the set of all the models of p and Q
the set of all models of q. Then the set Q v P is the set of
all models of p -> q
U
U is the set of all models
P
Q
Models for FOL
• Universe U of objects
• A interpretation function I that
– maps constants to elements of U
– maps function symbols f of n arguments to elements of U
– maps predicates P of n arguments to relations, i.e. a subset PU of Un
• Example: a model of integral arithmetic
– Integers U = {1,2,3,…}
– Functions symbols,
f1= successor ={(0,1), (1,2), (2,3),…}
f2= + ={(0,1,1), (0,2,2), (1,2,3), (0,3,3),…}
– Predicate symbols,
p=lessThan={(0,1), (0,2), (1,2), (0,3)…}
Interpretation in FOL
• meaning of constants
1, 2, jacob, …
• meaning of functions
I(f(t1, t2, ... tn)) = u U if f(I(t1),…I(tn))= u
• meaning of predicates
I(P(t1, t2, ... tn)) = true if <I(t1),…I(tn)> PU
false otherwise
• meaning of connectives ^ | v |  |  | 
Connectives operate on truth values {True, False}
Truth table gives true values for every possible
input values
imply connective: any implication is true
whenever its antecedent is false
• The meaning of a complex sentence is derived
from its parts
p
q
P->q
T
T
T
T
F
F
F
T
T
F
F
T
Variable Substitution
• Consider a substitution s to be a list of pairs x/u where x is a
variable in the language and u is an element of U
• a [s] is the sentence a with all of the variable assignments given
in s
• Example: a = x,y childof(y,x)  parentof(x,y)
a [x/jacob, y/issac] = childof(issac,jacob) parentof(jacob,issac)
Interpretation of
Quantifiers
• meaning of variables
x[x/u] = u
• meaning of quantifiers
x P(x) the predicate P holds for all objects x  U
x P(x) the predicate P holds for some object x  U
• Order of quantification is very important
x y Loves(x,y)
Everybody loves somebody
y x Loves(x,y)
There is someone who is loved by everyone
• The term Well-Formed Formula (wff) is often used for sentences
that have all their variables quantified
• A term with no variables is called a ground term
An Example
 x male(x) v female(x) ^  x (male(x) ^ female(x))
 x y z parentof(x,y) ^ ancesterof(y,z)  ancesterof(x,z)
 x y parentof(x,y)  ancesterof(x,y)
 x parentof(fatherof(x),x) ^ parentof(motherof(x),x) ^
male(fatherof(x)) ^ female(motherof(x))
•  x  y1, y2 parentof(y1,x) ^ parentof(y2,x) ^ (y1 = y2)
• x,y childof(y,x)  parentof(x,y)
• male(jacob), female(rebecca), parentof(rebecca,jacob) .....
•
•
•
•
• E.g. show  x  y ancesterof(y,x)
Logical Reasoning
• We need a proof theory for our representation
• Two notions of determining what follows from
what we know
– KB |=   KB entails a; if KB is true, then so is 
 Sentence  is entailed by KB if all models of KB are
models of 
– KB |-i   inference procedure i derives  from the
sentences in KB
Representation & the “Real
World”
entailment
sentences
Semantics
world
sentences
Semantics
representation
facts
facts
follows
Inference
• Sound reasoning = logical inference = deduction
Valid
A sentence s is valid if it is true in all interpretations
in all possible worlds
necessarily true, tautologies, analytic sentence
A sentence s is satisfiable if it is true for some
Satisfiable interpretation in some world
Unsatisfiable
A sentence s is unsatisfiable if there is no
interpretation in all possible world for which it it true
Inference Procedure
• We can make up any way of creating new
sentences from old
– i is sound if KB |-i  implies that KB |= 
• we only derive statements that are true given what we
know
• the record of the derivation is called a proof
– i is complete if KB |=  implies that KB |-i 
• if a fact is true, we can derive it
• Soundness is essential (and usually easy)
• Completeness is hard (and sometimes
impossible!)
Inference for Propositional
Logic
• [Reminder] Propositional Logic
– Atomic sentence: True, False, p, jacob
– connective: ^ | v |  |  | 
• We could do inference for propositional logic
just by checking models
– 2n potential true values for a sentence with n
atoms
– Impractical even for propositional logic
– Cannot extend this inference procedure for FOL
with infinitely large universe U
Rules of Inference for
Propositional Logic
Modus Ponens
And-Elimination
And-Introduction
Or-Introduction
Double-Negation Elimination
Unit Resolution
Resolution
   ,

1   2  ...   n
i
1 ,  2 ,...,  n
1   2  ...   n
i
1   2  ...   n
 

   , 

   ,   
 
Rules of Inference
Involving Quantifiers
• The connection between the universal and existential quantifiers
–  P(x) ==   x P(x)
–  x  P(x) ==   x P(x)
Universal Elimination
 
 [ / g ]
Sentence , variable n,
ground term g
Existential Elimination
 
 [ / k ]
Sentence , variable n,
constant k no in KB
Existential Introduction

  [g/ ]
Sentence , variable n not in
, ground term g in 
Example
•
From our previous axiomitization
1.  x male(x) v female(x) ^ (male(x) ^ female(x))
2.  x y z parentof(x,y) ^ ancesterof(y,z)  ancesterof(x,z)
3.  x y parentof(x,y)  ancesterof(x,y)
4.  x parentof(fatherof(x),x) ^ parentof(motherof(x),x) ^
male(fatherof(x)) ^ female(motherof(x))
5.  x  y1, y2 parentof(y1,x) ^ parentof(y2,x) ^ (y1 = y2)
6. x,y childof(y,x)  parentof(x,y)
7. male(jacob), female(rebecca), parentof(rebecca,jacob) ...
•
show
–  x  y ancesterof(y,x) ^ female(y)
– childof(jacob, rebecca)
– childof(rebecca,jacob)
Notes on Proofs by
Inference
• A proof may require many steps
• The proof process requires matching, substitution
and application of the inference rules
An Inference Procedure for
FOL?
An inference procedure
1. If  is in KB return yes
2. Apply inferences rules on KB
3. Add new sentences to KB
4. Go to 2
• This inference procedure will find a proof for any true
sentence
• For false sentences this procedure may not halt.
This procedure is semi-decidable.
Building a Knowledge
Base
• The process of building a knowledge base is called knowledge
engineering
• The knowledge engineer must encode domain knowledge in
logic sentences
• Typically, the knowledge engineer is a logician, not a domain
expert.
• Thus, the knowledge engineer interviews domain expert(s) to
learn about the domain. This process is called knowledge
acquisition.
– A realistic domain typically requires thousands of rules
– The knowledge is not available in rule form
– The domain expert’s time is precious ($$$)
– This process may take years – the knowledge engineering
bottleneck
Knowledge
Engineering
• 5-step methodology
– Decide what to talk about
– Decide on a vocabulary of predicates, functions,
and constants : ontology of the domain
– Encode general knowledge about domain : writing
logical sentences or axioms
– Encode descriptions of the specific problem
instances : writing simple atomic sentences
– Pose queries to the inference procedure and get
answers
Electronic Circuits
Domain
• What to talk about: circuits, terminals,
signals, gates, gate types
1
2
C1
X1
3
1
X2
A2
A1
O1
2
Electronic Circuits
Ontology
– Representation of constants
• Gates X1, X2,…
• Gate types XOR, OR, AND and NOT
• Signal value constants : On, Off
– Representation of objects
• Output terminals Out(1, X1) , In(2, X1)
– Representation of predicates on objects
• Type (X1) = XOR v.s. Type(X1, XOR) v.s. XOR(X1)
• Signal(X1) = On
– Representation of relations between objects
• Connected(Out(1, X1) , In(1, X2) )
Electronic Circuits
Representation
• Encode general rules
– If two terminals are connected, then they have the same
signal  i1, i2 Connected (i1, i2)  Signal(i1) = Signal(i1)
– An XOR gate’s output is on iff its inputs are different
 g Type(g)=XOR 
 Signal(Out(1,g)) = on  Signal(In(1,g)) !=
Signal(In(2,g))
– … Five more rules for this domain
• Encode specific instances
– Type(X1) = XOR, …
– Connected(Out(1, X1) , In(1, X2)) …
• Pose queries to the inference procedure
– What are the inputs for Sum bit = Off and Carry bit = On ?
i1, i2, i3 Signal(In(1, C1)) = i1  Signal(In(2, C1)) = i2 
Signal(In(3, C1)) = i3  Signal(Out(1, C1)) = Off 
Signal(Out(2, C1)) = On
General Relations and
Predicates
• Representation of general predicates
– If x is a parent of y then it is an ancestor of y
 x y parentof(x,y)  ancesterof(x,y)
 x y z parentof(x,y) ^ ancesterof(y,z)  ancesterof(x,z)
• Representation of general relations on predicates
– Ancestor is transitive
 x y z ancestorof(x,y) ^ ancesterof(y,z)  ancesterof(x,z)
– Ancestor is asymmetric
 x y z ancestorof(x,y)   ancesterof(y,x)
Higher Order Logics
• General relations on predicates
– Predicate p is transitive
 p Transitive(p) 
 x y p(x,y) ^ p(y,z)  ancesterof(x,z)
– Predicate p is asymmetric
 p Transitive(p) 
 x y p(x,y)   p(y,x)
• Higher-order logic have strictly greater expressive power than
first-order logic.
• Logicians have little understanding of how to reason effectively
with sentences in higher-order logic.
Representation limits of
FOL
• Inheritance
 x bird(x)  flies(x)
 x penguin(x)  bird(x)
• Inheritance with exceptions
 x penguin(x)   flies(x)
penguin(opus)
Can deduce both flies(opus) and  flies(opus)
A contradiction.
• The property of monotonicity
FOL is a monotonic logic. If P follows from KB, then it still
follows when KB is augmented with a new sentence s.
There are nonmonotonic logics that explicitly deal with default
values
General Ontologies
• Special-purpose ontologies
– Are the most efficient representation to solve problems for
the given domain
– Lack re-usability. Portions of knowledge have to be
duplicated from one ontology to another.
• General purpose ontologies
– more demanding to construct
– once done, many advantages
• General purpose ontologies should be applicable in any specialpurpose domain
– Add domain specific rules
• General purpose ontologies enable reasoning in several areas
simultaneously.
– In sufficiently demanding domains, different areas of
knowledge must be unified
General Ontologies
• Categories – define a taxonomic hierarchy where properties are
inherited from more general categories
•
•
•
•
Birds  Pigeons, x Bird(x)  fly(x)
Measures – a representation for mass, age, price, length, etc.
Composite objects – objects belong to categories based on their
composition from subparts. E.g a chair has four legs and a flat
seat
Time, Space and Change– represent a universe of continuous
temporal and spatial dimensions. Times places and objects are
part of this universe.
Events and processes – events are things that occur with space
and time extent; processes are continuous events.
General Ontologies
• Physical objects – allow objects to have different properties at
different times.
E.g. PrimeMinister(Israel)
• Substances – describe properties that are intrinsic to the
substances, rather than properties of the object as a whole.
E.g., x,y x Butter ^ part of(y,x) y Butter
• Mental objects and Beliefs – in multi-agent domains, it is
important for an agent to reason about the mental processes of
the other agents.
General purpose
ontology
•
•
•
•
•
Categories : objects having certain common properties
Measures : quantities of particular type, age, mass...
Composite objects : car with wheels, engines, ...
Time, Space, and Change
Events and Processes : individual event and continuous
events
• Physical Objects
• Substances : Tomato juice is category? Physical object?
• Mental Objects and Beliefs : reason about belief of its
own or others
West Wessex Marathon
Race
(by Martin Hollis)
•
With a field of five for the west wessex marathon race, there
was little to interest the bettors. So, Peter Piper opened one of
his ingenious books where he accepts multiple bets at high
odds. To place a multiple bet, you must bet on two
propositions, and you will win only if you are wholly successful.
Peter Piper is now on an extended vacation because of the
bettors who lost these bets:
1.
2.
3.
4.
5.
A will not win the gold, nor B the silver.
C will win a medal, and D will not.
D and E will both win medals.
D will not win the silver, nor E the bronze.
A will win a medal, and C will not.
Who won which of the medals?
West Wessex Marathon
Race
I.
A racer medals iff he receives a gold, silver or bronze medal
x medal(x)  (gold(x) v silver(x) v bronze(x))
II.
A racer can only receive one medal
a.
x gold(x)  medal(x) ^ (silver(x) v bronze(x))
b.
x silver(x)  medal(x) ^ (gold(x) v bronze(x))
c.
x bronze(x)  medal(x) ^ (silver(x) v gold(x))
Only one race can receive a gold (silver, bronze) medal
III.
a.
x,y gold(x) ^ x != y   gold(y)
b.
x,y silver(x) ^ x != y   silver(y)
x,y bronze(x) ^ x != y   bronze(y)
IV.
Some participant must win a gold (silver, bronze) medal
a.
x gold(x)
b.
x silver(x)
c.
x bronze(x)
c.
West Wessex Marathon
Race
1.
A will not win the gold, nor B the silver is false
gold(A) v silver(B)
2.
C will win a medal, and D will not is false
 medal(C) v medal(D)
3.
D and E will both win medals is false
 medal(D) v  medal(E)
4.
D will not win the silver, nor E the bronze is false
silver(D) v bronze(E)
5.
A will win a medal, and C will not is false
 medal(A) v medal(C)
•
Who won which of the medals? Proof in class.
Knights & Knaves
•
A very special island is inhabited only by
knights and knaves. Knights always tell the
truth, and knaves always lie.You meet two
inhabitants Zoey and Mel. Zoey tells you Mel
and I are both knaves.
1. Is Zoey a knight or knave?
2. Is Mel a knight or knave?
Knights & Knaves
•
A very special island is inhabited only by knights and
knaves.
•
knight(x)   knave(x)
Knights always tell the truth
x,s knight(x) ^ tell(x,s)  TV(s)
knaves always lie
•
x,s knave(x) ^ tell(x,s)   TV(s)
The meaning of the truth value predicate (TV)
•
•
s TV(s)  s, s  TV(s)   s
Zoey tells you Mel and I are both knaves.
tell(Zoey, knave(Zoey)^knave(Mel))
1.
Is Zoey a knight or knave?
2.
Is Mel a knight or knave?