Rushdi Shams, Dept of CSE, KUET, Bangladesh 1
Knowledge Representation IIKnowledge Representation II
LogicsLogics
Artificial IntelligenceArtificial Intelligence
Version 1.0Version 1.0
There are 10 types of people in this world- who understand binaryThere are 10 types of people in this world- who understand binary
and who do not understand binaryand who do not understand binary
Rushdi Shams, Dept of CSE, KUET, Bangladesh 2
Propositional LogicPropositional Logic
Rushdi Shams, Dept of CSE, KUET, Bangladesh 3
Introduction
Need formal notation to represent knowledge,
allowing automated inference and problem solving.
One popular choice is use of logic.
Propositional logic is the simplest.
Symbols represent facts: P, Q, etc..
These are joined by logical connectives (and, or,
implication) e.g., P Λ Q; Q ⇒ R
Given some statements in the logic we can deduce new
facts (e.g., from above deduce R)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 4
Syntactic Properties of
Propositional Logic
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
(bi-conditional)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 5
Semantic Properties of
Propositional Logic
¬S is true iff S is false
S1 ∧ S2 is true iff S1 is true and S2 is true
S1 ∨ S2 is true iff S1is true or S2 is true
S1 ⇒ S2 is true iff S1 is false or S2 is true
i.e., is false iff S1 is true and S2is false
S1 ⇔ S2is true iff S1⇒S2 is true and
S2⇒S1 is true
Rushdi Shams, Dept of CSE, KUET, Bangladesh 6
Truth Table for Connectives
Rushdi Shams, Dept of CSE, KUET, Bangladesh 7
Model of a Formula
If the value of the formula X holds 1 for the
assignment A, then the assignment A is called model
for formula X.
That means, all assignments for which the formula X
is true are models of it.
Rushdi Shams, Dept of CSE, KUET, Bangladesh 8
Model of a Formula
Rushdi Shams, Dept of CSE, KUET, Bangladesh 9
Model of a Formula:
Can you do it?
Rushdi Shams, Dept of CSE, KUET, Bangladesh 10
Satisfiable Formulas
If there exist at least one model of a formula then the
formula is called satisfiable.
The value of the formula is true for at least one
assignment. It plays no rule how many models the
formula has.
Rushdi Shams, Dept of CSE, KUET, Bangladesh 11
Satisfiable Formulas
Rushdi Shams, Dept of CSE, KUET, Bangladesh 12
Valid Formulas
A formula is called valid (or tautology) if all
assignments are models of this formula.
The value of the formula is true for all assignments. If
a tautology is part of a more complex formula then
you could replace it by the value 1.
Rushdi Shams, Dept of CSE, KUET, Bangladesh 13
Valid Formulas
Rushdi Shams, Dept of CSE, KUET, Bangladesh 14
Unsatisfiable Formulas
A formula is unsatisfiable if none of its
assignment is true in no models
Rushdi Shams, Dept of CSE, KUET, Bangladesh 15
Logical equivalence
Two sentences are logically equivalent iff true in same models: α ≡ ß
iff α╞ β and β α╞
Rushdi Shams, Dept of CSE, KUET, Bangladesh 16
Deduction: Rule of Inference
1. Either cat fur was found at the scene of the crime, or dog fur was
found at the scene of the crime. (Premise)
C v D
Rushdi Shams, Dept of CSE, KUET, Bangladesh 17
Deduction: Rule of Inference
2. If dog fur was found at the scene of the crime, then officer
Thompson had an allergy attack. (Premise)
D A→
Rushdi Shams, Dept of CSE, KUET, Bangladesh 18
Deduction: Rule of Inference
3. If cat fur was found at the scene of the crime, then Macavity is
responsible for the crime. (Premise)
C M→
Rushdi Shams, Dept of CSE, KUET, Bangladesh 19
Deduction: Rule of Inference
4. Officer Thompson did not have an allergy attack. (Premise)
¬ A
Rushdi Shams, Dept of CSE, KUET, Bangladesh 20
Deduction: Rule of Inference
5. Dog fur was not found at the scene of the crime. (Follows from 2
D A→ and 4. ¬ A). When is ¬ A true? When A is false- right?
Now, take a look at the implication truth table. Find what is the
value of D when A is false and D A→ is true
¬ D
Rushdi Shams, Dept of CSE, KUET, Bangladesh 21
Rules for Inference:
Modus Tollens
If given α β→
and we know ¬β
Then ¬α
Rushdi Shams, Dept of CSE, KUET, Bangladesh 22
Deduction: Rule of Inference
6. Cat fur was found at the scene of the crime. (Follows from 1
C v D and 5 ¬ D). When is ¬ D true? When D is false- right?
Now, take a look at the OR truth table. Find what is the value of
C when D is false and C V D is true
C
Rushdi Shams, Dept of CSE, KUET, Bangladesh 23
Rules for Inference:
Disjunctive Syllogism
If given α v β
and we know ¬α
then β
If given α v β
and we know ¬β
then α
Rushdi Shams, Dept of CSE, KUET, Bangladesh 24
Deduction: Rule of Inference
7. Macavity is responsible for the crime. (Conclusion. Follows from
3 C M→ and 6 C). When is C M→ true given that C is true?
Take a look at the Implication truth table.
M
Rushdi Shams, Dept of CSE, KUET, Bangladesh 25
Rules for Inference:
Modus Ponens
If given α β→
and we know α
Then β
Rushdi Shams, Dept of CSE, KUET, Bangladesh 26
Conjunctive Normal Form (CNF)
A formula is in conjunctive normal form (CNF) if it is
a conjunction (AND) of clauses, where a clause is a
disjunction (OR) of literals or a single literal.
It is similar to the canonical product of sums form
used in circuit theory
All of the following formulas are in CNF:
Rushdi Shams, Dept of CSE, KUET, Bangladesh 27
Conjunctive Normal Form (CNF)
The following formulae are not in CNF:
The above three formulas are respectively equivalent
to the following three formulas that are in conjunctive
normal form:
Rushdi Shams, Dept of CSE, KUET, Bangladesh 28
Conjunctive Normal Form (CNF)
Eliminate implication with its equivalence. This will
turn P Q into ¬ P V Q→
Use de Morgan's law to move the ¬ symbol onto
atoms (not sentences), replace:
Perform the following operation:
Rushdi Shams, Dept of CSE, KUET, Bangladesh 29
CNF
(p ^ ~q) V (r V s) ^ (r V t)
(p V r V s ) ^ (p V r V t) ^ (~q V r V s)^(~q V r V t)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 30
Horn Clause
 A Horn clause is a clause with at most one positive
