0% found this document useful (0 votes)
0 views

Module 3

The document discusses informed (heuristic) search strategies, focusing on methods like Greedy best-first search and A* search, which utilize problem-specific knowledge to find solutions more efficiently than uninformed strategies. It explains the importance of heuristic functions in evaluating nodes and outlines conditions for optimality, such as admissibility and consistency. Additionally, it covers memory-bounded heuristic search methods like IDA* and RBFS, and the generation of admissible heuristics from relaxed problems and pattern databases.

Uploaded by

h13584962
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Module 3

The document discusses informed (heuristic) search strategies, focusing on methods like Greedy best-first search and A* search, which utilize problem-specific knowledge to find solutions more efficiently than uninformed strategies. It explains the importance of heuristic functions in evaluating nodes and outlines conditions for optimality, such as admissibility and consistency. Additionally, it covers memory-bounded heuristic search methods like IDA* and RBFS, and the generation of admissible heuristics from relaxed problems and pattern databases.

Uploaded by

h13584962
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 71

BAD402-Module 3

INFORMED (HEURISTIC)
SEARCH STRATEGIES

how an informed search strategy—one that uses problem-specific knowledge


beyond the definition of the problem itself—can find solutions more efficiently than can
an uninformed strategy .

1
Module 3-Contents
• Informed (Heuristic) Search Strategies
• Greedy best first search
• A*search
• Heuristic Functions
• Logical Agents:
• Knowledge—based agents
• The Wumpus world
• Logic
• Propositional logic
• Reasoning patterns in Propositional Logic

2
BEST-FIRST SEARCH
• Best-first search is an instance of the general TREE-SEARCH or GRAPH-SEARCH
algorithm in which a node is selected for expansion based on an evaluation
function, f(n).
• The evaluation function is construed as a cost estimate, so the node with the
lowest evaluation is expanded first.
• Most best-first algorithms include as a component of f a heuristic function,
denoted h(n):
h(n) = estimated cost of the cheapest path from the state at node n to a goal state
• For example, in Romania, one might estimate the cost of the cheapest path from
Arad to Bucharest via the straight-line distance from Arad to Bucharest.
• Heuristic functions are the most common form in which additional knowledge of
the problem is imparted to the search algorithm.
3
Example: Romania

4
Greedy best-first search
Greedy best-first search tries to expand the node that is closest to the goal, on the grounds
that this is likely to lead to a solution quickly. Thus, it evaluates nodes by using just the heuristic
function; that is, f(n) = h(n).

5
Let us see how this works for route-finding problems in Romania;
• straight- line distance heuristic, which we will call hSLD.
• If the goal is Bucharest, we need to know the straight-line distances
to Bucharest, shown in Figure 3.22. For example,
• hSLD(In(Arad))=366. Notice that the values of hSLD cannot be computed
from the problem description itself.
• It takes a certain amount of experience to know that hSLD is correlated
with actual road distances and is, therefore, a useful heuristic.

6
7
The worst-case time and
space complexity for the tree
version is O(bm), where m is
the maximum
depth of the search space.

Greedy best-first tree search is also incomplete even in a finite state space, much like depth-
first search.
8
A* search: Minimizing the total
estimated solution cost
The most widely known form of best-first search is called A* search (pronounced “A-
star search”).
It evaluates nodes by combining g(n), the cost to reach the node, and h(n), the cost to get
from the node to the goal:
f(n) = g(n) + h(n) .

• g(n) gives the path cost from the start node to node n, and h(n) is the estimated cost of
the cheapest path from n to the goal.
• f(n) = estimated cost of the cheapest solution through n .

To find the cheapest solution, a reasonable thing to try first is the node with the lowest value of
g(n) + h(n). It turns out that this strategy is more than just reasonable: provided that the
heuristic function h(n) satisfies certain conditions, A* search is both complete and optimal.

9
Stages in an A∗ search for
Bucharest

10
11
12
Conditions for optimality:
Admissibility and consistency
Admissibility
• The first condition required for optimality is that h(n ) be an admissible heuristic.
• An admissible heuristic is one that never overestimates the cost to reach the goal.
• Because g(n) is the actual cost to reach n along the current path, and f(n)=g(n) + h(n),
• An immediate consequence that f(n) never overestimates the true cost of a solution along the current path
through n.

