Chapter 4 AI
Chapter 4 AI
2
Knowledge Representation (KR)
Knowledge: What and Why?
o Knowledge includes facts about the real world entities and the
relationship between them
o Knowledge-based Systems (KBSs) are useless without the
ability to represent knowledge.
Knowledge Knowledge
acquisition Representation Knowledge
(Extract knowledge (choose KR Method & Base
of Human Expert) reasoning strategy)
5
The two main tasks of KE
o Knowledge acquisition: The knowledge engineer interview the real
human experts to be educated about the domain and to elicit the
required knowledge, in a process called knowledge acquisition
o Knowledge Representation techniques such as logic are a powerful
tool for KR and reasoning. However, such techniques consists of
only the syntax, semantics and proof theory.
–KR techniques do not offer any guidance as to what facts should be expressed,
nor what vocabulary should be used to express them
o Knowledge base is used to store a set of facts and rules about the
domain expressed in a suitable representation language
–Each individual representation are called sentences
–Sentences are expressed in a (formal) knowledge representation (KR) language
6
Knowledge Representation & Reasoning
o Knowledge Representation (KR): express knowledge
explicitly in a computer-tractable way such that the agent
can reason out.
o Parts of KR language:
–Syntax of a language: describes the possible configuration to form
sentences. E.g.: if x & y denote numbers, then x > y is a sentence
about numbers
–Semantics: determines the facts in the world to which the sentences
refer. E.g.: x > y is false when y is greater than x and true otherwise
o Reasoning: is the process of constructing new sentences
from existing facts in the KB.
–Proper reasoning ensures that the new configuration represent facts
that actually follow from the facts in the KB.
7
Logic as KR
o A Logic is a formal language in which knowledge can be
represented such that conclusions can easily be drawn.
–It is a declarative language to assert sentences and deduce from
sentences.
o Components of a formal logic include syntax, semantics,
reasoning and inference mechanism.
–Syntax: what expressions/structures are allowed in the language.
Describes how to make sentences
E.g. mycar (red) is ok, but mycar(grey or green) is not.
–Semantics: express what sentences mean, in terms of a mapping to
real world.
• The meaning of a sentence is not intrinsic to that sentence. Semantics relate
sentences to reality.
• E.g. mycar (red) means that my car is red.
–Proof Theory: It is a means of carrying our reasoning using a set of
rules. It helps to draw new conclusions from existing statements in
8
the logic.
Why formal languages (Logic) ?
o An obvious way of expressing or representing facts and
thoughts is by writing them in a natural language such as
English, Amharic, etc. However,
– The meaning of a sentence depends on the sentence itself and on the
context on which the sentence was spoken
e.g. Look!
– Natural languages exhibit ambiguity.
E.g. small dogs and cats.
– A single sentence can usually be interpreted in more than one way,
possibly inhibiting reasoning. Consider English sentences like:
“The boy saw a girl with a telescope”
“Our shoes are guaranteed to give you a fit”
o Ambiguity makes reasoning difficult and incomplete.
– Hence we need formal languages to express facts and concepts in
an unambiguous and well-defined way.
9
Propositional logic
o A simple language useful for showing key ideas and definitions
o Syntax: PL allows facts about the world to be represented as
sentences formed from:
Logical constants: True, False
Proposition symbols (P, Q, R, …) are used to represent facts
about the world: e.g.: P = "It is hot“, Q = "It is humid“, R = "It is
raining“
Logical connectives: not (), and (), or (), implies (), is
equivalent, if and only if ().
Precedence order from highest to lowest is: , ,,,
e.g. The sentence P v Q R S is equivalent to [(P) v (Q
R)] S
Parenthesis ( ): Used for grouping sentences and to specify order of
precedence
10
Propositional logic (PL) sentences
o A sentence is made by linking prepositional symbols
together using logical connectives.
– There are atomic and complex sentences.
– Atomic sentences consist of propositional symbol (e.g. P, Q,
TRUE, FALSE)
– Complex sentences are combined by using connectives or
parenthesis:
– while S and T are atomic sentences, S T, (S T), (S T), (S
T), and (S T) are complex sentences.
14
Proof: Inference Rules
o Inference is used to create new sentences that logically
follow from a given set of sentences in the KB.
–It captures patterns of inferences that occur over & over
again.
–Once a rule is established, it can be used to make
inferences without going through the tedious process of
building truth tables
o Given set of inference rules (I) and set of sentences (KB);
Inference is the process of applying successive inference
rules from I to KB, each rule inferring new facts and
adding its conclusion to KB
–Example: Modus Ponens: { , } |-
–There are different inference rules (including logical
equivalence) that can be used for proofing and reasoning
purpose. 15
Logical equivalence
•Two sentences are logically equivalent iff they are true in same models
20
Example
1.Battery-OK Bulbs-OK Headlights-Work
2.Battery-OK Starter-OK Empty-Gas-Tank Engine-Starts
3.Engine-Starts Flat-Tire Car-OK
4.Headlights-Work
5.Battery-OK
6.Starter-OK
7.Empty-Gas-Tank
8.Car-OK
Proof
Proof: Flat-Tire 9. Battery-OK Starter-OK (5+6)
10. Battery-OK Starter-OK Empty-
Gas-Tank (9+7)
11. Engine-Starts (2+10)
12. Engine-Starts Flat-Tire (3+8)
13. Flat-Tire (11+12) 21
Example
Construct formal proof of validity for the following
problem:
If the investigation continues, then new evidence is brought
to light. If new evidence is brought to light, then several
leading citizens are implicated. If several leading citizens
are implicated, then the newspapers stop publicizing the
case. If continuation of the investigation implies that the
newspapers stop publicizing the case, then the bringing to
light of new evidence implies that the investigation
continues. The investigation does not continue. Therefore,
new evidence is not brought to light.
Represent using PL and proof the conclusion that “new
evidence is not brought to light”.
22
Solution
Let
C: The investigation continues.
B: New evidence is brought to light.
I: Several leading citizens are implicated.
S: The newspapers stop publicizing the case.
1. CB
2. BI
3. IS
4. (C S) (B C)
5. C
6. CI 1,2 (Hypothetical Syllogism)
7. CS 6,3 (Hypothetical Syllogism)
8. BC 7,4 (Modus Ponens)
9. B 8,5 (Modus Tollens)
23
Exercise
Let p stand for the proposition “I bought a lottery ticket”
and q for “I won the jackpot”.
• Express the following as natural English sentences:
(a) ¬p
(b) p q
(c) p q
(d) p q
(e) ¬p ¬q
(f) ¬p (p q)
24
Propositional logic is a weak language
o PL cannot handle even a domain with small worlds. The
problem is that there are just too many propositions to handle
since it only has one representational device: the proposition
o In PL world consists of just facts. It is hard to :
–Identify individuals: E.g., Mary, 3
–Describe properties of (or relations between) individuals. E.g.
Belete is taller than Gelaw
–Generalize for a given universe. E.g., all triangles have 3 sides
o Example: Prove that “my dog Fido is Nice, given that “all dogs
are Nice.”
–This requires to get at the structure and meanings of statements
(where FOL is useful).
25
First Order Logic
o First-Order Logic (FOL) is expressive enough to
concisely represent any kind of situation that are
expressed in natural language.
–FOL represents objects and relations between objects,
variables, and quantifiers in addition to propositions
Every elephant is gray:
x (elephant(x) → gray(x))
26
Syntax of FOL
o Constants symbol
– names (like Jonas, Kebede, …), numbers (like 1, 2, … n), ...
o Predicates:
– Predicates used to relate one object with another. E.g. brother, >,...
o Functions: Returns value (Sqrt, mother-of,...)
o Variables: x, y, a, b,...
– Important to increase generalization capability of KB
o Connectives:
– retains connectives used in PL (, , , , )
o Quantifiers:
– Quantifiers specify whether all or some objects satisfy properties
or relations between objects
– Two standard quantifiers: Universal (" for all, for every) and
Existential ($ there exists, some)
27
Quantification
28
Universal quantification
o Universal Quantifiers: makes statements about every object
<variables> <sentence>
–Everyone at AAU is smart:
x At(x,AAU) Smart(x)
–All cats are mammals:
x cat(x) mammal(x)
x man(x) mortal(x)
man(Aristotle)
so we can conclude that: mortal(Aristotle)
–This involves matching man(x) against man(Aristotle) and
binding the variable x to Aristotle.
36
Unification
• Unification is an algorithm for determining the substitutions needed
to make two expressions match
– Unification is a "pattern matching" procedure that takes two
atomic sentences as input, and returns the most general unifier,
i.e., a shortest length substitution list that makes the two literals
match.
– E.g: To make, say p(X, X) and p( Y, Z) match, subst(X/ Y) or subst(X/
Z)
• Note: It is possible to substitute two variables with the same value,
but not the same variables with different values.
•Example
Sentence 1 Sentence 2 Unifier
group(x, cat(x), dog(Bill)) group(Bill, cat(Bill), y) {x/Bill, y/dog(Bill)}
group(x, cat(x), dog(Bill)) group(Bill, cat(y), z) {x/Bill, y/Bill, z/dog(Bill)}
group(x, cat(x), dog(Jane)) group(Bill, cat(y), dog(y)) Failure
37
Cont’d
• A variable can never be replaced by a term containing that variable. For
example, x/f(x) is illegal.
• Unification and inference rules allows us to make inferences on a set of
logical assertions. To do this, the logical database must be expressed in an
appropriate form
• A substitution α unfies atomic sentences p and q if pα = qα
p q α
Knows(John,x) Knows(John,Jane) {x/Jane}
Knows(John,x) Knows(y, Abe) {y/John, x/Abe}
Knows(John,x) Knows(y,Mother(y)) {y/John, x/Mother(John)}
Knows(John,x) Knows(x,Abe) Fail
39
Sound Inference Rules
• Universal Elimination: If x P(x) is true, then P(c) is true, where c is
a constant in the domain of x.
Example: x eats(x, IceCream).
Using the substitution (x/Ben) we can infer eats(Ben, Icecream).
– The variable symbol can be replaced by any constant symbol or function symbol.
• Existential Introduction: If P(c) is true, then x P(x) is inferred.
Example: eats(John, IceCream) we can infer x eats(x, icecream).
– All instances of the given constant symbol are replaced by the new variable
symbol.
• Existential Elimination: From x P(x) infer P(c).
Example: x eats(Sol, x) infer eats(Sol, Cheese)
– Note that the variable x is replaced by a brand new constant (like Cheese) that
does not occur in this or any other sentence in the KB
– If x is within the scope of y it is replaced by new function f(y)
40
Cont’d
Example 1: What can we conclude from the following?
x tall(x) strong(x)
tall(john)
x strong(x) loves(mary, x)
41
Proofs
• Sound inference: find α such that KB |= α
• Proof process is a search, operators are inference rules
– It requires the operation of a series of inference rule to come up
with some conclusion
Example:
Bob is a buffalo. Pat is a pig. Buffaloes outrun pigs
Conclude: Bob outruns Pat
1. Buffalo(Bob)
2. Pig(Pat)
3. x,y Buffalo(x) ^ Pig(y) → outrun(x,y)
4. Buffalo(Bob) ^ Pig(Pat) And Introduction (1, 2)
5. Buffalo(Bob) ^ Pig(Pat) → outrun (Bob, Pat)
Universal Elimination (3, {x/Bob,y/Pat})
6. outrun(Bob,Pat) Modus Ponens (6, 7)
42
Generalized Modus Ponens (GMP)
• Combines And-Introduction, Universal-Elimination, and Modus
Ponens
• Given atomic sentences P1, P2, ..., PN, and implication sentence (Q1 ^ Q2
^ ... ^ QN) R, where Q1, ..., QN and R are atomic sentences, derive new
sentence R. That is,
• from P(c), Q(c), and x (P(x) ^ Q(x) R(x)), derive R(c)
Example: Given Faster(Bob,Pat), Faster(Pat,Steve) and
Faster(x,y) ^ Faster(y,z) Faster(x,z);
by substituting {x/Bob, y/Pat, z/Steve}
infer in one step the new sentence: Faster(Bob, Steve)
• GMP is not complete for FOL. Natural deduction using GMP is
possible only for KBs containing Horn clauses.
• A Horn clause is a sentence of the form:
x (P1(x) ^ P2(x) ^ ... ^ Pn(x)) Q(x)
where there are zero or more Pi‘s
43
Inference Mechanisms
• Inference is a means of interpretation of knowledge in
the KB to reason and give advise to users query.
• There are two inference strategies to control and
organize the steps taken to solve problems:
– Forward chaining: also called data-driven chaining
• It starts with facts and rules in the KB and try to draw
conclusions from the data
– Backward chaining: also called goal-driven chaining
• It starts with possible solutions/goals and tries to gather
information that verifies the solution
44
Conclude by Chaining
•Forward chaining
–Proofs start with the given axioms/premises in KB, deriving new
sentences using GMP until the goal/query sentence is derived.
–This defines a forward chaining inference procedure because it
moves "forward" from the KB to the goal.
•Example: All cats like fish, cats eat everything they like, and
Ziggy is a cat. Goal query: Does Ziggy eat fish?
1. x cat(x) likes(x, Fish)
2. x,y (cat(x) ^ likes(x,y)) eats(x,y)
3. cat(Ziggy)
–Proof: 4. likes(Ziggy, Fish) Using GMP with (1) and (3) &
subst{x/Ziggy}
5. eats(Ziggy, Fish) Using GMP with (3), (4) and (2)
So, Yes, Ziggy eats fish.
45
Cont’d
•Backward chaining:
–Proofs start with the goal query, find implications that would allow
you to prove it, and then prove each of the antecedents in the
implication, continuing to work "backwards" until we get to the
axioms, which we know are true.
–To prove eats(Ziggy, Fish), first see if this is known from one of the
axioms directly. Otherwise, see if there is a Horn clause that has the
consequent (i.e., right-hand side (RHS)) of the implication matching
the goal. Here,
• Goal matches RHS of (2), so prove new sub-goals
cat(Ziggy) and likes(Ziggy, Fish) that correspond to the LHS of (2)
• cat(Ziggy) matches axiom (3), so we've "solved" that sub-goal
• likes(Ziggy, Fish) matches the RHS of (1), so prove cat(Ziggy)
• cat(Ziggy) matches (3), so we've solved this sub-goal
• There are no unsolved sub-goals,
So we conclude. Yes, Ziggy eats fish 46
Generalized Resolution
• Resolution procedure is a sound and complete inference procedure for
FOL
–It uses a single resolution rule of inference: which is generalization of the
same rule used in PL.
• Resolution Rule for PL: From sentence P1 v P2 v ... v Pn and sentence
P1 v Q2 v ... v Qm derive resolvent sentence:
P2 v ... v Pn v Q2 v ... v Qm
• Resolution Rule for FOL:
• Given sentence P1 v ... v Pn and sentence Q1 v ... v Qm where each Pi
and Qi is a predicate sentences, if Pj and Qk unify with substitution
list θ, then derive the sentence:
P1 v ... v Pj-1 v Pj+1 v ... v Pn v Q1 v ... Qk-1 v Qk+1 v ... V Qm
Examples:
–Given: Rich(ken); Rich(x) v unhappy(x)
using subst {x/ken}
we can conclude that: unhappy(ken) 47
Generalized Resolution: proof by refutation
• Generalized Resolution inference rule provides a
complete system for proof by refutation.
– Resolution is a generalization of modus ponens
– It requires a normal form, but any sentence can be put into CNF
• Conjunctive normal form (CNF)
– Each individual sentence is a disjunction of literals. This form is
CNF
– CNF is more common. For instance,
P(x) v R(x)
Q(y) v S(y)
• Conversion to CNF:
– any FOL sentence can be put into normal form
48
Steps to convert a FOL sentence to CNF
• Eliminate connectives: replace (P Q) by ((P Q) ^ (Q P))
51
Resolution: Proof by Refutation
Example
• Jack owns a dog. Every dog owner is an animal lover. No
animal lover kills an animal. Either Jack or Curiosity killed
the cat, who is named Tuna. Did Curiosity kill the cat?
• FOL representation:
A. (x) Dog(x) Owns(Jack,x)
B. (x) ((y) Dog(y) Owns(x, y)) AnimalLover(x)
C. (x) AnimalLover(x) ((y) Animal(y) Kills(x,y))
D. Kills(Jack,Tuna) Kills(Curiosity,Tuna)
E. Cat(Tuna)
F. (x) Cat(x) Animal(x)
G. Kills(Curiosity, Tuna)
52
Properties of Good KB
• A KB should be clear, correct, expressive, concise, context-insensitive
and effective.
– The relations that matter should be defined, and the irrelevant details should
be suppressed
• Separate the KB from inference procedure.
– This allows the KE (creator of the KB) to focus on the content of the KB,
and not about how it will be used by the inference procedure
• Define a generally applicable KB.
– Every KB has two potential consumers: human readers and inference
procedure
– A common mistake is to choose predicate names that are meaningful to the
human readers, and then assume that the name is somehow meaningful to
the inference procedure as well
• E.g. consider the sentence: BearOfVerySmallBrain(Lilly). Do you think
the Inference engine be able to infer from this sentence facts such as:
Lilly is a bear or Lilly has a very small brain; that it has a brain at all
– Such very long names do not scale up well
– In a properly designed KB, facts that were entered for one situation should
be used in new situations as well
53
Most general KB design
•In a good KB, BearOfVerySmallBrain(Lilly) would be
replaced by the following
– Lilly is a bear; bears are animals; animals are physical things
• Bear(Lilly)
x bear(x) animal(x)
y animal(y) physicalThing(y)
– All animals have a brain, which is a part of the animal
z animal(z) brain(brainOf(z))
x partOf(brainOf(x),x)
– Lilly has a very small brain
• relativeSize(BrainOf(Lilly), BrainOf(typicalBear)) = very(small)
– If something is part of a physical thing, then it is also a physical
thing
x,y part-of(x,y) ^ physicalThing(y) physicalThing(x)
54
Thank you!!!
55