Lec 20 Knowledge Based Agents
Lec 20 Knowledge Based Agents
1
Truth Table Approach
2
Truth-table approach
• A two steps procedure:
• 1. Generate table for all possible interpretations
• 2. Check whether the sentence evaluates to true whenever KB evaluates to true
• EXAMPLE:
3
Truth tables
The five logical connectives:
A complex sentence:
4
Models of complex sentences
5
Validity Example
• known facts about the Wumpus World
• there is a wumpus in [1,3] or in [2,2]
• there is no wumpus in [2,2]
• question (hypothesis)
• is there a wumpus in [1,3]
• task
• prove or disprove the validity of the question
• approach
• construct a sentence that combines the above statements in an appropriate manner
• so that it answers the questions
• construct a truth table that shows if the sentence is valid
• incremental approach with truth tables for sub-sentences
6
Validity Example
W13 W22 W13 W22
False False False
False True True
True False True
True True True
Interpretation:
W13 Wumpus in [1,3]
W22 Wumpus in [2,2]
P Q PQ
Facts: False False False
• there is a wumpus in [1,3] or in [2,2] False True True
True False True
True True True
7
Validity Example
W13 W22 W22
False True
True False
True True
True False
Interpretation:
W13 Wumpus in [1,3]
W22 Wumpus in [2,2]
Facts: P Q PQ
• there is a wumpus in [1,3] or in [2,2] False False False
False True False
• there is no wumpus in [2,2] True False False
True True True
8
Validity Example
W13 W22 W22
False True
True False
True True
True False
Question:
• can we conclude that the wumpus is in [1,3]?
9
Validity Example
W13 W22 W22
False True
True False
True True
True False
11
i.e. no pit in [1,2]
12
12
Wumpus World Truth Table
14
Truth Table Approach: Example (3)
A B C KB=(A V B) & α2=(¬A V C)
(¬C V B)
F F F F T
F F T F T
F T F T T
F T T F T
T F F T F
T F T T T
T T F T F
T T T T T
15
Validity and Computers
• the computer has no access to the real world, and can’t check the
truth value of individual sentences (facts)
• humans often can do that, which greatly decreases the complexity of
reasoning
• humans also have experience in considering only important aspects,
neglecting others
• if a conclusion can be drawn from premises, independent of their
truth values, then the sentence is valid
• usually too tedious for humans
• may exclude potentially interesting sentences
• some, but not all interpretations are true
16
Limitations of the truth table approach
• What is the computational complexity of the truth table approach?
• Exponential in the number of the proposition symbols
• Rows in the table has to be filled
• But typically only for a small subset of rows the KB is true
17
Inference rules
18
Inference rules approach
• The idea behind the inference rules approach?
• Check only entries for which KB is True.
• Inference rules:
• Represent sound inference patterns repeated in inferences
• Can be used to generate new (sound) sentences from the existing ones
19
Inference , Soundness, Completeness
• Inference is the process of mechanically deriving sentences entailed by a
knowledge-base. If sentence α is derived from KB using inference
mechanism i then we will write KB ├i α .
• An inference mechanism is called sound if it derives only sentences that are
entailed.
• An inference mechanism is called complete if it derives all the sentences
that are entailed.
• The steps used to derive a sentence α from a set of sentences KB is called a
proof.
• A proof theory is a set of rules for deriving the entailments of a set of
sentences.
20
Truth Table for Connectives
21
21
Inference and Derivation
• inference rules allow the construction of new sentences from existing
sentences
• notation: a sentence can be derived from
|- or
• an inference procedure generates new sentences on the basis of
inference rules
• if all the new sentences are entailed, the inference procedure is called
sound or truth-preserving
22
Inference Rules
• Modus Ponens ,
• from an implication and its
premise one can infer the
conclusion
• AND-Elimination 1 2 ... n
• from a conjunct, one can
infer any of the conjuncts i
• AND-Introduction
• from a list of sentences, one 1, 2, … , n
can infer their conjunction
• OR-Introduction 1 2 ... n
• from a sentence, one can
infer its disjunction with i
anything else
1 2 ... n
23
Inference Rules
• double-negation
elimination
• a double negations infers the
positive sentence
• unit resolution
• if one of the disjuncts in a
,
disjunction is false, then the
other one must be true
• resolution
• cannot be true and false, so ,
one of the other disjuncts
must be true
• can also be restated as
“implication is transitive” ,
24
Two Famous Inference Rules
• Modus Ponens
Given that P implies Q,
and I know that P is true,
then I can infer Q
• And Rule
Given that P AND Q is true, I can infer that
P is true, and I can also infer that Q is true.
25
25
Logical Equivalence
26
26
Question
• Consider a knowledge base that contains the following propositional logic
sentences:
• R1: If it is hot and humid then it is raining
• R2: If it is humid then it is hot
• R3: It is humid.
• Goal:
• Is it raining?
• a) Construct a truth table that shows the truth value of each sentence in KB
and indicate the models in which the KB is true.
• b) Does KB entail R? Use the definition of entailment to justify your answer.
• c) Using propositional logic to prove () from (R1,R2,R3)
27
Proving things
• A proof is a sequence of sentences, where each sentence is either a premise or
a sentence derived from earlier sentences in the proof by one of the rules of
inference.
• The last sentence is the theorem (also called goal or query) that we want to
prove.
• Example for the “weather problem” given above.
1 It is humid
2 If it is humid, it is hot
3 Modus Ponens (1,2) It is hot
4 If its hot and humid, its raining
5 AND Rule (1,2) Its is hot and humid
6 Modus Ponens (4,5) It is raining
28
Examples
• Given:
1. A → B
2. B→ C
3. A
• prove: C
29
Examples
• Prove C
• Given:
1. (A D) B
2. A
3. D
4. B C
30
Practice Example
31
Inference and proofs: Wumpus World
• There is no pit in [1,1]:
• R1 : ¬P1,1 .
• A square is breezy if and only if there is a pit in a neighboring
square. This has to be stated for each square; for now, we
include just the relevant squares:
• R2 : B1,1 ⇔ (P1,2 ∨ P2,1 ) .
• R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1 )
• The preceding sentences are true in all wumpus worlds. Now
we include the breeze percepts for the first two squares visited
in the specific world the agent is in, leading up to the situation
in Figure 7.3(b).
• R4 : ¬B1,1
• R5 : B2,1
32
Inference and proofs: Wumpus World
• Knowledge base contains: R1 through R5.
• i.e.
• Want to prove ¬P1,2
• holds / is valid.
1. First, we apply biconditional elimination to R2 to obtain
• R6 : (B1,1 ⇒ (P1,2 ∨ P2,1 )) ∧ ((P1,2 ∨ P2,1 ) ⇒ B1,1 ) .
2. Then we apply And-Elimination to R6 to obtain
• R7 : ((P1,2 ∨ P2,1 ) ⇒ B1,1 ) .
3. Logical equivalence for contrapositives gives
• R8 :(¬B1,1 ⇒ ¬(P1,2 ∨ P2,1 )) .
33
Inference and proofs
• R8 :(¬B1,1 ⇒ ¬(P1,2 ∨ P2,1 )) .
• Now we can apply Modus Ponens with R8 and the percept R4 (i.e.,
¬B1,1 ), to obtain
• R9 :¬(P1,2 ∨ P2,1 ) .
• Finally, we apply De Morgan’s rule, giving the conclusion
• R10 : ¬P1,2 ∧ ¬P2,1 . (neither [1,2] nor [2,1] contains a pit).
• R11: ¬P1,2
34
Question
• Consider the following 4x4 Wumpus world scenario. Suppose the agent has explored the cells,
and those cells are shown in colored form.
4
2 Breeze
1 Start Smell
0 1 2 3 4
• Write the KB for the information about the Smell and Breeze for the four colored rooms?
• What sentences in the KB would represent the following information about the environment
• No Smell no Wumpus nearby
• Smell Wumpus nearby
• Using Propositional Logic inference rules to find the location of the Wumpus?
35
Question
• You are given the following knowledge base:
36