Admissible heuristics are by nature optimistic because they think the cost of solving the
problem is less than it actually is.

Example: Straight-line distance is admissible because the shortest path between


any two points is a straight line, so the straight line cannot be an overestimate.

13
Consistency

A second, slightly stronger condition called consistency (or sometimes monotonicity) is


required only for applications of A* to graph search.

A heuristic h(n) is consistent if, for every node n and every successor n' of n generated by
any action a, the estimated cost of reaching the goal from n is no greater than the step
cost of getting to n' plus the estimated cost of reaching the goal from n' :

h(n) ≤ c(n, a, n ') + h(n ') .


This is a form of the general triangle inequality,

Here, the triangle is formed by n, n' and the goal Gn closest to n.

For example, hSLD is a consistent heuristic.

14
Optimality of A*
A* has the following properties:
The tree-search version of A* is optimal if h(n) is admissible,
while the graph-search version is optimal if h(n) is
The consistent.
argument for the optimality of uniform-cost search, with g replaced by f—just as in the A*
algorithm itself.

The first step is to establish the following:


if h(n) is consistent, then the values of f(n) along any path are nondecreasing.
The proof follows directly from the definition of consistency.
Suppose n' is a successor of n; then g(n')=g(n) + c(n, a, n ') for some action a, and we
have

f(n) = g(n ') + h(n ') = g(n ) + c(n, a, n ') + h(n ') ≥ g(n) + h(n) =
f(n) .
The next step is to prove that whenever A* selects a node n for expansion, the optimal path to
that node has been found. Were this not the case, there would have to be another frontier 15
node
If C* is the cost of the optimal solution path, then we can say the following:
• A* expands all nodes with f(n) < C*.
• A* might then expand some of the nodes right on the “goal contour” (where f(n) = C*)
before selecting a goal node.
16
17
Absolute error and Relative
error
The absolute error is defined as Δ ≡ h* − h,
where h* is the actual cost of getting from the root to the goal

and

The relative error is defined as ε ≡ (h* − h)/h*.

The time complexity of A* is exponential in the maximum absolute error O(bΔ).


For constant step costs, we can write this as O(bεd), where d is the solution depth.
A*’s main drawback
• The complexity of A* often makes it impractical to insist on finding an optimal solution.
• Computation time is high, because it keeps all generated nodes in memory

18
Memory-bounded heuristic
search
To reduce memory requirements for A* - adapt the idea of iterative deepening
to the heuristic search iterative-deepening A* (IDA*) algorithm.

The main difference between IDA* and standard iterative deepening is


• The cutoff used is the f-cost (g+h) rather than the depth; at each iteration,
• The cutoff value is the smallest f-cost of any node that exceeded the cutoff
on the previous iteration.

IDA* difficulties with real valued costs (overhead associated with keeping a sorted queue of
nodes)

Two other memory-bounded algorithms, called RBFS and MA*

19
Recursive best-first search
(RBFS)
function R -B -F -S
ECURSIVE (problem) returns a solution, or failure
EST IRST EARCH
return RBFS(problem,MAKE-NODE(problem.INITIAL-STATE),∞)

function RBFS(problem, node, f limit ) returns a solution, or failure and a new f-cost limit
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
successors ←[ ]
for each action in problem.ACTIONS(node.STATE) do
add CHILD-NODE(problem, node, action) into successors
if successors is empty then return failure,∞
for each s in successors do /* update f with value from previous search, if any
*/
s.f ←max(s.g + s.h, node.f ))
loop do
best ←the lowest f-value node in successors
if best .f > f limit then return failure, best .f
alternative ←the second-lowest f-value among successors
result , best .f ←RBFS(problem, best , min( f-limit, alternative))
if result = failure then return result

20
• f-limit variable to keep track of the f-value of the best
alternative path available from any ancestor of the current
node.
• If the current node exceeds this limit, the recursion unwinds
back to the alternativepath.
• As the recursion unwinds, RBFS replaces the f-value of each
node along the path with a backed-up value—the best f-
value of its children.

21
Recursive best-first search
(RBFS)
• The f-limit value for each recursive call is shown on top of each current
node,
• every node is labeled with its f-cost.

