Chapter 4- Knowledge and Reasoning(I)
Chapter 4- Knowledge and Reasoning(I)
1
Knowledge Base Agent
Knowledge base agent is an agent that perform action using the
knowledge it has and reason about their action using its inference
procedure.
2
There must mechanisms to derive new sentences from old
ones.
This process is known as inferencing or reasoning.
Inference must obey the primary requirement that the new
sentences should follow logically from the previous ones
Logic is the primary vehicle for representing and
reasoning about knowledge
Declarative approach to building an agent (or other system):
Tell it what it needs to know (Knowledge base)
Ask what it knows
Answers should follow from the KB
3
Knowledge-based agent program
4
A generic knowledge-based agent
function KB-AGENT(percept) returns an action
persistent: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
action ← ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t←t+1
return action
5
Knowledge Bases Agent
6
Knowledge Bases Agent
7
Example
Agent should incorporate new percept
For example,
1. Azieb get maried with melaku, they born two kids selam and solomon
2. This can be reflected by incorporating the new percepts
FACTS
1. female(azieb).
2. Age(azieb, 18).
3. Married(azieb, melaku).
4. male(melaku).
5. female(selam).
6. male(solomon).
7. parent(melaku,selam).
8. parent(azieb,selam).
9. parent(melaku,solomon).
10. parent(azieb,solomon).
11. age(melaku,26).
12. age(selam, 5).
13. age(solomon, 1).
RULE
1. married(X,Y):-maried(Y,X).
2. father(X,Y):-male(X),parent(X,Y).
3. mother(X,Y):-female(X),parent(X,Y).
4. wife(X,Y):-parent(X,Z),parent(Y,Z).
5. brother(X,Y):-male(X), parent(Z,X),parent(Z,Y).
6. sister(X,Y):-female(X), parent(Z,X),parent(Z,Y).
8
Example
The agent should deduce hidden portion of the world like azieb and selam
are beautiful.
If one asks questions like
?brother(aster,belay).
Married(melaku, azieb).
The system must respond correctly
Deduce appropriate action to query.
If one asks questions like
who is the sister of whom,
who is the father of belay,
who is the mother of Selam, etc
The system must respond correctly
Agent should update internal representation of the world.
For example, if died(melaku) is given we should modify any fact
that tells us about live history about melaku.
9
Knowledge representation
Knowledge representation refers to the technique how to express
the available facts and rules inside a computer so that agent will
use it to perform well.
Knowledge representation consists of:
Syntax (grammar): possible physical configuration that
constitute a sentence (fact or rule) inside the agent architecture.
For example one possible syntax rule may be every sentence must end
with full stop.
Semantics (concept): determine the facts in the world to which
the sentence refers
Without semantics a sentence is just a sequence of characters or binary
sequences
Semantic defines the meaning of the sentence
10
Knowledge representation
E.g., In the language of arithmetic
x+2 ≥ y is a sentence; x2+y > {} is not a sentence
x+2 ≥ y is true iff the number x+2 is not less than the number y
x+2 ≥ y is true in a world where x = 7, y = 1
x+2 ≥ y is false in a world where x = 0, y = 6
11
Logic
12
Types of Logic
In mathematics there are different kinds of logics.
Some of these according to order of their generality are
Prepositional logic
First order logic
Second order logic and more
First order logic can be used to design, represent or infer for any
environment in the real world.
13
Prepositional (Boolean) logic (PL)
Preposition is statement which is either true or false but not both at any
time.
A statement is a sentence which is either true or false.
PL uses declarative sentences only
PL doesn’t involve quantifiers.
Not all sentences are statement (interrogatives, imperatives and
exclamatory)
Preposition can be conditional or unconditional
Examples
Socrates is mortal (unconditional)
If the winter is severe, students will not succeed. (conditional)
All are the same iff their color is black (conditional)
In prepositional logic, symbols represent the whole preposition.
Examples:
M = Socrates is mortal
W = winter is sever
14S = students will not succeed
Prepositional (Boolean) logic (PL)
(negation),
(conjunction),
(disjunction),
(bi-implication or equivalence),
(implication) and parenthesis
15
Prepositional (Boolean) logic (PL)
Rules
Logical constants and propositional symbols are sentence by them selves
Wrapping parenthesis around a sentence yield a sentence like
(P V Q)
Literal are atomic symbols or negated atomic symbols
Complex sentence can be formed by combining simpler sentences with
logical connectors
PL connector priority
Priority of logical connectives from highest to lowest
parenthesis
Negation
Conjunction
Disjunction
Implication
Bi-implication
16
Types of sentence
Given a sentence α, this sentence according to the world considered can
be
Valid (tautology)
Invalid (contradiction)
Satisfiable (neither valid nor invalid)
Validity (tautology)
A sentence is valid iff it is true under any interpretations in all
possible world
17
Satisfiablility
A sentence is satisfiable iff there is some interpretation in some
world for which it is true.
Every valid sentence is satisfiable
Example: x+2 = 20
Every student of AI are in their class
A sentence which is not satisfiable is unsatisfiable (contradiction or
invalid).
18
Entailment
Entailment means that one thing follows from another:
It can be represented by ╞ symbol (double turnstyle)
KB ╞ α shows α can be entailed from KB
Knowledge base, KB entails sentence α if and only if α is true in all
worlds where KB is true
E.g., the KB containing “the Giants won” and “the Reds won” entails
“Either the Giants won or the Reds won”
E.g., x+y = 4 entails 4 = x+y
E.g., x+y = 4 can’t entails x= 2 and y = 2
Entailment is a relationship between sentences (i.e., syntax) that is
based on semantics
19
Inference Procedure
20
Inference Procedure property
The record of operation of a sound inference procedure is called
a proof
Soundness of an inference can be established through truth table.
For example the inference procedure that entails P from a KB
which consists of PQ & Q is not sound as shown bellow
P Q PQ Remark
2. And Elimination
3. And introduction
4. Or introduction
6. Unit resolution
7.Resolution
We will discuss all this one by one in the next slides after discussing normal
forms
22
Normal Forms of Logical expression
There are different standard forms of expressing PL statement.
Some inference procedure require their knowledge base to be in one
of the normal forms to infer from it.
Hence, we need to convert the logical expression which are the
source of knowledge into the appropriate forms
Some of the normal forms are stated bellow
23
Normal Forms of Logical expression
Clausal normal form:
it is a set of one or more literals connected with the disjunction operator
(disjunction of literals).
It doesn’t allow negation marker except as a prefix to a symbol
Example ~P Q ~R is a clausal form
According to the definition a single symbol or negation of a symbol is in
clausal form
Conjunctive normal forms (CNF):
Simply defined as a sequences of one or more clauses connected by the
conjunction operator
Or it is conjunction of clauses
Or conjunction of disjunction of literals
Example (A B) (C D)
Note: connector is needed if we have two or more elementary unit to
connect to each other to form complex expression
This is the basis for the generalized resolution inference procedure
24
Normal Forms of Logical expression
Disjunctive normal form (DNF):
disjunction of conjunction of literals.
Example (A B) (C D)
25
Inference procedure and normal forms
The inference procedure that we have seen before are all sound
If KB is represented in CNF, the generalized resolution inference
procedure is complete
If KB is represented in Horn form, the generalized modes ponens
algorithm is complete
It can be proved that every sentence of human language can be
represented using logic as CNF. However, it is not possible in Horn form.
Therefore, CNF is a more powerful representation technique for
knowledge
But, Horn form representation of knowledge is easily understandable
and convenient. It also require polynomial time inference procedure
26
Modes Ponens
There are a set of already identified inference rules. These are:
1. Modes Ponens or implication elimination:
2. And Elimination
3. And introduction
4. Or introduction
6. Unit resolution
7. Resolution
27
Modes Ponens or implication elimination:
The notation means that, whenever any sentences of
the form and a are given, then the sentence
can be inferred.
And Elimination
Is a rule of inference that allows us to derive conjuncts from
a conjunction. If a proof contains the conjunction of a 1 through an,
then we can deduce any of the conjuncts.
28
Generalized Resolution for PL
Given any two clauses A and B, if there are any literal P 1 in A which has a
Note: in order to apply resolution for proving a theory, make sure first
all the knowledge is in its clausal form
30
Generalized Resolution for PL
Method Two (refutation)
Insert the negation of the statement as valid sentence
A: P Q R
B: ~P R
C: ~Q
D: ~ R
Find fallacy in the KB that will indicate the added statement is invalid
so that its negation is valid
Entail E: Q R from A and B
Entail F: R from C and E
Entail G: {} from D and F
An empty clause shows false. This proves the contradiction.
31
Generalized Resolution for PL
Method Two (refutation) Graphical representation
Insert the negation of the statement as valid sentence
A: P Q R
B: ~P R
C: ~Q
D: ~ R
32
Example: Resolution
Prove that r follows from:
(p q) (r s) - (1)
p~s - (2)
p q - (3)
Solution:
Clause (1) in Clausal form
~ (p q) (r s)
{~ p ~ q r s} - (1)
Clause (2) in Clausal form
{~ p ~ s} - (2)
Clause (3) in Clausal form
{p} - (3)
{q} - (4)
Assume not r which {~ r} in Clausal form - (5)
33
Example: Resolution
Using inference rules: from unit resolution rule of (1) and (5)
{~p ~ q s} - (6) (resolve r with ~r and get resolvent)
from unit resolution of (3) and (6)
{~ q s} - (7) (resolve p with ~p and get resolvent)
from (4) and (7)
{s} - (8) (resolve q with ~q and get resolvent)
from (2) and (8)
{~ p} - (9) (resolve p with ~p and get resolvent)
from (3) and (9)
{} - (10)
Therefore r follows from the original clauses
34
What rule is used for the conclusion?
36
Logical equivalence (2)
37
Converting to CNF
Converting the following sentence to CNF:
a ~b↔c
≡ (a ~ b) ↔ c
Steps:
1. Remove Bi-implication
[(a ~ b) c] [c (a ~ b)]
2. Remove Implication
[~(a ~ b) c] [~c (a ~ b)]
3. Push Negations Inwards
[~a ~~b c] [~c (a ~ b)]
4. Eliminate Double Negations
[~a b c] [~c (a ~ b)]
5. Push Disjunctions into Conjunctions
[~a b c] [~c a] [~c ~ b]
38
Converting to CNF
39
Model
40
Complexity of prepositional inference
The use of inference rules depends on general principles of logic called mono-tonicity
Monotonicity says that the set of entailed sentences can only increase as
information is added to the knowledgebase
Monotonicity means that inference rules can be applied whenever
suitable premises are found in the knowledge base-the conclusion of the
rule must follow regardless of what else is in the knowledge base
41