tp2623 : knowledge representation & reasoning
DESCRIPTION
TP2623 : Knowledge Representation & Reasoning. Topic 2 : Propositional Logic. By : Shereena Arif Room : T2/8, Blok H Email : [email protected] / [email protected]. Learning Outcomes. At the end of this topic, students will: - PowerPoint PPT PresentationTRANSCRIPT
TOPIC 2 : PROPOSITIONAL LOGIC
TP2623 : Knowledge Representation &
Reasoning
By : Shereena ArifRoom : T2/8, Blok HEmail : [email protected] / [email protected]
Learning Outcomes
TP2623, [email protected]
2
At the end of this topic, students will:Understand the concept of knowledge-bases
and propositional logicAble to construct knowledge base according
to propositional logic representation.
06/05/2011
Introduction
06/05/2011TP2623, [email protected]
3
What is ‘Knowledge Representation & Reasoning’ ? Also known as KRR. Is a sub-area in AI- Artifical Intelligence.
Fundamental goal to represent knowledge in a manner that facilitates inferencing (i.e. drawing conclusions) from knowledge.
It analyzes how to formally think – how to use a symbol system to represent a domain of discourse
(that which can be talked about), along with functions that allow inference (formalized reasoning) about the objects
06/05/2011TP2623, [email protected]
4
These concepts are central to the entire field of AI: The representation of knowledge The reasoning processes that bring knowledge to life
The importance of KR&R : To artificial agents successful behavior that would be very
hard to achieve otherwise. E.g : permainan catur.
In partially observable situation E.g : doktor dan pesakit
Understanding natural language E.g : Hamzah tertarik dengan sebentuk cincin di dalam kotak
pameran dan berhasrat membelinya. Flexibility to changes in the environment by updating the
relevant knowledge.
Knowledge-Based Agents
06/05/2011TP2623, [email protected]
5
The central component of a knowledge-based agent is its knowledge base, KB.
Informally, a KB is a set of sentences related, but not identical to natural languages.
Each sentence is expressed in a language called knowledge representation language.
How to : Add new sentences into KB TELL Query about something already known ASK
06/05/2011TP2623, [email protected]
6
Both tasks may involved inference deriving new sentences from old ones.
In logical agents, inference must obey the requirement : When one ASKs a question of the KB, The answer should follow from what has been told (or
TELLed) to the KB previously.
06/05/2011TP2623, [email protected]
7
function KB-AGENT (percept) returns an action static : 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
Agent takes percept as input and returns an action.
Agent maintains a knowledge base, KB, which may initially contain some background knowledge.
06/05/2011TP2623, [email protected]
8
Each time the agent program is called it does two things. It TELLs the knowledge base what it perceives. It ASKs the knowledge base what action it should
perform.
In the process of answering, extensive reasoning may be done about the current state, about outcomes of possible actions, and so on.
Once the action is chosen, the agent records its choice with TELL and executes the action.
The wumpus world
06/05/2011TP2623, [email protected]
9
The wumpus world is a cave consisting of rooms connected by passageways.
Lurking somewhere in the cave is the wumpus, a beast that eats anyone who enters its room
The wumpus can be shot by an agent, but the agent has only one arrow.
Some rooms contain bottomless pits that will trap anyone who wanders into these room (except the wumpus, who are too big).
Why ??.. The possibility of finding a heap of gold.Wumpus world an excellent testbed
environment for intelligent agents.
Wumpus World PEAS description
TP2623, [email protected]
10
Performance measure gold +1000, death -1000 -1 per step, -10 for using the arrow
Environment Squares adjacent to wumpus are smelly Squares adjacent to pit are breezy Glitter if gold is in the same square Shoot kills wumpus if you are facing it Shooting uses up the only arrow Grab picks up gold if in same square Release drops the gold in same square
Sensors: The percept [Stench, Breeze, Glitter, Bump, Scream]
Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
06/05/2011
Exploring a wumpus world
06/05/2011TP2623, [email protected]
11
[None, None, None, None, None] [None, Breeze, None, None, None]
06/05/2011TP2623, [email protected]
12
[Stench, None, None, None, None] [Stench, Breeze, Glitter, None, None]
06/05/2011TP2623, [email protected]
13
From the fact that there was no stench or breeze in [1,1], the agent can infer that [1,2] and [2,1] are free of dangers.
From the fact that it is still alive, it can infer than [1,1] is also OK.
A cautious agent will only move into a square that it knows is OK.
Let us suppose the agent moves to [2,1], giving us (b) in page 11.
The agent detects a breeze in [2,1], so there must be a pit in a neighbouring square, either [2,2] or [3,1]. (The notation P? indicates a possible pit.)
The pit cannot be in [1,1] because the agent has already been there and did not fall in.
At this point, there is only one known square that is OK and has not yet been visited.
So the prudent agent turns back and goes to [1,1] and then [1,2], giving us (a) in page 12 below.
06/05/2011TP2623, [email protected]
14
The stench in [1,2] means that there must be a wumpus nearby.
But the wumpus cannot be in [1,1] and it cannot be in [2,2] (or the agent would have detected a stench when it was in [2,1].
Therefore, the agent can infer that the wumpus is in [1,3].
The notation W! indicates this.Moreover, the lack of a Breeze in [1,2] implies that there
is no pit in the [2,2]. Yet, we already inferred that there must be a pit in either
[2,2] or [3,1], so this means it must be in [3,1].This is fairly a difficult inference because it combines
knowledge gained at different times in different places.When the agent moved to [2,3], it detects a glitter, which
means that the gold must be there.
06/05/2011TP2623, [email protected]
15
In each case where the agent draws a conclusion from the available information, that conclusion is guaranteed to be correct if the available information is correct fundamental property of reasoning.
In the rest of discussion, we will learn how to build logical agents that can represent the necessary information and draw the conclusions that were described.
Logic in general
TP2623, [email protected]
16
Logics are formal languages for representing information so that conclusions can be drawn
Syntax defines the sentences in the languageSemantics define the "meaning" of sentences;
i.e., define truth of a sentence to each possible world
E.g x+y =4 is true if x=y=2, but false in x=y=1E.g., the language of arithmetic
x+2 ≥ y is a sentence; x2+ y > {} is not a sentence x+2 ≥ y is true if the number x+2 is no 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
06/05/2011
Entailment
TP2623, [email protected]
17
Entailment means that one thing follows from another:
KB ╞ αKnowledge base KB entails sentence α if and
only if in all worlds where KB is true, α is also true
Another way to say this is if KB is true, then α must also be true
E.g., the KB containing “the Rumah Kuning won” and “the Rumah Merah won” entails “Either the Rumah Kuning won or the Rumah Merah won”
E.g., x+y = 4 entails 4 = x+y Entailment is a relationship between sentences (i.e.,
syntax) that is based on semantics
06/05/2011
Entailment in the wumpus world
TP2623, [email protected]
18
Situation after detecting nothing in [1,1], moving right, breeze in [2,1]
Consider possible models for KB assuming only pits
3 Boolean choices 8 possible models
06/05/2011
1
2
3
4
1 2 3 4
Wumpus models
TP2623, [email protected]
21
KB = wumpus-world rules + observationsα1 = "[1,2] is safe", KB ╞ α1, proved by model checkingIn every model in which KB is true, α1 is also true
06/05/2011
Wumpus models
TP2623, [email protected]
23
KB = wumpus-world rules + observations In some models in which KB is true, α2 is false α2 = "[2,2] is safe", KB ⊭ α2 The agent cannot conclude that [2,2] is safe.The example shows how definition of entailment can be
used to derive conclusions logical inference
06/05/2011
Inference
TP2623, [email protected]
24
Entailment & inference : KB is a haystack & α is the needle Entailment needle in the haystack Inference how to find the needle
If an inference i can derive α from KB : KB ├i α “α can be derived from KB by procedure i” “i derives α from KB”
Soundness/Truth preserving : An inference algo is sound if it derives only entailed sentences i is sound if whenever KB ├i α, it is also true that KB╞ α an unsound inference procedure makes things up as it goes along
announces the discovery nonexistent needles. Model checking (if exist) is a sound procedure
Completeness An inference algo is complete if it can derive any sentence that is
entailed i is complete if whenever KB╞ α, it is also true that KB ├i α
06/05/2011
Recap : Described a reasoning process whose conclusions are
guaranteed to be true in any world in which the premises are true.
“if KB is true in the real world, then any sentence α is also true in the real world”
Sentences physical configurations of the agent Reasoning a process of constructing new physical
configurations from the old ones. Logical reasoning ensures that the new ones actually follow
the old ones.Preview: we will define a logic (first-order logic) which
is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure.
That is, the procedure will answer any question whose answer follows from what is known by the KB.
06/05/2011TP2623, [email protected]
25
Propositional Logic or Calculus
TP2623, [email protected]
26
Propositional logic A very simple logic Also called as Boolean logic. Syntax & Semantics The way in which the truth of
sentences is determined.
Syntax Defines allowable sentences.
Two types of sentences : Atomic sentences Complex sentences
06/05/2011
Atomic sentences (indivisible) consist of proposition symbol. Each symbol stands for a proposition that can be true
or false P, Q, R etc. Ex : W1,3 Wumpus is in [1,3] Two proposition symbols with fixed meaning : True &
False.
Complex sentences Constructed from simpler sentences. The sentences connected by logical connectives.
, , , ,
06/05/2011TP2623, [email protected]
27
Logical Connectives
TP2623, [email protected]
28
Not (negation) Ex : W1,3 negation of W1,3
And (conjunction) A B A and B
Or (disjunction) A B A or B
06/05/2011
Logical Connectives
TP2623, [email protected]
29
Implies also known as rules or if-then statements. Conditional of A and B Implication of B given A Sometimes written as → or ⊃ Ex : (W1,3 P3,1 ) W2,2
Premise/Antecedent : (W1,3 P3,1 ) Conclusion/Consequent : W2,2
Ex : A B If A, then B A implies B B when A A only if B A is antecedent, B is consequent
06/05/2011
Logical Connectives
If and only if (biconditional or equivalence)A B is the same as (A B) (A B) if A, then B, and if B, then A
Recap
06/05/2011TP2623, [email protected]
30
Sentence AtomicSentence | ComplexSentence AtomicSentence True | False | SymbolSymbol P | Q | RComplexSentence Sentence
| (Sentence Sentence) | (Sentence V Sentence) | (Sentence Sentence) | (Sentence Sentence)
Propositional Logic Syntax ORValid Sentences
TP2623, [email protected]
31
Logical constants by themselves T or F
Propositional symbol by itself P or Q
Parents around a sentence (P)
Sentences can be combined with logical connectives (P Q)
Order of precedence (highest to lowest) So P Q R S is the same as ((P) (Q R)) S
06/05/2011
Propositional logic: Syntax
TP2623, [email protected]
32
Propositional logic is the simplest logic – illustrates basic ideas
The proposition symbols P1, P2 etc are sentences
If S is a sentence, S is a sentence (negation)
If S1 and S2 are sentences, S1 S2 is a sentence (conjunction)
If S1 and S2 are sentences, S1 S2 is a sentence (disjunction)
If S1 and S2 are sentences, S1 S2 is a sentence (implication)
If S1 and S2 are sentences, S1 S2 is a sentence (biconditional)
06/05/2011
Propositional logic: Semantics
Semantics rules for determining the truth of a sentence with respect to a particular model
Each model specifies true/false for each proposition symbol Ex : P1,2 P2,2 P3,1
false true false m1 = {P1,2 = false, P2,2 = true, P3,1 = false}
06/05/2011TP2623, [email protected]
34
Propositional logic: Semantics
The semantics for propositional logic must specify how to compute the truth value of any sentence, given a model.
Sentences are constructed from atomic sentences and the 5 connectives : Atomic sentences true in every model or false? Complex sentences rules, summarized in a truth
table.
06/05/2011TP2623, [email protected]
35
Propositional logic: Semantics
TP2623, [email protected]
36
Rules for evaluating truth with respect to a model m:S is true iff S is false S1 S2 is true iff S1 is true and S2 is trueS1 S2 is true iff S1is true or S2 is trueS1 S2 is true iff S1 is false or S2 is true i.e., is false iff S1 is true and S2 is falseS1 S2 is true iff S1S2 is true and S2S1 is true
Simple recursive process evaluates an arbitrary sentence, e.g.,P1,2 (P2,2 P3,1) = true (true false) = true true = true
06/05/2011
Truth Table
TP2623, [email protected]
37
P QP Q P P Q P Q P Q
TF F T F F T
FF T T F T T
FT F F F T F
TT T F T T T
06/05/2011
Solving Problems with Truth Tables(Enumeration Method)
TP2623, [email protected]
38
Problem If Ali starts playing with his Playstation, then he will stay
up late. If he stays up late, he will miss his morning class. He was in class.
Did he start playing his playstation?Propositions
P1: Ali plays playstation P2: Ali stays up late P3: Ali attends class
Premises P1 -> P2 P2 -> -P3 P3
Answer
06/05/2011
Truth Tables
TP2623, [email protected]
39
Truth tables are effective, but impractical n propositions requires a table with 2n rows
More efficient methods of proving conclusions from premises exist E.g. Wang’s Algorithm
06/05/2011
Some Exercises Using Truth Table
TP2623, [email protected]
40
(T F) T Answer:
(F F) T Answer:
((F T) F) ((T F)) Answer:
06/05/2011
Things we can say with Propositional Calculus
TP2623, [email protected]
41
The sky is grey = S1It will rain = R1I have three arms = A1If S1 and R1 are T, then The sky is grey It will rain is also TIf S1 is T and A1 is F then The sky is grey I have three arms is T
06/05/2011
Combining expressions in Propositional Calculus
TP2623, [email protected]
42
(A1 B1) C1(A2 ( C1 B4) C3(A4 B2) C2
Is equivalent to
((A1 B1) C1) ((A2 ( C1 B4) C3) ((A4 B2) C2)
06/05/2011
Logical equivalence
TP2623, [email protected]
43
Two sentences are logically equivalent} iff true in same models: α ≡ ß iff α╞ β and β╞ α
06/05/2011
Logical equivalence
TP2623, [email protected]
44
Two sentences are logically equivalent} iff true in same models: α ≡ ß iff α╞ β and β╞ α
06/05/2011
Validity and satisfiability
TP2623, [email protected]
45
A sentence is valid if it is true in all models, also known as tautologye.g., True, A A, A A, (A (A B)) B
Validity is connected to inference via the Deduction Theorem:KB ╞ α if and only if (KB α) is valid
A sentence is satisfiable if it is true in some modele.g., A B, Ce.g, if sentence α is true in a model m m satisfies α, or m is a
model of α
A sentence is unsatisfiable if it is true in no modelse.g., AAα is valid iff α is unsatisfiable
Satisfiability is connected to inference via the following:KB ╞ α if and only if (KB α) is unsatisfiable
06/05/2011
Entailment: Propositional Inference(Enumeration Method)
TP2623, [email protected]
46
Let = AB and KB = (AB)(B C)Is it the case that KB ╞ ?Check all possible models - must be true wherever KB is true
A B C AB B C KBF F FF F TF T FF T TT F FT F TT T FT T T
Answer
06/05/2011
The Method of Deduction
Intro
TP2623, [email protected]
48
Previously we used the truth table to test arguments for validity
Here we develop an alternative approach the method of deduction
We can use rules of inference and rules of replacement
Covers standard patterns of inference that can be applied to derive chains of conclusions that lead to the desired goal inference rules
06/05/2011
Inference & Replacement with Propositional Calculus
TP2623, [email protected]
49
Modus Ponens (Implication elimination)
Assume P Q, Given P ----------------- Then Q
For example:If the statement “If it is raining, then you get
wet” is true, and the statement “It is raining” is true, Then you can infer that “you get wet.”
06/05/2011
Inference & Replacement with Propositional Calculus
TP2623, [email protected]
50
Disjunctive Syllogism (or introduction) Assume P -------------- Then P Q
For example:If the statement “It is raining” is true, Then you can infer that the compound statement “It
is raining” OR <anything> will be true
06/05/2011
Inference & Replacement with Propositional Calculus
TP2623, [email protected]
51
Resolution
Assume P Q, Given P Z ----------------- Then Q Z
For example:If we assume “It is raining, or you go outside”, and the statement “It is not raining, or you stay
inside”, Then you can infer that “you go outside or you
stay inside.”
06/05/2011
Inference & Replacement with Propositional Calculus
TP2623, [email protected]
52
And Elimination From a conjunction, you can infer any of the conjuncts E.g from (Wumpus Ahead ∧ Wumpus Alive), Wumpus
Alive can be inferred.
And introduction From a list of sentences, you can infer their
conjunction
Double negation elimination A double-negative makes a positive
06/05/2011
THANK YOU
… to be continued
TP2623, [email protected] 55
Let = AB and KB = (AB)(B C)
Is it the case that KB ╞ ?
Check all possible models - must be true wherever KB is true
06/05/2011