The path via Rimnicu Vilcea is followed until the current best leaf (Pitesti) has a value that is
worse than the best alternative path (Fagaras).
22
The recursion unwinds and the best leaf value of the forgotten subtree (417) is backed up to
Rimnicu Vilcea; then Fagaras is expanded, revealing a best leaf value of 450.

23
The recursion unwinds and the best leaf value of the forgotten subtree (450) is backed up to
Fagaras; then Rimnicu Vilcea is expanded. This time, because the best alternative path
(through Timisoara) costs at least 447, the expansion continues to Bucharest.

24
Limitations

IDA∗ and RBFS suffer from using too little memory. Between iterations, IDA* retains only a
single number: the current f-cost limit.

MA∗ (memory-bounded A∗) SMA∗ (simplified MA∗).


• SMA* proceeds just like A*, expanding the best leaf until memory is full.
• it cannot add a new node to the search tree without dropping an old one.
• SMA* always drops the worst leaf node—the one with the highest f-value.

• Like RBFS, SMA* then backs up the value of the forgotten node to its parent.
• the ancestor of a forgotten subtree knows the quality of the best path in that
subtree.
SMA* expands the newest best leaf and deletes the oldest worst leaf.

25
HEURISTIC FUNCTIONS

26
• The average solution cost for a randomly generated 8-puzzle instance
is about 22 steps.
• The branching factor is about 3. (When the empty tile is in the middle,
four moves are possible; when it is in a corner, two; and when it is
along an edge, three.)
• This means that an exhaustive tree search to depth 22 would look at
about 322≈ 3.1×1010 states.
• A graph search would cut this down by a factor of about 170,000
because only 9!/2 =181, 440 distinct states are reachable.

27
Here are two commonly used candidates:
• h1 = the number of misplaced tiles.
For Figure 3.28, all of the eight tiles are out of position, so the
start state would have h1 = 8. h1 is an admissible heuristic
because it is clear that any tile that is out of place must be moved
at least once.
• h2 = the sum of the distances of the tiles from their goal positions.
Because tiles cannot move along diagonals, the distance we will
count is the sum of the horizontal and vertical distances. This is
sometimes called the city block distance or Manhattan
distance. h2 is also admissible because all any move can do is
move one tile one step closer to the goal. Tiles 1 to 8 in the start
state give a Manhattan distance of

h2 = 3+1 + 2 + 2+ 2 + 3+ 3 + 2 = 18 .
28
The effect of heuristic accuracy
on performance
One way to characterize the quality of a heuristic is the effective branching
factor b*
If the total number of nodes generated by A* for a particular problem is N and the
solution depth is
d, then b* is the branching factor that a uniform tree of depth d would have to have in
order to contain N + 1 nodes.
Thus,
N + 1 = 1+b* + (b *)2+ ・ ・ ・ + (b*)d.
For example, if A* finds a solution at depth 5 using 52 nodes, then the effective
branching factor is 1.92.

A well designed heuristic would have a value of b* close to 1

29
Domination translates directly into efficiency
from the definitions of the two heuristics that, for any node n, h2(n) ≥ h1(n), say that h2
dominates h1.
30
Generating admissible
heuristics from
relaxed problems
A problem with fewer restrictions on the actions is called a relaxed
problem.
The state-space graph of the relaxed problem is a supergraph of the original state space
because the removal of restrictions creates added edges in the graph.

the cost of an optimal solution to a relaxed problem is an admissible heuristic for the
original problem.
If a problem definition is written down in a formal language, it is possible to construct
relaxed problems automatically.
For example, if the 8-puzzle actions are described as
A tile can move from square A to square B if
A is horizontally or vertically adjacent to B and B is blank,
we can generate three relaxed problems by removing one or both of the conditions:

(a) A tile can move from square A to square B if A is adjacent to B.


(b) A tile can move from square A to square B if B is blank.
(c) A tile can move from square A to square B.
31
Generating admissible
heuristics from subproblems:
Pattern databases

Admissible heuristics can also be derived from the solution cost of a subproblem of a
given
The idea problem.
behind pattern databases is to store these exact solution costs for every possible
subproblem instance—in our example, every possible configuration of the four tiles and the
blank.
32
Generating admissible heuristics
from subproblems: Pattern
databases
Admissible heuristics can also be derived from the solution cost of a subproblem of a given
problem.
pattern databases
disjoint pattern databases

