Sie sind auf Seite 1von 38

@ 

  

| 
|    

@ 
  
î Knowledge base agents can form representations about the world

î Use inference to derive new representations about the world

î Use new representations to deduce what to do


î The central component of knowledge based agents is a knowledge
base KB
î A KB is a set of sentences
î Each sentence is expressed in the knowledge representation
language and represents some assertion about the world
î There must be away to add new sentences to the knowledge base
(TELL) and a way to query the knowledge base (ASK)

| 
|    

@ 
  
î Knowledge bases consists of sentences
î These sentences are expressed according to the syntax of the
representation language
î The syntax specifies all the sentences that are well formed
î A logic must also define the semantics of the language
î Semantics has to do with the meaning of the sentences
î In logic the semantics define the truth of each sentence with
respect to each possible world
î In logic, every sentence is either true or false

| 
|    

^   
î This involves the idea of logical entailment between sentences
î The idea that a sentence logically follows from another
sentence
î We use the symbol |= to indicate entailment
î We have E |=F, means that E logically entails F
î E |=F iff in every model in which E is true, F is also true
î rodel here refers to a possible world.
î For instance in the 8-puzzle, any of the possible states of the
board is a model of the board
î Logical inference ʹ the formal process of deriving conclusion
given a model
| 
|    

^   
î An inference algorithm that derives only entailed conclusion is said
to be !  or  ! 

î any unsound inference algorithm makes up things as it goes along
î An inference algorithm is complete if it can derive any sentence that
is logically entailed.
*   
î The connection between logical reasoning processes and the real
environment in which the agent exists
î How do we know that the KB is true in the real world?
Assume the sensors (which create the connection) are accurate
Other general rules in the KB derived from conclusions based on
experience e.g. humans are mortal
These conclusions could be wrong but usually generally
accepted

| 
|    

@ 
   
î Syntax ʹ defines the allowable sentences
î The atomic sentences (Propositional Symbols) consists of
indivisible strings of characters beginning with an uppercase
letter e.g. @, , , 
î Each atomic sentence stands for a proposition that can either
be true or false
î The other two atomic sentences are ½  and 

î Yomplex sentences are constructed from simpler sentences
using logical connectives

| 
|    

@ 
   
î We have five connectives
i   
î A sentence such as W is a negation of W
î A literal is either an atomic sentence ( a positive literal) or a
negated atomic sentence (a negative literal)
V  
î A sentence of the form W1W2 also called a conjunction.
î W1 and W2 are the conjuncts
3) V  
î A sentence of the form W1VW2 is called a disjunction
î W1 and W2 are the disjuncts

| 
|    

@ 
   
Ñ
  !
î A sentence of the form W1
W2 is called an implication
î W1 is called the premise or antecedent, W2 is called the
consequent or conclusion
î Implications are also known as rules or if-then statements
ü R    
î A sentence of the form W1RW2 is called a biconditional
î èead as w1 iff w2

| 
|    

@ 
   
î The following is the definition of a well formed formulas
1) an atom is a wff, e.g. P, P3 ͙
2) if w1and w2 are well formed formulas then so are
3) w1 w2
4) w1V w2
5) w1
w2
6) w1Rw2
7) w1
There are no other wffs
î Sentences constructed with binary connectives should be enclosed
in parentheses.
î This ensures that the syntax is completely unambiguous
î The order of precedence in propositional logic is , , V,
, R

| 
|    

@ 
    
î The semantics define the rules for determining the truth of a
sentence in respect to a particular model
î In propositional logic, a model simply fixes the truth of every
propositional symbol (atomic sentence)
î For instance with three propositions, there are 23 possible models
î The rules for determining the truth of a sentence formed using any
of the connectives can be summarized in a truth table as shown
below
î ½ specifies the truth value of a complex sentence for each
possible assignment of truth values to its components

| 
|    

@ 
    
@  
  
 
 


  


 
 