literal.
 Any Horn clause therefore belongs to one of four
categories:
1. A rule: 1 positive literal, at least 1 negative literal. A
rule has the form "~P1 V ~P2 V ... V ~Pk V Q".
2. A fact or unit: 1 positive literal, 0 negative literals.
3. A negated goal : 0 positive literals, at least 1 negative
literal.
4. The null clause: 0 positive and 0 negative literals.
Appears only as the end of a resolution proof.
Rushdi Shams, Dept of CSE, KUET, Bangladesh 31
First Order Logic orFirst Order Logic or
First Order Predicate Logic orFirst Order Predicate Logic or
Predicate LogicPredicate Logic
Rushdi Shams, Dept of CSE, KUET, Bangladesh 32
Introduction
Propositional logic is declarative
Propositional logic allows partial/disjunctive/negated
information
(unlike most data structures and databases)
Meaning in propositional logic is context-independent
(unlike natural language, where meaning depends on context)
Propositional logic has very limited expressive power
(unlike natural language)
E.g., cannot say “if any student sits an exam they either pass or
fail”.
Propositional logic is compositional
(meaning of B ^ P is derived from meaning of B and of P)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 33
Introduction
You see that we can convert the sentences into
propositional logic but it is difficult
Thus, we will use the foundation of propositional
logic and build a more expressive logic
Rushdi Shams, Dept of CSE, KUET, Bangladesh 34
Introduction
Whereas propositional logic assumes the world
contains facts,
first-order logic (like natural language) assumes the
world contains
Objects: people, houses, numbers, colors, baseball
games, wars, …
Relations: red, round, prime, brother of, bigger than,
part of, comes between, …
Functions: father of, best friend, one more than, plus, …
Rushdi Shams, Dept of CSE, KUET, Bangladesh 35
Syntax of FOL: Basic Elements
Constants KingJohn, 2, NUS,...
Predicates Brother, >,...
Functions Sqrt, LeftLegOf,...
Variables x, y, a, b,...
Connectives ¬, ⇒, ∧, ∨, ⇔
Equality =
Quantifiers ∀, ∃
Rushdi Shams, Dept of CSE, KUET, Bangladesh 36
Examples
King John and Richard the Lion heart are
brothers
Brother(KingJohn,RichardTheLionheart)
The length of left leg of Richard is greater than
the length of left leg of King John
> (Length(LeftLegOf(Richard)),
Length(LeftLegOf(KingJohn)))
Rushdi Shams, Dept of CSE, KUET, Bangladesh 37
Atomic Sentences
Rushdi Shams, Dept of CSE, KUET, Bangladesh 38
Atomic Sentences
Rushdi Shams, Dept of CSE, KUET, Bangladesh 39
Complex Sentences
Complex sentences are made from atomic sentences using
connectives:
¬S, S1∧ S2, S1∨ S2, S1⇒ S2, S1⇔S2,
Example
Sibling(KingJohn,Richard) ⇒ Sibling(Richard,KingJohn)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 40
Complex Sentences
Rushdi Shams, Dept of CSE, KUET, Bangladesh 41
FOL illustrated
 Five objects-