33
Learning heuristics from
experience
A heuristic function h(n) is supposed to estimate the cost of a solution beginning from the
state at node n.
How could an agent construct such a function?
Solution
1. To devise relaxed problems for which an optimal solution can be found easily.
2. To learn from experience. “Experience” here means solving lots of 8-puzzles, for instance.
Each optimal solution to an 8-puzzle problem provides examples from which h(n) can be
learned

34
Inductive learning methods work best when supplied with features of a state that
are
relevant to predicting the state’s value, rather than with just the raw state
description.
The feature
“number of misplaced tiles” might be helpful in predicting the actual distance of a state from
the goal.
Let’s call this feature x1(n).

take 100 randomly generated 8-puzzle configurations and gather statistics on their actual
solution costs.
We might find that when x1(n) is 5, the average solution cost is around 14, and so on.
Given these data, the value of x1 can be used to predict h(n).

Of course, we can use several features.

A second feature x2(n) might be “number of pairs of adjacent tiles that are not adjacent in the
goal state.” The constants c1 and c2 are adjusted to give the
best fitto
How should x1(n) and x2(n) be combined topredict
the actual data on solution costs.
h(n)?
A common approach
is to use a linear combination: 35
LOGICAL
AGENTS
1. Knowledge—based agents
2. The Wumpus world
3. Logic
4. Propositional logic
5. Reasoning patterns in Propositional Logic

we design agents that can form representations of a complex world, use a


process of inference to derive new representations about the world, and use
these new representations to deduce what to do.

36
Knowledge based Agents
function KB-AGENT( percept ) returns an action
knowledge base
persistent: KB , a knowledge base Sentences
t , a counter, initially 0, indicating time knowledge representation language
axiom
TELL(KB, MAKE-PERCEPT-SENTENCE( percept , t ))
action ← ASK(KB, MAKE-ACTION-
QUERY(t ))
TELL(KB, MAKE-ACTION-
SENTENCE(action, t ))
t ←t +1 Figure 7.1 A generic knowledge-based agent. Given a
percept, the agent adds the percept to its knowledge base,
return action asks the knowledge base for the best action, and tells the
knowledge base that it has in fact taken that action.

37
THE WUMPUS WORLD

38
The PEAS description
Performance measure: +1000 for climbing out of the cave with the gold, –1000 for falling
into a pit or being eaten by the wumpus, –1 for each action taken and –10 for using up the
arrow. The game ends either when the agent dies or when the agent climbs out of the cave.

Environment: A 4×4 grid of rooms. The agent always starts in the square labeled [1,1],
facing to the right. The locations of the gold and the wumpus are chosen randomly, with a
uniform distribution, from the squares other than the start square. In addition, each square
other than the start can be a pit, with probability 0.2.

Actuators: The agent can move Forward, TurnLeft by 90◦, or TurnRight by 90◦. The agent dies
a miserable death if it enters a square containing a pit or a live wumpus. (It is safe, albeit
smelly, to enter a square with a dead wumpus.) If an agent tries to move forward and bumps
into a wall, then the agent does not move. The action Grab can be used to pick up the gold if it
is in the same square as the agent. The action Shoot can
be used to fire an arrow in a straight line in the direction the agent is facing. The arrow
continues until it either hits (and hence kills) the wumpus or hits a wall. The agent has only
one arrow, so only the first Shoot action has any effect. Finally, the action Climb can be used
to climb out of the cave, but only from square [1,1].

39
Sensors: The agent has five sensors, each of which gives a single bit of information:
– In the square containing the wumpus and in the directly (not diagonally) adjacent squares,
the agent will perceive a Stench.
– In the squares directly adjacent to a pit, the agent will perceive a Breeze.
– In the square where the gold is, the agent will perceive a Glitter.
– When an agent walks into a wall, it will perceive a Bump.
– When the wumpus is killed, it emits a woeful Scream that can be perceived anywhere in the
cave.

The percepts will be given to the agent program 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 program will get
[Stench, Breeze, None, None, None].

40
41
42
LOGIC
The fundamental concepts of logical representation and reasoning.

• Knowledge bases consist of sentences.