[  
   

@ V 
  
 
 

  

 
 


[  
V   
| 
|    

@ 
    
@ 

  
 
 


  

 
 
[  

  

@ R 

  

 
 



  



 
 

[  
R   

| 
|    

@ 
      
î If there five sentences in the knowledge base say è1 to è5, it can
also be considered as a single sentence, the conjunction of è1 to
è5 i.e. è1è2 è3è4è5 because it asserts all the individual
sentences are true
î The aim of inference is to decide if KB |= E
î One way to determine entailment is to enumerate all models
(assignments of values to the atoms) which KB is true, and check
if E is true for every model in which KB is true.
î With n atoms, there are 2n possible models to consider
î Thus such an algorithm would have exponential complexity

| 
|    

@ 
      
Enumeration of Models (First Algorithm)
î Enumerate all models and check that E is true in all models in
which KB is true
î Example algorithm ½½ 
(èussell and Norvig, 2003, pg.
209)
Algorithm is sound because it implements directly the
definition if entailment. Y   
    
      E  
The algorithm is complete because it works for any KB and
E and always terminates
rust test 2n models when n is the number of symbols

| 
|    

@ 
      
 
 
î Two sentences E and F are logically equivalent if they are true in
the same set of models
î This is written as ERF
î An alternative definition is
î Two sentences E and F
î E|F
î E|=F and F|=E

| 
|    

@ 
      
î Some common equivalents
i EF | FE   
 
EVF | FVE   
 V
 EF | EF     
 
 EVFV | EV FV     
 V
 E|E   
 E
F | F
E  
 E
F | E V F   
! ERF| E
FF
E " 
# EF|E V F  $ %& '(
i) EVF|E  F  $ %& '(
ii EFV | EVFFV   $ 
    V
i EVF | EVF FV   $ 
 V   

| 
|    

@ 
      
>  
î A sentence is valid if it is true in all the models
î e.g. PVP
î >alid sentences are also known as tautologies
p !   
î A sentence is satisfiable if it is true in some model
î If a sentence E is true in a model , we say that m satisfies E or
that  is a model of E.
î E is valid iff E is unsatisfiable
î E is satisfiable iff E is not valid
î E|=F iff the sentence (EF) is unsatisfiable
î Proving E from F by checking the unsatisfiability of (EF) is called
proof by refutation or contradiction.
î One assumes that sentence F is false and shows that this leads to
contradiction with known axioms E
| 
|    

@ 
      
|    !
methods used to derives new sentences (conclusions) from existing sentences.
Modus Ponens
E
F, E
F
›       !
EF
E
î The equivalences given earlier can also be used as inference rules
ERF
(E
F)(F
E)
E
F
šEVF
î Some equivalences can also be used backward like the ones above
šEV

 
š
š

| 
|    

@ 
      
î The process of derivation of a new sentence by application of
inference rules is called a  .
î For example given the axioms
è 

 V è 

½  (  
      ruddy  (
Vè 

è 
 E
F | E V F  
è 
     E
FE  F 

     

| 
|    

@ 
      
î Example 2
Given the knowledgebase
(AR(BVY))
A
´  š

Using Biconditional elimination


(A
(BVY)) (BVY)
A)
Using and elimination
(BVY)
A
Using logical equivalence for contrapositives
A
(BVY)
Using rodus Ponens
(BVY)
Using de rorgan͛s rules
BY
Using and elimination
B

| 
|    

@ 
      
î Finding proofs is exactly like finding solutions to search problems
î If the successor function is defined to generate all possible
applications of inference rules, then search algorithms can be used
to find proofs
î Thus searching is an alternative to enumerating models.
î The goal is the sentence to be derived
î The alternative paths are the alternative inference rules to be used
to generate new sentences
î Finding a proof can be made efficient by ignoring irrelevant
propositions e.g. by considering only the sentences that contain the
goal proposition
î These inference algorithms are complete iff the rules are
adequate to produce all the necessary intermediate conclusions
to reach the desired goal

| 
|    

 
î èesolution
î Is an inference rule
î Yields a complete inference algorithm when coupled with any
complete search algorithm
î èesolution applies to a special format of wffs called clauses
î A clause is a disjunction of literals
î e.g. AVB VY
î èesolution works as follows

| 
|    

 
î Assume P means it is raining in rombasa
î Q means it is raining in Nairobi
î Assume è means that it is raining in Nakuru
î If we have the clause PVQVè , and Q then we can infer PVè
î This means that if it is raining in either Nairobi or rombasa or
Nakuru, and we know that it is not raining in Nairobi, then it
must be raining in either rombasa or Nakuru
î I.e. given
@V Vè    
@Vè
î This is known as unit resolution inference rule

| 
|    

 
î If we have complementary literals in the two clauses in the previous
case Q and Q
î This rule takes a disjunction of literals (a clause) and a clause which
contains a complimentary literal in the clause and produces another
clause, where the complimentary literal has been eliminated
î We have the general inference rule which works when we have two
clauses as shown below
@V Vè V V
@VèVV
î This takes two clauses that contain complimentary literals and
produces another clause that contains all literals except the
complimentary literals

| 
|    

 
î The resulting literal should contain only one copy of each of the
literals. This is called factoring. For instance
@V Vè V Vè
@VèVVè     
@VèV
î The resulting Ylause is called the resolvent
î èesolution is sound, we can see this by considering
EVF  F V
F  *   F     
F     F    E  
+ (       F*   EV       
E     
| 
|    

 
î èesolution used by itself is not complete
î For instance given
Pè|=(PVè)
î But we cannot infer PVè using resolution on the clause P  è
because there is nothing that can be resolved.
î Therefore we cannot use resolution directly to decide all logical
entailments.
î However, we can show by resolution that the negation of PVè is
inconsistent with the set {P, è hence use proof by contradiction to
show Pè|=(PVè)
î The process is illustrated below
We have the clauses P and è written {P, è
we negate PVè to get ( PVè), which is equivalent to (Pè)
two clause {P,è

| 
|    

 
î we can then resolve combine these clauses into one set {P, è,
P,è
î We resolve the clauses with complementary literals resulting
in an empty clause
resolve P and P to get 
which is equivalent to false
î This makes the whole set false since it consists of
conjunctions) therefore one false clause, makes the whole set
false which is a contradiction hence we have indirectly
established Pè|=(PVè)

| 
|    

 
Y 
   
î èesolution applies only to disjunctions of literals
î So it would seem relevant only to knowledge bases and queries
consisting only of such disjunctions.
î However, every sentence in propositional logic can be converted
to a conjunction of clauses (disjunctions of literals)
î Such a sentence is said to be in conjunctive normal form (YNF)
e.g.
(AVB) (YV AVB).
î This would be equivalent to a knowledge base containing the
clauses
(AVB),
(YV AVB).
| 
|    

 
î The negation of the query can also be converted to YNF form
î The clauses in the Query in YNF can the be resolved with the
clauses in the KB,
if we get an empty clause in the process, then we have
succeeded in proving the query is entailed by the DB by
refutation.

| 
|    

 
  Y 
    
   

@
V
è
@
î Eliminate the implication symbol by using the V equivalent

@V V
èV@
î Eliminate the scope of  using De rorgan͛s law and double-
negation elimination
G@š  VGšV@
î Yonvert to YNF by using the associative and distributive rules
G@VšV@  Gš šVV@
G@šV  Gš V šV@
î A conjunction of clauses in YNF form is usually expressed as a set of
clauses, with the conjunction of clauses implied
š
@Vè
 VèV@ 

| 
|    

 
î In general, a resolution refutation for proving an arbitrary wff, ,
from a set of wffs, G proceeds as follows
1. convert the wffs in G to clause form, A conjunction of clauses
2. convert the negation of  to clause form
3. combine the clauses resulting from step 1 add 2 into a single set
½
4. iteratively apply resolution to the clauses in ½ and the results
into ½ until there are no more resolvents that can be added or
until the empty clause is generated
5. if the procedure completes with an empty clause then G|= 
6. else G does not entail 

| 
|    

 
›   
î Given the following KB, Prove è using resolution
P
(PQ)
è
(SVT)
Q
T
î Yonvert the wffs into clause form
1) P P
2) (PQ)
è PV QVè
3) (SVT)
Q (SVQ)
(TVQ)
4) T T

| 
|    

 

[     


         

 
| 
|    

[      

î The completeness of resolution makes it a very important inference
method
î In many practical situations, the full power of resolution is not
needed
î èeal-World Knowledge bases often contain clauses of a restricted
form called A Y! !
î A horn clause is a disjunction of literals with at most one positive
literal
e.g. AVBVPVQ
î Every horn clause can be written as an implication whose premise is
a conjunction of positive literals and whose conclusion is a single
positive literal
î For example the horn clause AVBVPVQ can be written as
ABP
Q

| 
|    

[      

î Such a horn clause is usually called a definite clause
î The positive literal is called the head of the clause while the
negative literals are called the body of the clause.
î Such a clause is also called a rule
î A definite clause with no negative literals simply asserts a given
proposition and is sometimes called a fact
î A horn clause with no positive literals can be written as an
implication whose conclusion is the literal 
 For example
î PVQ can be written as PQ
false
î Such sentences are called integrity constraints on the data and
they are used to signal errors in the data.

| 
|    

[      

î Inference with horn clause can be done via backward chaining
and forward chaining
î Forward chaining works by trying to infer the goal either from
the facts or using the rules
î Backward chaining works by trying to prove the literals in the
body of a rule that contains the goal

| 
|    

Forward Yhaining Algorithm
@ 
      

a   
   !       

            ! 

u uau Ô 
 ! " !      !
 

   ! " ! ! #       




   !     !  $   !


   

| 
|    

Forward Yhaining Algorithm
3 au    

O@@

 u 



O
      Ô  
  
   Ô 
Ô ! 
a Ô 
Ô -
aA
Ô 
  
@%
%&'Ô( 
 

[  

 
   
   

!    " 
# $

| 
|    


Das könnte Ihnen auch gefallen