1. Richard the Lionheart
2. Evil King John
3. Left leg of Richard
4. Left leg of John
5. The crown
Rushdi Shams, Dept of CSE, KUET, Bangladesh 42
FOL illustrated
 Objects are related with
Relations
 For example, King John and
Richard are related with
Brother relationship
 This relationship can be
denoted by
(Richard,John),(John,Richard)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 43
FOL illustrated
 Again, the crown and King
John are related with
OnHead Relationship-
OnHead (Crown,John)
 Brother and OnHead are
binary relations as they
relate couple of objects.
Rushdi Shams, Dept of CSE, KUET, Bangladesh 44
FOL illustrated
 Properties are relations that
are unary.
 In this case, Person can be
such property acting upon
both Richard and John
Person (Richard)
Person (John)
 Again, king can be acted
only upon John
King (John)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 45
FOL illustrated
 Certain relationships are
best performed when
expressed as functions.
 Means one object is related
with exactly one object.
Richard -> Richard’s left leg
John -> John’s left leg
Rushdi Shams, Dept of CSE, KUET, Bangladesh 46
Universal quantification
∀<variables> <sentence>
Everyone studies at KUET is smart:
∀x Studies (x,KUET) ⇒ Smart (x)
∀x P is true in a model m iff P is true with x being each possible
object in the model
Roughly speaking, equivalent to the conjunction of
instantiations of P
Rushdi Shams, Dept of CSE, KUET, Bangladesh 47
Universal quantification
 Remember, we had five
objects, let us replace them
with a variable x-
1. x ―›Richard the Lionheart
2. x ―› Evil King John
3. x ―› Left leg of Richard
4. x ―› Left leg of John
5. x ―› The crown
Rushdi Shams, Dept of CSE, KUET, Bangladesh 48
Universal quantification
 Now, for the quantified
sentence
∀x King (x) ⇒ Person (x)
Richard is king ⇒ Richard is Person
John is king ⇒ John is person
Richard’s left leg is king ⇒ Richard’s
left leg is person
John’s left leg is king ⇒ John’s left leg
is person
The crown is king ⇒ the crown is
person
Rushdi Shams, Dept of CSE, KUET, Bangladesh 49
Universal quantification
Richard is king ⇒ Richard is
Person
John is king ⇒ John is person
Richard’s left leg is king ⇒
Richard’s left leg is person
John’s left leg is king ⇒ John’s left
leg is person
The crown is king ⇒ the crown is
person
Only the second
sentence is correct,
the rest is incorrect
Rushdi Shams, Dept of CSE, KUET, Bangladesh 50
A common mistake to avoid
Typically, ⇒ is the main connective with ∀
Common mistake: using ∧ as the main connective
with ∀:
∀x Studies (x,KUET) ∧ Smart (x)
means “Everyone Studies at KUET and everyone is smart”
Rushdi Shams, Dept of CSE, KUET, Bangladesh 51
Existential Quantification
∃<variables> <sentence>
Someone studies at KUET is smart:
∃x Studies (x,KUET) ∧ Smart (x)
∃x P is true in a model m iff P is true with x being
some possible object in the model
Roughly speaking, equivalent to the disjunction
of instantiations of P
Rushdi Shams, Dept of CSE, KUET, Bangladesh 52
Another common mistake to
avoid
Typically, ∧ is the main connective with ∃
Common mistake: using ⇒ as the main connective with ∃:
∃x Studies (x,KUET) ⇒ Smart (x)
means some guys, if they study in KUET, then they are smart
Rushdi Shams, Dept of CSE, KUET, Bangladesh 53
Properties of quantifiers
∀x ∀y is the same as ∀y ∀x
∃x ∃y is the same as ∃y ∃x
∃x ∀y is not the same as ∀y ∃x
Rushdi Shams, Dept of CSE, KUET, Bangladesh 54
Properties of quantifiers
∃x ∀y Loves(x,y)
“There is a person who loves everyone in the world”
∀y ∃x Loves(x,y)
“Everyone in the world is loved by at least one person”
Rushdi Shams, Dept of CSE, KUET, Bangladesh 55
Properties of quantifiers
Quantifier duality: each can be expressed using the other
∀x Likes(x,IceCream) is equivalent to
¬∃x ¬Likes(x,IceCream)
∃x Likes(x,Broccoli) is equivalent to
¬∀x ¬Likes(x,Broccoli)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 56
Properties of quantifiers
 Equivalences-