• Sentences are expressed according to the syntax of the
representation language.
Example: “x + y = 4” is a well-formed sentence, whereas “x4y+ =” is not
• A logic must also define the semantics or meaning of sentences.
• The semantics defines the truth of each sentence with respect to each possible world
(model).
Example: the sentence “x + y =4” is true in a world where x is 2 and y is 2, but
false in a world where x is 1 and y is 1.

43
• The possible models are just all possible assignments of real numbers to the variables x
and y.
• Each such assignment fixes the truth of any sentence of arithmetic whose variables are x
and y.
• If a sentence α is true in model m, say that m satisfies α or sometimes m is a model of α.
• The notation: M(α) to mean the set of all models of α.
• Notion of truth involves the relation of logical entailment between sentences—the idea
that a sentence follows logically from another sentence.
Mathematical notation: α |= β (sentence α entails the sentence β.)
• The formal definition of entailment is this: α |= β if and only if, in every model in which
α is true, β is also true.
α |= β if and only if M(α) ⊆ M(β)
Note the direction of the ⊆ here: if α |= β, then α is a stronger assertion than β: it rules out
more possible worlds

44
45
Let us consider two possible conclusions:
α1 = “There is no pit in [1,2].”
α2 = “There is no pit in [2,2].”

By inspection, we see the following:


• In every model in which KB is true, α1 is also true.
Hence, KB |= α1: there is no pit in [1,2].
• In some models in which KB is true, α2 is false.
Hence, KB |= α2: the agent cannot conclude that there is no pit in [2,2].
Figure 7.5 is called model checking because it enumerates all possible models to
check that α is true in all models in which KB is true, that is, that M(KB) ⊆ M(α).
Formal notation:
If an inference algorithm i can derive α from KB, we write

which is pronounced “α is derived from KB by i” or “i derives α from KB.”

46
47
PROPOSITIONAL LOGIC: A VERY SIMPLE
LOGIC
• A simple but powerful logic called propositional logic
• The syntax of propositional logic and its semantics—the way in which the truth of sentences is determined.
• Entailment—the relation between a sentence and another sentence that follows from it
• How this leads to a simple algorithm for logical inference.

Syntax
The syntax of propositional logic defines the allowable sentences.
The atomic sentences consist of a single proposition symbol.

Two proposition symbols


True is the always-true proposition and False is the always-false proposition.

Complex sentences are constructed from simpler sentences,


using parentheses and logical connectives.
48
There are five connectives in common use:

1. ¬ (not)-negation
2. ∧ (and)-conjunction
3. ∨ (or)- disjunction
4. ⇒ (implies)-implication (premise and conclusion)
5. ⇔ (if and only if (alternate Symbol is ≡))-biconditional

49
50
Semantics
• The semantics defines the rules for determining the truth of a sentence with
respect to a particular model.
• In propositional logic, a model simply fixes the truth value—true or false—
for every proposition symbol.
For example,
o If the sentences in the knowledge base make use of the proposition symbols
P1,2, P2,2, and P3,1, then
o one possible model is
m1 = {P1,2 = false, P2,2 = false, P3,1 = true} .
• The semantics for propositional logic must specify how to compute the truth
value of any sentence, given a model.

51
Atomic sentences are easy:
• True is true in every model and False is false in every model.
• The truth value of every other proposition symbol must be specified
directly in the
model.
For example, in the model m1 given earlier, P1,2 is false.
For complex sentences, we have five rules, which hold for any
subsentences P and Q in any model m :
• ¬ P is true iff P is false in m.
• P ∧ Q is true iff both P and Q are true in m.
• P ∨ Q is true iff either P or Q is true in m.
• P ⇒ Q is true unless P is true and Q is false in m.
• P ⇔ Q is true iff P and Q are both true or both false in m.

52
53
A simple knowledge base
 To construct a knowledge base for the wumpus world.
 Focus first on the immutable aspects of the wumpus world
 We need the following symbols for each [x, y] location:
• Px,y is true if there is a pit in [x, y].
• Wx,y is true if there is a wumpus in [x, y], dead or alive.
• Bx,y is true if the agent perceives a breeze in [x, y].
• Sx,y is true if the agent perceives a stench in [x, y].

 We label each sentence Ri so that we can refer to them:


• 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:
R2 : B1,1 ⇔ (P1,2 ∨ P2,1)
R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1)
54
• The preceding sentences are true in all wumpus worlds.
• Include the breeze percepts for the first two squares visited in the
specific world the agent is in, leading up to the situation given in
Figure.

R4 : ¬ B1,1
R5 : B2,1

55
A simple inference procedure
• Our goal now is to decide whether KB |= α for some
sentence α.
• Our first algorithm for inference is a model-checking approach:
o enumerate the models, and
o check that α is true in every model in which KB is true.
• Models are assignments of true or false toevery proposition symbol.
Wumpus-world example:
• The relevant proposition symbols are B1,1, B2,1, P1,1, P1,2, P2,1, P2,2, and P3,1.
• there are 27 = 128 possible models
• In three of these, KB is true

56
57
A general algorithm for deciding entailment in propositional logic

function TT-ENTAILS?(KB , α) returns true or false


inputs: KB , the knowledge base, a sentence in propositional logic α,
the query, a sentence in propositional logic
symbols ← a list of the proposition symbols in KB and α
return TT-CHECK-ALL(KB , α, symbols , { })
function TT-CHECK-ALL(KB, α, symbols , model ) returns true or false
if EMPTY?(symbols) then
if PL-TRUE?(KB , model ) then return PL-TRUE?(α, model )//if a sentence holds within a model.
else return true // when KB is false, always return true
else do
P ← FIRST(symbols)
rest ← REST(symbols)
return (TT-CHECK-ALL(KB, α, rest , model ∪ {P = true}) and
TT-CHECK-ALL(KB , α, rest , model ∪ {P = false }))

58
Standard logical equivalences
The symbols α, β, and γ stand for arbitrary sentences of propositional logic.

(α ∧ β) ≡ (β ∧ α) commutativity of ∧
(α ∨ β) ≡ (β ∨ α) commutativity of ∨
((α ∧ β) ∧ γ) ≡ (α ∧ (β ∧ γ)) associativity of ∧
((α ∨ β) ∨ γ) ≡ (α ∨ (β ∨ γ))associativity of ∨
¬(¬α) ≡ α double-negation elimination
(α ⇒ β) ≡ (¬β ⇒ ¬α) contraposition
(α ⇒ β) ≡ (¬α ∨ β) implication elimination
(α ⇔ β) ≡ ((α ⇒ β) ∧ (β ⇒ α)) biconditional elimination
¬(α ∧ β) ≡ (¬α ∨ ¬β) De Morgan
¬(α ∨ β) ≡ (¬α ∧ ¬β) De Morgan
(α ∧ (β ∨ γ)) ≡ ((α ∧ β) ∨ (α ∧ γ)) distributivity of ∧ over ∨
(α ∨ (β ∧ γ)) ≡ ((α ∨ β) ∧ (α ∨ γ)) distributivity of ∨ over ∧

59
Reasoning patterns in Propositional Logic
(Propositional Theorem Proving)
Additional concepts related to entailment:
1. logical equivalence (α ≡ β): two sentences α and β are logically equivalent if they are true in the same set of
models.
two sentences α and β are equivalent only if each of them entails the other:
α ≡ β if and only if α |= β and β |= α .

2. Validity. A sentence is valid if it is true in all models. For example, the sentence P ∨ ¬P is valid. Valid
sentences are also known as tautologies—they are necessarily true.
For any sentences α and β, α |= β if and only if the sentence (α ⇒ β) is valid
if α |= β by checking that (α ⇒ β) is true in every model

3. The final concept we will need is satisfiability. A sentence is satisfiable if it is true in, or satisfied by, some
model.
For example, the knowledge base given earlier, (R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5), is satisfiable because there are three
models in which it is true.
• α |= β if and only if the sentence (α ∧ ¬β) is unsatisfiable (Validity and satisfiability are connected)
60
Inference and proofs
Inference rules that can be applied to derive a proof—a chain of conclusions that leads to the desired goal.

• The best-known rule is called Modus Ponens (Latin mode that affirms) and is written

if (WumpusAhead ∧ WumpusAlive) ⇒ Shoot and (WumpusAhead ∧ WumpusAlive) are given, then Shoot
Example:

can be inferred.
• And-Elimination, which says that, from a conjunction, any of the conjuncts can be inferred:

For example, from (WumpusAhead ∧ WumpusAlive), WumpusAlive can be inferred.

