Documente Academic
Documente Profesional
Documente Cultură
Inferential reasoning
Hridaya Kandel
hridayakandel@gmail.com
AI Lecturer
BScCSIT Vth
Hridaya Kandel 1
Objective
Students should understand the importance of knowledge
representation
Students should understand the use of formal logic as a knowledge
representation language
The student should be familiar with the concepts of logic such as
syntax, semantics, validity, models, entailment.
student should be able Represent a natural language description as
statements in logic and Deduct new sentences by applying inference
rules.
Students should learn in details about resolution techniques
Hridaya Kandel 2
Knowledge-based Agents
Intelligent agents should have capacity for:
Perceiving, that is, acquiring information from environment,
Knowledge Representation, that is, representing its understanding of
the world,
Reasoning, that is, inferring the implications of what it knows and of
the choices it has, and
Acting, that is, choosing what it want to do and carry it out.
Hridaya Kandel 3
Knowledge-based Agents
Representation of knowledge and the reasoning process are
central to the entire field of artificial intelligence.
Useful mostly in partially observable environments
Hridaya Kandel 4
Knowledge-based Agents
Understanding natural language also requires inferring hidden
state, namely, the intention of the speaker.
Example:
John saw the diamond through the window and coveted it, we
know it refers to the diamond and not the window
when we hear, John threw the brick through the window and
broke it, we know it refers to the window
Reasoning allows us to cope/deal with the virtually infinite
variety of utterances(vocal expressions) using a finite store of
commonsense knowledge.
Problem-solving agents have difficulty with this kind of
ambiguity because their representation of contingency
problems is inherently exponential.
Hridaya Kandel 5
Knowledge-based Agents
Knowledge-based Agents are flexible
They are able to accept new tasks in the form of explicitly described
goals,
they can achieve competence quickly by being told or learning new
knowledge about the environment, and
they can adapt to changes in the environment by updating the relevant
knowledge.
Hridaya Kandel 6
Knowledge-based Agents
The central component of a knowledge-based agent is its
knowledge base, or KB. Informally, a knowledge base is a set
of sentences (not English sentences).
Knowledge base = set of sentences in a formal language
Each sentence is expressed in a language called a knowledge
representation language. A language used to express
knowledge about the world
Declarative approach language is designed to be able to easily
express knowledge for the world the language is being implemented
for
Procedural approach encodes desired behaviors directly in program
code
Hridaya Kandel 7
Knowledge-based Agents
The new sentences are added to the Knowledge Base and the
query are made on Knowledge Base. This two task are
performed using the two generic functions.
TELL: add new sentences (facts) to the KB
Tell it what it needs to know
ASK: query what is known from the KB
Ask what to do next
Hridaya Kandel 8
Wumpus World
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 iff gold is in the same square
Shooting kills wumpus if you are facing it
Shooting uses up the only arrow
Grabbing picks up gold if in same square
Releasing drops the gold in same square
Sensors: Stench, Breeze, Glitter, Bump, Scream
Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
The percepts will be given to the agent in the form of a list of five symbols; for
example, if there is a stench and a breeze, but no glitter, bump, or scream, the agent
will receive
Hridaya Kandel the percept [Stench; Breeze; 9None; None; None].
Wumpus World
Hridaya Kandel 10
Exploring Wumpus World
We will mark down what we know initially the agent (A) is in 1,1, and
we know that that square is OK.
It then gets the first percept remember order is [stench, breeze, glitter,
bump, scream] and first percept has these all null [null null null null
null].
The agent will move only into a square it knows to be OK.
Hridaya Kandel 11
Exploring Wumpus World
In initial state, there are no percepts (the sequence is none, none, none, none,
none) and therefore it can be inferred that the neighboring squares are safe (OK).
Hridaya Kandel 12
Exploring Wumpus World
The agent decides to move up and feels a breeze what does this mean?
Hridaya Kandel 13
Exploring Wumpus World
That there is a pit in either of the two neighboring squares. Better not move there
since it knows there is a safer move if it backs up
Hridaya Kandel 14
Exploring Wumpus World
Hridaya Kandel 15
Exploring Wumpus World
A pretty difficult inference!; note how difficult because of the inference of where
the pit is depends on the lack of a percept (no B in 2,1) and percepts gathered over
time.
Hridaya Kandel 16
Exploring Wumpus World
Hridaya Kandel 17
Exploring Wumpus World
Hridaya Kandel 18
Exploring Wumpus World
Hridaya Kandel 19
Exploring Wumpus World
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.
Hridaya Kandel 22
Logic in general
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 Nepal won and the India won entails
Either the Nepal won or the India won
E.g., x+y = 4 entails 4 = x+y
Hridaya Kandel 24
Logic in general
The KB is false in models that contradict what the agent
knowsfor example, the KB is false in any model in which
[1,2] contains a pit, because there is no breeze in [1,1]. There
are in fact just three models in which the KB is true, and these
are shown as a subset of the models in Figure
Hridaya Kandel 26
Logic in general
For conclusion
2 = There is no pit in [2,2].
Hridaya Kandel 28
Logic in general
An inference algorithm that derives only entailed sentences is called
sound or truth preserving.
Soundness
i is sound if
whenever KB |-i a is true, KB |= a is true
Hridaya Kandel 30
Propositional Logic
Propositional logic is the simplest logic.
Also Known As Boolean Logic
The syntax of propositional logic defines the allowable sentences.
Proposition symbols P1, P2, etc are sentences
Atomic sentence - consists of a single propositional symbol, which is True or
False
Complex sentence-sentence constructed from simpler sentences using
parentheses and logical connectives:
(not) negation
(and) conjunction
( or) disjunction
(implies) implication (premise=>conclusion)
(if and only if) biconditional
P Q P PQ PQ PQ PQ
False False True False False True True
False True True False True True False
Truth table for connectives:
Hridaya Kandel
True False
31
False False True False False
True True False True True True True
Propositional Logic
Formal grammar for propositional logic can be given as below
Hridaya Kandel 32
Propositional Logic
A simple KB : Wumpus World
For simplicity: we deal only with pits.
Choose vocabulary of proposition symbols. For each i, j
Let Pi,j be True if there is a pit in [i,j]
Let Bi,j be True if there is a breeze in [i,j]
The KB contains the following (Rules)
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. (for
simplicity only relevant square)
R2: B1,1 (P1,2 P2,1)
R3: B2,1 (P1,1 P2,2 P3,1)
The breeze percepts for the first two squares visited in the specific world the agent
is in
Hridaya Kandel
R4: B1,1 33
R5: B2,1
Propositional Logic
Figure: A truth table constructed for the knowledge base as discussed. KB is true if
R1 through R5 are true, which occurs in just 3 of the 128 rows. In all 3 rows, P 1,2 is
false, so there is no pit in [1,2]. On the other hand, there might (or might not) be a pit
in [2,2].
Hridaya Kandel 34
KB example
Hridaya Kandel 35
KB example
Hridaya Kandel 36
KB example
Hridaya Kandel 37
Propositional Logic: Equivalence
Hridaya Kandel 38
Validity, Satisfiability, Unsatisfiability
Hridaya Kandel 40
Reasoning Patterns
A Inference Rules
Patterns of inference that can be applied to derive chains of
conclusions that lead to the desired goal.
Proof rules (or inference rules) show us, given true statements how to
generate further true statements.
Hridaya Kandel 41
Inference Rules
Modus Ponens
This well known proof rule is called modus ponens, i.e. in general
Hridaya Kandel 42
Inference Rules
AND ()-elimination
From a conjunction, any of the conjuncts can be inferred
The first of these can be read if A and B hold (or are provable or true) then
A must also hold.
(WumpusAhead WumpusAlive), WumpusAlive can be inferred
Hridaya Kandel 43
Inference Rules
OR ()-introduction
Another proof rule, known as -introduction is
The first of these can be read if A holds (or are provable or true) then A B
must also hold.
All of the logical equivalences can be used as inference rules
Note:
sequence of applications of inference rulesis called a Proof.
Finding proofs is exactly like finding solutions to search problems.
Monotonicity
says that the set of entailed sentences can only increase as information is
added to the knowledge base.
If we have a proof, adding information to the DB will not invalidate the
Hridaya Kandel 44
proof
Inference Rules: Example
From r s and s p can we prove p, i.e. show r s, s p
p?
Hridaya Kandel 45
Resolution
We have argued that the inference rules covered so far are sound, but we have not
discussed the question of completeness for the inference algorithms that use them.
Resolution is a proof method for classical propositional and first-order logic.
Resolution allows a complete inference mechanism (search-based) using only one
rule of inference ie. Resolution itself
The (propositional) resolution rule is as follows
Hridaya Kandel 46
Resolution
Unit Resolution
Unit resolution rule takes a clause a disjunction of literals and a literal and
produces a new clause. Single literal is also called unit clause.
Hridaya Kandel 48
Resolution Method
Example
Show by resolution that the following set of clauses is unsatisfiable.
The sets of clauses are already in CNF.
Hridaya Kandel 49
Resolution Method: example
First Convert to CNF B1,1 (P1,2 P2,1)
1. Eliminate , replacing with ( )( ).
(B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1)
Hridaya Kandel 50
Resolution Method: Example
Conclusion: there is no pit in [1,2]
i.e = P1,2
Proof by contradiction, i.e., show
KB unsatisfiable
We have
KB = (B1,1 (P1,2 P2,1)) B1,1
= P1,2
Hridaya Kandel 51
Resolution Method: Exercise
Use resolution Algorithm to solve the following problem
KB entails A
Hridaya Kandel 52
Evaluation : Resolution
Resolution is sound
Because the resolution rule is true in all cases
Resolution is complete
Provided a complete search method is used to find the
proof, if a proof can be found it will
Note: you must know what youre trying to prove in
order to prove it!
Resolution is exponential
The number of clauses that we must search grows
exponentially
Hridaya Kandel 53
Horn clause
Real-world knowledge bases often contain only clauses of a
restricted kind called Horn clauses.
A Horn clause is a disjunction of literals of which at most one is
positive.
The positive literal is called the head and the negative literals form the
body of the clause
For example, the clause ( L Breeze B), is a Horn clause, whereas
( B P P) is not.
Importance:
Horn Clauses form the basis of forward
and backward chaining
Deciding entailment with Horn Clauses
is linear in the size of the knowledge
base.
Can be written as an implication
(example) Fig: Example of Horn clauses
Note: Hridaya
TheKandel
Prolog language is based on Horn
54
Clauses
ANDOR graphs
ANDOR graphs,
multiple links joined by an arc indicate a conjunctionevery
link must be proved
while multiple links without an arc indicate a disjunction
any link can be proved.
Hridaya Kandel 55
Reasoning with Horn Clauses
Forward Chaining
For each new piece of data, generate all new facts, until
the desired fact is generated
Data-directed reasoning
Backward Chaining
To prove the goal, find a clause that contains the goal as
its head, and prove the body recursively
(Backtrack when you chose the wrong clause)
Goal-directed reasoning
Hridaya Kandel 56
Forward Chaining
Fire any rule whose premises are satisfied in the KB
Add its conclusion to the KB until the query is found
Hridaya Kandel 57
Forward Chaining
Hridaya Kandel 58
Forward Chaining
Hridaya Kandel 59
Forward Chaining
Hridaya Kandel 60
Forward Chaining
Hridaya Kandel 61
Forward Chaining
Hridaya Kandel 62
Forward Chaining
Hridaya Kandel 63
Forward Chaining
Hridaya Kandel 64
Forward Chaining
Hridaya Kandel 65
Backward Chaining
Idea: work backwards from the query q:
To prove q by BC,
Check if q is known already, or
Prove by BC all premises of some rule concluding q
Avoid loops
Check if new subgoal is already on the goal stack
Hridaya Kandel 66
Backward Chaining
Hridaya Kandel 67
Backward Chaining
Hridaya Kandel 68
Backward Chaining
Hridaya Kandel 69
Backward Chaining
Hridaya Kandel 70
Backward Chaining
Hridaya Kandel 71
Backward Chaining
Hridaya Kandel 72
Backward Chaining
Hridaya Kandel 73
Backward Chaining
Hridaya Kandel 74
Backward Chaining
Hridaya Kandel 75
Backward Chaining
Hridaya Kandel 76
Backward Chaining
Hridaya Kandel 77
Translation Guide
Hridaya Kandel 78
Pros and Cons of PL
Propositional logic is declarative
Propositional logic allows partial/disjunctive/negated
information
(unlike most data structures and databases)
Propositional logic is compositional:
meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2
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 "pits cause breezes in adjacent squares
except by writing one sentence for each square
Hridaya Kandel 79
Logics in General
Ontological Commitment:
What exists in the world TRUTH
PL : facts hold or do not hold.
FOL : objects with relations between them that hold or do not hold
Epistemological Commitment:
What an agent believes about facts BELIEF
Hridaya Kandel 80
First-order logic
Whereas propositional logic assumes the world contains facts,
first-order logic (like natural language) assumes the world
contains
Objects, which are things with individual identities
Properties of objects that distinguish them from other objects
Relations that hold among sets of objects
Functions, which are a subset of relations where there is only one value for
any given input
Examples:
Objects: Students, lectures, companies, cars ...
Relations: Brother-of, bigger-than, outside, part-of, has-color, occurs-after,
owns, visits, precedes, ...
Properties: blue, oval, even, large, ...
Functions: father-of, best-friend, second-half, one-more-than ...
Hridaya Kandel 81
Models for FOL: Graphical Example
Hridaya Kandel 82
Syntax of FOL: Basic elements
Constant Symbols: which represent individuals in the world
Stand for objects
e.g., KingJohn, 2, UCI,...
Predicate Symbols : which map individuals to truth values
Stand for relations
E.g., Brother(Richard, John), greater_than(3,2)...
Function Symbols : which map individuals to individuals
Stand for functions
E.g., Sqrt(4), LeftLegOf(John),...
Variables x, y, a, b,...
Connectives , , , ,
Equality =
Quantifiers ,
Hridaya Kandel 83
Syntax of FOL:BNF
Hridaya Kandel 84
FOPL: Sentences
A term (denoting a real-world individual) is a constant symbol, a variable
symbol, or an n-place function of n terms.
x and f(x1, ..., xn) are terms, where each xi is a term.
A term with no variables is a ground term
Examples:
LargerThan(2,3) is false.
Brother_of(Mary,Pete) is false.
Married(Father(Richard), Mother(John)) could be true or false
Brother_of(Pete,Brother(Pete)) is True.
Hridaya Kandel 86
Binary relation Function
Complex Sentence
binary function
relation
objects
connectives
Hridaya Kandel 87
Universal Quantification
Universal quantification
<variables> <sentence>
Allows us to make statements about all objects that have certain properties
(x)P(x) means that P holds for all values of x in the domain associated
with that variable
E.g.,
x dolphin(x) => mammal(x)
x King(x) => Person(x)
x Person(x) => HasHead(x)
i Integer(i) => Integer(plus(i,1))
Hridaya Kandel 97
Existential generalization
Existential Introduction/ Existential generalization
If P(c) is true, then (x) P(x) is inferred
For any sentence , variable v that does not occur in , and ground term g that
does occur in :
v SUBST({g/v}, )
Example
eats(Ziggy, IceCream) (x) eats(Ziggy, x)
All instances of the given constant symbol are replaced by the new variable
symbol
Note that the variable symbol cannot already exist anywhere in the expression
Hridaya Kandel 98
Reduction to propositional form
FOL->predicate Logic(PL) (Some may call reduction to Propositional Logic)
Existential and universal instantiation allows to propositionalize any FOL
sentence or KB
EI produces one instantiation per Existential Quantified (EQ) sentence
UI produces a whole set of instantiated sentences per Universal Quantified (UQ)
sentence
Example:
Suppose the KB contains the following: Instantiating the universal sentence in all
x King(x) Greedy(x) Evil(x) possible ways, we have:
Father(x) King(John) Greedy(John) Evil(John)
King(John) King(Richard) Greedy(Richard) Evil(Richard)
Greedy(John) King(John)
Brother(Richard,John) Greedy(John)
Brother(Richard,John)
p q
Last unification fails: only because x cant take values John and Elizabeth at
the same time
Problem is due to use of same variable x in both sentences .Both use the same
variable, X. X cant equal both John and Elizabeth.
The solution: change the variable X to Y (or any other value) in Knows(X,
Elizabeth)
Knows(X, Elizabeth) is changed to Knows(Y, Elizabeth) which Still means the
same.
This is called standardizing apart.
Hridaya Kandel
Standardizing apart eliminates
102
overlap of variables
Unification Complication
A problem may arise in unification when the variable take two values as seen in the
example before
Standardizing apart eliminates overlap of variables.
Process: rename all variables so that variables bound by different quantifiers have
unique names for each sentences in KB.
For example if KB has following After Standardizing apart KB becomes
x Apple(x) => Fruit(x) x Apple(x) => Fruit(x)
x Spider(x) => Arachnid(x) y Spider(y) => Arachnid(y)
There is one more complication with Unification: we said that UNIFY should return
a substitution that makes the two arguments look the same. But there could be more
than one such unifier.
Example To unify Knows(John,x) and Knows(y,z),
This can return two possible unifications:
{y/ John, x/ z} which means Knows(John, z) OR {y/ John, x/ John, z/ John} which means
Knows(John, John).
So the unification algorithm is required to return the (unique) most general unifier (MGU).
for above example MGU = { y/John, x/z }
There is a single most general unifier (MGU) that is unique up to renaming of variables
Hridaya Kandel 103
Generalized Modus Ponens (GMP)
This is a general inference rule for FOL(lifted) that does not require
instantiation
For atomic sentences pi, pi' , and q, where there is a substitution such that
Subst(, pi' )= Subst(, pi), for all i,
More on Skolemization
If an existentially quantified variable is in the scope of universally quantified
variables, then the existentially quantified variable must be a function of those
other variables. We introduce a new, unique function called Skolem function.
Hridaya Kandel 119
Converting FOL sentences to CNF: Example
Original sentence:
Anyone who likes all animals is loved by someone:
x [y Animal(y) Likes(x,y)] [y Loves(y,x)]
2. Move inwards:
Recall: x p x p, x p x p
x [y (Animal(y) Likes(x,y))] [y Loves(y,x)]
x [y Animal(y) Likes(x,y)] [y Loves(y,x)]
x [y Animal(y) Likes(x,y)] [y Loves(y,x)]
Either there is some animal that x doesn'tt like if that is not the case then someone
loves x
4. Skolemize:
x [Animal(A) Likes(x,A)] Loves(B,x)
Everybody fails to love a particular animal A or is loved by a particular
person B
Animal(cat)
Likes(marry, cat)
Loves(john, marry)
Likes(cathy, cat)
Loves(Tom, cathy)
a more general form of existential instantiation.
6. Distribute over :
[Animal(F(x)) Loves(G(x),x)] [Likes(x,F(x)) Loves(G(x),x)]
Original sentence is now in CNF form can apply same ideas to all
sentences in KB to convert into CNF
KB:
a) Everyone who loves all animals is loved by someone.
b) Anyone who kills animals is loved by no-one.
c) Jack loves all animals.
d) Either Curiosity or Jack killed the cat, who is named Tuna.
Query: Did Curiosity kill the cat?
Inference Procedure:
1. Express sentences in FOL.
2. Eliminate existential quantifiers.
3. Convert to CNF form and negated query.
Approaches to Reasoning
There are three different approaches to reasoning under uncertainties.
Symbolic reasoning (facts)
Statistical reasoning (degree of belief)
Fuzzy logic reasoning (degree of truth)
Statistical reasoning
In the logic based approaches (symbolic), we have assumed that everything is either
believed false or believed true.
However, it is often useful to represent the fact that we believe such that something
is probably true, or true with probability (say) 0.55.
This is useful for dealing with problems where there is randomness and
unpredictability (such as in games of chance) and also for dealing with problems
where we could, if we had sufficient information, work out exactly what is true. To
do all this in a principled way requires techniques for probabilistic reasoning.
Atomic event: A complete specification of the state of the world about which the
agent is uncertain
E.g., if the world consists of only two Boolean Random variables Cavity and
Toothache, then there are 4 distinct atomic events:
Cavity = false Toothache = false Can also be written as
Cavity = false Toothache = true cavity toothache
cavity toothache
Cavity = true Toothache = false cavity toothache
Cavity = true Toothache = true cavity toothache
Atomic events are mutually exclusive and exhaustive
Atomic event: A complete specification of the state of the world about which the
agent is uncertain
E.g., if the world consists of only two Boolean Random variables Cavity and
Toothache, then there are 4 distinct atomic events:
Cavity = false Toothache = false Can also be written as
Cavity = false Toothache = true cavity toothache
cavity toothache
Cavity = true Toothache = false cavity toothache
Cavity = true Toothache = true cavity toothache
Atomic events are mutually exclusive and exhaustive
Toothache Toothache
P(CavityToothache) P(CavityToothache)
Tooth ~ Tooth
Catch ~ Catch Catch ~ Catch
Cavity 0.108 0.012 0.072 0.008
~ Cavity 0.016 0.064 0.144 0.576
Example: What is the probability that the alarm has sounded, but neither burglary nor an
earthquake has occurred, and both John and Mary call?
P(J M A B E ) = P(J|A)* P(M|A)*P(A|B E )*P(B) P(E)
Hridaya Kandel
=0.9 * 0.7 * 0.001 *148
0.999 * 0.998 = 0.00062
Thank You!