1. ∃x P is equivalent to ¬∀x ¬P
2. ¬∃x ¬P is equivalent to ∀x P
3. ∃x ¬P is equivalent to ¬∀x P
4. ¬∃x P is equivalent to ∀x ¬P
Rushdi Shams, Dept of CSE, KUET, Bangladesh 57
Equality
term1 = term2 is true under a given interpretation if and only if
term1 and term2 refer to the same object
E.g., definition of Sibling in terms of Parent:
∀x,y Sibling(x,y) ⇔ [¬(x = y) ∧ ∃m,f ¬ (m = f) ∧ Parent(m,x) ∧
Parent(f,x) ∧ Parent(m,y) ∧ Parent(f,y)]
Rushdi Shams, Dept of CSE, KUET, Bangladesh 58
Example knowledge base
The law says that it is a crime for an
American to sell weapons to hostile
nations. The country Nono, an enemy of
America, has some missiles, and all of its
missiles were sold to it by Colonel West,
who is American.
Prove that Col. West is a criminal
Rushdi Shams, Dept of CSE, KUET, Bangladesh 59
Example knowledge base
... it is a crime for an American to sell weapons to hostile nations:
American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x)
Nono … has some missiles,
Owns(Nono,x)
Missile(x)
… all of its missiles were sold to it by Colonel West
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missiles are weapons:
Missile(x) ⇒ Weapon(x)
An enemy of America counts as "hostile“:
Enemy(x,America) ⇒ Hostile(x)
West, who is American …
American(West)
The country Nono, an enemy of America …
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 60
Forward Chaining
American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒
Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(x,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 61
Forward Chaining
American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒
Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(x,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 62
Forward Chaining
American(West) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z)
⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(x,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 63
Forward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(z) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(x,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 64
Forward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(z) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(x,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 65
Forward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(z) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 66
Forward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(z) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 67
Forward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 68
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 69
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 70
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 71
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 72
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 73
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,Nono) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 74
Backward Chaining
American(West) ∧ Weapon(y) ∧ Sells(West,y,Nono) ∧
Hostile(Nono) ⇒ Criminal(x)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 75
…& the Inference
American(West) ∧ Weapon(y) ∧ Sells(West,y,Nono) ∧
Hostile(Nono) ⇒ Criminal(West)
Owns(Nono,x)
Missile(x)
Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(Nono,America) ⇒ Hostile(Nono)
American(West)
Enemy(Nono,America)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 76
Probability: Logic forProbability: Logic for
UncertaintyUncertainty
Rushdi Shams, Dept of CSE, KUET, Bangladesh 77
Conditional Probability
Definition of conditional probability:
P(a | b) = P(a ∧ b) / P(b) if P(b) > 0
Product rule gives an alternative formulation:
P(a ∧ b) = P(a | b) P(b) = P(b | a) P(a)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 78
Inference with Probability
Rushdi Shams, Dept of CSE, KUET, Bangladesh 79
Inference in Probability
P(toothache) =
0.108 + 0.012 + 0.016 + 0.064
= 0.2
Rushdi Shams, Dept of CSE, KUET, Bangladesh 80
Inference in Probability
P(cavity V toothache) =
0.108 + 0.012 + 0.072 + .008 +
0.016 + 0.064 = 0.28
Rushdi Shams, Dept of CSE, KUET, Bangladesh 81
Inference in Probability
Can also compute conditional probabilities:
Rushdi Shams, Dept of CSE, KUET, Bangladesh 82
Inference in Probability
Can also compute conditional probabilities:
Rushdi Shams, Dept of CSE, KUET, Bangladesh 83
Baye’s Rule
Product rule gives an alternative formulation:
P(a ∧ b) = P(a | b) P(b)
= P(b | a) P(a)
Joining them together, we can find-
P(a | b) = P(b | a) P(a)
P(b)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 84
Application of Bayes’ Rule
A doctor knows that the disease meningitis causes the patient to
have a stiff neck is 50%
Means probability of stiff neck given the probability of having
meningitis
P(s | m) = 0.5
He also knows that in every 50000 patients, 1 may have meningitis
Means probability that a patient has meningitis
P (m) = 1/50000
He also knows that in every 20 patients, 1 may have stiff neck
Means probability that a patient has meningitis
P (m) = 1/20
Then, from Bayes’ rule
P(m | s) = P(s | m) P(m)
P(s)
Rushdi Shams, Dept of CSE, KUET, Bangladesh 85
Application of Bayes’ Rule
P(m | s) = P(s | m) P(m)
P(s)
= 0.5 X (1/50000)
1/20
= 0.0002
Means he can expect only 1 in 5000 patients with a stiff neck
to have meningitis
Rushdi Shams, Dept of CSE, KUET, Bangladesh 86
References
Artificial Intelligence: A Modern Approach (2nd
Edition)
by Russell and Norvig
Chapter 7, 8, 9, 13
http://www.iep.utm.edu/p/prop-log.htm#H5
http://www.cs.yale.edu/homes/cc392/node5.html
http://www.cs.nyu.edu/courses/spring03/G22.2560-001/ho
Rushdi Shams, Dept of CSE, KUET, Bangladesh 87
Acknowledgement
Dr. Adel Elsayed
Research Leader, M3C Lab, University of Bolton, UK
Weiqiang Wei
PhD Student, University of Bolton, UK

Knowledge representation

  • 1.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 1 Knowledge Representation IIKnowledge Representation II LogicsLogics Artificial IntelligenceArtificial Intelligence Version 1.0Version 1.0 There are 10 types of people in this world- who understand binaryThere are 10 types of people in this world- who understand binary and who do not understand binaryand who do not understand binary
  • 2.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 2 Propositional LogicPropositional Logic
  • 3.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 3 Introduction Need formal notation to represent knowledge, allowing automated inference and problem solving. One popular choice is use of logic. Propositional logic is the simplest. Symbols represent facts: P, Q, etc.. These are joined by logical connectives (and, or, implication) e.g., P Λ Q; Q ⇒ R Given some statements in the logic we can deduce new facts (e.g., from above deduce R)
  • 4.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 4 Syntactic Properties of Propositional Logic 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 (bi-conditional)
  • 5.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 5 Semantic Properties of Propositional Logic ¬S is true iff S is false S1 ∧ S2 is true iff S1 is true and S2 is true S1 ∨ S2 is true iff S1is true or S2 is true S1 ⇒ S2 is true iff S1 is false or S2 is true i.e., is false iff S1 is true and S2is false S1 ⇔ S2is true iff S1⇒S2 is true and S2⇒S1 is true
  • 6.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 6 Truth Table for Connectives
  • 7.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 7 Model of a Formula If the value of the formula X holds 1 for the assignment A, then the assignment A is called model for formula X. That means, all assignments for which the formula X is true are models of it.
  • 8.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 8 Model of a Formula
  • 9.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 9 Model of a Formula: Can you do it?
  • 10.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 10 Satisfiable Formulas If there exist at least one model of a formula then the formula is called satisfiable. The value of the formula is true for at least one assignment. It plays no rule how many models the formula has.
  • 11.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 11 Satisfiable Formulas
  • 12.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 12 Valid Formulas A formula is called valid (or tautology) if all assignments are models of this formula. The value of the formula is true for all assignments. If a tautology is part of a more complex formula then you could replace it by the value 1.
  • 13.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 13 Valid Formulas
  • 14.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 14 Unsatisfiable Formulas A formula is unsatisfiable if none of its assignment is true in no models
  • 15.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 15 Logical equivalence Two sentences are logically equivalent iff true in same models: α ≡ ß iff α╞ β and β α╞
  • 16.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 16 Deduction: Rule of Inference 1. Either cat fur was found at the scene of the crime, or dog fur was found at the scene of the crime. (Premise) C v D
  • 17.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 17 Deduction: Rule of Inference 2. If dog fur was found at the scene of the crime, then officer Thompson had an allergy attack. (Premise) D A→
  • 18.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 18 Deduction: Rule of Inference 3. If cat fur was found at the scene of the crime, then Macavity is responsible for the crime. (Premise) C M→
  • 19.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 19 Deduction: Rule of Inference 4. Officer Thompson did not have an allergy attack. (Premise) ¬ A
  • 20.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 20 Deduction: Rule of Inference 5. Dog fur was not found at the scene of the crime. (Follows from 2 D A→ and 4. ¬ A). When is ¬ A true? When A is false- right? Now, take a look at the implication truth table. Find what is the value of D when A is false and D A→ is true ¬ D
  • 21.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 21 Rules for Inference: Modus Tollens If given α β→ and we know ¬β Then ¬α
  • 22.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 22 Deduction: Rule of Inference 6. Cat fur was found at the scene of the crime. (Follows from 1 C v D and 5 ¬ D). When is ¬ D true? When D is false- right? Now, take a look at the OR truth table. Find what is the value of C when D is false and C V D is true C
  • 23.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 23 Rules for Inference: Disjunctive Syllogism If given α v β and we know ¬α then β If given α v β and we know ¬β then α
  • 24.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 24 Deduction: Rule of Inference 7. Macavity is responsible for the crime. (Conclusion. Follows from 3 C M→ and 6 C). When is C M→ true given that C is true? Take a look at the Implication truth table. M
  • 25.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 25 Rules for Inference: Modus Ponens If given α β→ and we know α Then β
  • 26.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 26 Conjunctive Normal Form (CNF) A formula is in conjunctive normal form (CNF) if it is a conjunction (AND) of clauses, where a clause is a disjunction (OR) of literals or a single literal. It is similar to the canonical product of sums form used in circuit theory All of the following formulas are in CNF:
  • 27.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 27 Conjunctive Normal Form (CNF) The following formulae are not in CNF: The above three formulas are respectively equivalent to the following three formulas that are in conjunctive normal form:
  • 28.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 28 Conjunctive Normal Form (CNF) Eliminate implication with its equivalence. This will turn P Q into ¬ P V Q→ Use de Morgan's law to move the ¬ symbol onto atoms (not sentences), replace: Perform the following operation:
  • 29.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 29 CNF (p ^ ~q) V (r V s) ^ (r V t) (p V r V s ) ^ (p V r V t) ^ (~q V r V s)^(~q V r V t)
  • 30.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 30 Horn Clause  A Horn clause is a clause with at most one positive literal.  Any Horn clause therefore belongs to one of four categories: 1. A rule: 1 positive literal, at least 1 negative literal. A rule has the form "~P1 V ~P2 V ... V ~Pk V Q". 2. A fact or unit: 1 positive literal, 0 negative literals. 3. A negated goal : 0 positive literals, at least 1 negative literal. 4. The null clause: 0 positive and 0 negative literals. Appears only as the end of a resolution proof.
  • 31.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 31 First Order Logic orFirst Order Logic or First Order Predicate Logic orFirst Order Predicate Logic or Predicate LogicPredicate Logic
  • 32.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 32 Introduction Propositional logic is declarative Propositional logic allows partial/disjunctive/negated information (unlike most data structures and databases) Meaning in propositional logic is context-independent (unlike natural language, where meaning depends on context) Propositional logic has very limited expressive power (unlike natural language) E.g., cannot say “if any student sits an exam they either pass or fail”. Propositional logic is compositional (meaning of B ^ P is derived from meaning of B and of P)
  • 33.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 33 Introduction You see that we can convert the sentences into propositional logic but it is difficult Thus, we will use the foundation of propositional logic and build a more expressive logic
  • 34.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 34 Introduction Whereas propositional logic assumes the world contains facts, first-order logic (like natural language) assumes the world contains Objects: people, houses, numbers, colors, baseball games, wars, … Relations: red, round, prime, brother of, bigger than, part of, comes between, … Functions: father of, best friend, one more than, plus, …
  • 35.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 35 Syntax of FOL: Basic Elements Constants KingJohn, 2, NUS,... Predicates Brother, >,... Functions Sqrt, LeftLegOf,... Variables x, y, a, b,... Connectives ¬, ⇒, ∧, ∨, ⇔ Equality = Quantifiers ∀, ∃
  • 36.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 36 Examples King John and Richard the Lion heart are brothers Brother(KingJohn,RichardTheLionheart) The length of left leg of Richard is greater than the length of left leg of King John > (Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn)))
  • 37.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 37 Atomic Sentences
  • 38.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 38 Atomic Sentences
  • 39.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 39 Complex Sentences Complex sentences are made from atomic sentences using connectives: ¬S, S1∧ S2, S1∨ S2, S1⇒ S2, S1⇔S2, Example Sibling(KingJohn,Richard) ⇒ Sibling(Richard,KingJohn)
  • 40.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 40 Complex Sentences
  • 41.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 41 FOL illustrated  Five objects- 1. Richard the Lionheart 2. Evil King John 3. Left leg of Richard 4. Left leg of John 5. The crown
  • 42.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 42 FOL illustrated  Objects are related with Relations  For example, King John and Richard are related with Brother relationship  This relationship can be denoted by (Richard,John),(John,Richard)
  • 43.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 43 FOL illustrated  Again, the crown and King John are related with OnHead Relationship- OnHead (Crown,John)  Brother and OnHead are binary relations as they relate couple of objects.
  • 44.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 44 FOL illustrated  Properties are relations that are unary.  In this case, Person can be such property acting upon both Richard and John Person (Richard) Person (John)  Again, king can be acted only upon John King (John)
  • 45.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 45 FOL illustrated  Certain relationships are best performed when expressed as functions.  Means one object is related with exactly one object. Richard -> Richard’s left leg John -> John’s left leg
  • 46.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 46 Universal quantification ∀<variables> <sentence> Everyone studies at KUET is smart: ∀x Studies (x,KUET) ⇒ Smart (x) ∀x P is true in a model m iff P is true with x being each possible object in the model Roughly speaking, equivalent to the conjunction of instantiations of P
  • 47.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 47 Universal quantification  Remember, we had five objects, let us replace them with a variable x- 1. x ―›Richard the Lionheart 2. x ―› Evil King John 3. x ―› Left leg of Richard 4. x ―› Left leg of John 5. x ―› The crown
  • 48.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 48 Universal quantification  Now, for the quantified sentence ∀x King (x) ⇒ Person (x) Richard is king ⇒ Richard is Person John is king ⇒ John is person Richard’s left leg is king ⇒ Richard’s left leg is person John’s left leg is king ⇒ John’s left leg is person The crown is king ⇒ the crown is person
  • 49.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 49 Universal quantification Richard is king ⇒ Richard is Person John is king ⇒ John is person Richard’s left leg is king ⇒ Richard’s left leg is person John’s left leg is king ⇒ John’s left leg is person The crown is king ⇒ the crown is person Only the second sentence is correct, the rest is incorrect
  • 50.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 50 A common mistake to avoid Typically, ⇒ is the main connective with ∀ Common mistake: using ∧ as the main connective with ∀: ∀x Studies (x,KUET) ∧ Smart (x) means “Everyone Studies at KUET and everyone is smart”
  • 51.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 51 Existential Quantification ∃<variables> <sentence> Someone studies at KUET is smart: ∃x Studies (x,KUET) ∧ Smart (x) ∃x P is true in a model m iff P is true with x being some possible object in the model Roughly speaking, equivalent to the disjunction of instantiations of P
  • 52.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 52 Another common mistake to avoid Typically, ∧ is the main connective with ∃ Common mistake: using ⇒ as the main connective with ∃: ∃x Studies (x,KUET) ⇒ Smart (x) means some guys, if they study in KUET, then they are smart
  • 53.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 53 Properties of quantifiers ∀x ∀y is the same as ∀y ∀x ∃x ∃y is the same as ∃y ∃x ∃x ∀y is not the same as ∀y ∃x
  • 54.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 54 Properties of quantifiers ∃x ∀y Loves(x,y) “There is a person who loves everyone in the world” ∀y ∃x Loves(x,y) “Everyone in the world is loved by at least one person”
  • 55.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 55 Properties of quantifiers Quantifier duality: each can be expressed using the other ∀x Likes(x,IceCream) is equivalent to ¬∃x ¬Likes(x,IceCream) ∃x Likes(x,Broccoli) is equivalent to ¬∀x ¬Likes(x,Broccoli)
  • 56.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 56 Properties of quantifiers  Equivalences- 1. ∃x P is equivalent to ¬∀x ¬P 2. ¬∃x ¬P is equivalent to ∀x P 3. ∃x ¬P is equivalent to ¬∀x P 4. ¬∃x P is equivalent to ∀x ¬P
  • 57.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 57 Equality term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object E.g., definition of Sibling in terms of Parent: ∀x,y Sibling(x,y) ⇔ [¬(x = y) ∧ ∃m,f ¬ (m = f) ∧ Parent(m,x) ∧ Parent(f,x) ∧ Parent(m,y) ∧ Parent(f,y)]
  • 58.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 58 Example knowledge base The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American. Prove that Col. West is a criminal
  • 59.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 59 Example knowledge base ... it is a crime for an American to sell weapons to hostile nations: American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Nono … has some missiles, Owns(Nono,x) Missile(x) … all of its missiles were sold to it by Colonel West Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missiles are weapons: Missile(x) ⇒ Weapon(x) An enemy of America counts as "hostile“: Enemy(x,America) ⇒ Hostile(x) West, who is American … American(West) The country Nono, an enemy of America … Enemy(Nono,America)
  • 60.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 60 Forward Chaining American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(x,America) ⇒ Hostile(x) American(West) Enemy(Nono,America)
  • 61.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 61 Forward Chaining American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(x,America) ⇒ Hostile(x) American(West) Enemy(Nono,America)
  • 62.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 62 Forward Chaining American(West) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(x,America) ⇒ Hostile(x) American(West) Enemy(Nono,America)
  • 63.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 63 Forward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(x,America) ⇒ Hostile(x) American(West) Enemy(Nono,America)
  • 64.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 64 Forward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(x,America) ⇒ Hostile(x) American(West) Enemy(Nono,America)
  • 65.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 65 Forward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(x) American(West) Enemy(Nono,America)
  • 66.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 66 Forward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(z) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 67.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 67 Forward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 68.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 68 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 69.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 69 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 70.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 70 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 71.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 71 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 72.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 72 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,z) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 73.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 73 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,Nono) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 74.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 74 Backward Chaining American(West) ∧ Weapon(y) ∧ Sells(West,y,Nono) ∧ Hostile(Nono) ⇒ Criminal(x) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 75.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 75 …& the Inference American(West) ∧ Weapon(y) ∧ Sells(West,y,Nono) ∧ Hostile(Nono) ⇒ Criminal(West) Owns(Nono,x) Missile(x) Missile(x) ∧ Owns(Nono,x) ⇒Sells(West,x,Nono) Missile(x) ⇒ Weapon(x) Enemy(Nono,America) ⇒ Hostile(Nono) American(West) Enemy(Nono,America)
  • 76.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 76 Probability: Logic forProbability: Logic for UncertaintyUncertainty
  • 77.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 77 Conditional Probability Definition of conditional probability: P(a | b) = P(a ∧ b) / P(b) if P(b) > 0 Product rule gives an alternative formulation: P(a ∧ b) = P(a | b) P(b) = P(b | a) P(a) 
  • 78.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 78 Inference with Probability
  • 79.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 79 Inference in Probability P(toothache) = 0.108 + 0.012 + 0.016 + 0.064 = 0.2
  • 80.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 80 Inference in Probability P(cavity V toothache) = 0.108 + 0.012 + 0.072 + .008 + 0.016 + 0.064 = 0.28
  • 81.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 81 Inference in Probability Can also compute conditional probabilities:
  • 82.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 82 Inference in Probability Can also compute conditional probabilities:
  • 83.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 83 Baye’s Rule Product rule gives an alternative formulation: P(a ∧ b) = P(a | b) P(b) = P(b | a) P(a) Joining them together, we can find- P(a | b) = P(b | a) P(a) P(b)
  • 84.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 84 Application of Bayes’ Rule A doctor knows that the disease meningitis causes the patient to have a stiff neck is 50% Means probability of stiff neck given the probability of having meningitis P(s | m) = 0.5 He also knows that in every 50000 patients, 1 may have meningitis Means probability that a patient has meningitis P (m) = 1/50000 He also knows that in every 20 patients, 1 may have stiff neck Means probability that a patient has meningitis P (m) = 1/20 Then, from Bayes’ rule P(m | s) = P(s | m) P(m) P(s)
  • 85.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 85 Application of Bayes’ Rule P(m | s) = P(s | m) P(m) P(s) = 0.5 X (1/50000) 1/20 = 0.0002 Means he can expect only 1 in 5000 patients with a stiff neck to have meningitis
  • 86.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 86 References Artificial Intelligence: A Modern Approach (2nd Edition) by Russell and Norvig Chapter 7, 8, 9, 13 http://www.iep.utm.edu/p/prop-log.htm#H5 http://www.cs.yale.edu/homes/cc392/node5.html http://www.cs.nyu.edu/courses/spring03/G22.2560-001/ho
  • 87.
    Rushdi Shams, Deptof CSE, KUET, Bangladesh 87 Acknowledgement Dr. Adel Elsayed Research Leader, M3C Lab, University of Bolton, UK Weiqiang Wei PhD Student, University of Bolton, UK