61
The equivalence for biconditional elimination yields the two inference rules

how these inference rules ad equivalences can be used in the wumpus world.

The knowledge base containing R1 through R5 and show how to prove ¬P1,2, that is, there is no pit in [1,2].
• First, apply biconditional elimination to R2 to obtain R1 : ¬ P1,1
R6 : (B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1) . R2 : B1,1 ⇔ (P1,2 ∨ P2,1)
• Then apply And-Elimination to R6 to obtain R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1)
R4 : ¬ B1,1
R7 : ((P1,2 ∨ P2,1) ⇒ B1,1) R5 : B2,1
• Logical equivalence for contrapositives gives
R8 : (¬B1,1 ⇒ ¬(P1,2 ∨ P2,1))
• Now apply Modus Ponens with R8 and the percept R4 (i.e., ¬B1,1), to obtain
R9 : ¬(P1,2 ∨ P2,1) .
• Finally, apply De Morgan’s rule, giving the conclusion
R10 : ¬P1,2 ∧ ¬P2,1 (neither [1,2] nor [2,1] contains a pit)

62
To define a proof problem as follows:
• INITIAL STATE: the initial knowledge base.
• ACTIONS: the set of actions consists of all the inference rules applied to all the
sentences that match the top half of the inference rule.
• RESULT: the result of an action is to add the sentence in the bottom half of the
inference rule.
• GOAL: the goal is a state that contains the sentence we are trying to prove.

63
Proof by resolution

A single inference rule, resolution, that yields a complete inference algorithm when
coupled with any complete search algorithm.

Consider the steps leading up to figure given below: the agent returns from [2,1] to [1,1]
and then goes to [1,2], where it perceives a stench, but no breeze.

Add the following facts to the knowledge base:


R11 : ¬B1,2

R12 : B1,2 ⇔ (P1,1 ∨ P2,2 ∨ P1,3)

64
Derive the absence of pits in [2,2] and [1,3]

Apply biconditional elimination to R3, followed by Modus Ponens


with R5, to obtain the fact that there is a pit in [1,1], [2,2], or [3,1]

The first application of the resolution rule: the literal ¬P2,2 in R13
resolves with the literal P2,2 in R15 to give the resolvent

Similarly, the literal ¬P1,1 in R1 resolves with the literal P1,1 in R16 to give

R16 and R17 are examples of the unit resolution inference rule

65
Unit resolution

where each l is a literal and li and m are complementary literals.


• The unit resolution rule takes a clause—a disjunction of literals—and a literal and
produces a new clause.
• A single literal can be viewed as a disjunction of one literal, also known as a unit clause.
The unit resolution rule can be generalized to the full resolution rule,
where li and mj are complementary literals

Example,

The removal of multiple copies of literals is called factoring


66
Conjunctive normal form
A sentence expressed as a conjunction of clauses is said to be in conjunctive normal
form or CNF.
Converting the sentence B1,1 ⇔ (P1,2 ∨ P2,1) into CNF.
The steps are as follows:
1. Eliminate ⇔, replacing α ⇔ β with (α ⇒ β) ∧ (β ⇒ α):
(B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1)
2. Eliminate ⇒, replacing α ⇒ β with ¬α ∨ β: • ¬(α ∧ β) ≡ (¬α ∨ ¬β) (De Morgan)
• ¬(¬α) ≡ α (double-negation elimination)

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬(P1,2 ∨ P2,1) ∨ B1,1)


• ¬(α ∨ β) ≡ (¬α ∧ ¬β) (De Morgan)

3. CNF requires ¬ to appear only in literals : (¬B1,1 ∨ P1,2 ∨ P2,1) ∧ ((¬P1,2 ∧ ¬P2,1) ∨ B1,1)
4. A sentence
. containing nested ∧ and ∨ operators applied to literals: apply the distributivity
law : (¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬P1,2 ∨ B1,1) ∧ (¬P2,1 ∨ B1,1) in CNF, as a conjunction of three clauses
67
A resolution algorithm

68
Apply the resolution procedure to a very simple inference in the wumpus world

KB = R2 ∧ R4 = (B1,1 ⇔ (P1,2 ∨ P2,1)) ∧ ¬B1,1

69
Forward and backward chaining

70
Thank you!

71

You might also like