ch4 heuristic search
DESCRIPTION
Ch4 Heuristic Search. Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2011. George Polya defines heuristic as: “the study of the methods and rules of discovery and invention” This meaning can be traced to the term’s Greek root, the verb eurisco , which means “I discover” - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/1.jpg)
Ch4 Heuristic Search
Dr. Bernard Chen Ph.D.University of Central Arkansas
Spring 2011
![Page 2: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/2.jpg)
Introduction George Polya defines heuristic as:“the study of the methods and rules of discovery and
invention”
This meaning can be traced to the term’s Greek root, the verb eurisco, which means “I discover”
When Archimedes emerged from his famous bath clutching the golden crown, he shouted “Eureka!!”, meaning I have found it
IN AI, heuristics are formalized as Rules for choosing those branches in a state space that are most likely to lead to an acceptable problem solution
![Page 3: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/3.jpg)
Introduction AI problem solvers employ heuristics in
two basic situations:
A problem may not have an exact solution because of inherent ambiguities in the problem statement or available data
A problem may have an exact solution, but the computational cost of finding it may be prohibitive
For example…
![Page 4: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/4.jpg)
Introduction A problem may not have an exact
solution because of inherent ambiguities in the problem statement or available data
Medical diagnosis. Doctors use heuristic to choose the most likely diagnosis based on patient’s symptoms and description
Vision. Vision systems often use heuristics to select the most likely of several possible interpretations of a scene
![Page 5: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/5.jpg)
Introduction
A problem may have an exact solution, but the computational cost of finding it may be prohibitive
When brute force search techniques (BFS, DFS) may fail to find a solution within a reasonable amount of time
![Page 6: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/6.jpg)
Introduction Unfortunately, like all rules of discovery
and invention, heuristic are fallible
A heuristic is only an informed guess of the next step to take
A heuristic can lead a search to a suboptimal solution or fail to find any solution at all, because heuristic use limited information of the present situation
![Page 7: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/7.jpg)
Introduction Consider heuristic in the game of tic-tac-
toe A simple analysis put the total number of
states for 9! Symmetry reduction decrease the
search space Thus, there are not 9 but 3 initial moves:
to a corner to the center of a side to the center of the grid
![Page 8: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/8.jpg)
Introduction
![Page 9: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/9.jpg)
Introduction Use of symmetry on the second level
further reduces the number of path to 3* 12 * 7!
A simple heuristic, can almost eliminate search entirely: we may move to the state in which X has the most winning opportunity
In this case, X takes the center of the grid as the first step
![Page 10: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/10.jpg)
Introduction
![Page 11: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/11.jpg)
Introduction
![Page 12: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/12.jpg)
Introduction
The following topics in Heuristic includes: Hill-Climbing and Dynamic
Programming Best-first-search Using heuristic in Games
![Page 13: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/13.jpg)
Hill-Climbing Te simplest way to implement heuristic
search is through a procedure called hill-climbing
It expend the current state of the search and evaluate its children
The Best child is selected for further expansion
Neither it sibling nor its parent are retained
Tic-Tac-Toe we just saw is an example
![Page 14: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/14.jpg)
Hill-Climbing
Because it keeps no history, the algorithm cannot recover from failures of its strategy
A major problem of hill-climbing is their tendency to become stuck at local maxima
![Page 15: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/15.jpg)
Hill-Climbing
Hill Climbing is named for the strategy that might be used by an eager, but blind mountain climber:
Go uphill along the closest-to-the-top path until you can go no further up
![Page 16: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/16.jpg)
Hill-Climbing
![Page 17: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/17.jpg)
Hill-Climbing An example of local maximum in games
occurs in the 8-puzzle. Often, in order to move a particular tile
to its destination, other tiles already in their position need to move out
This is a necessary step but temporarily worsens the board state
Thus, hill climbing is not useful to the 8-puzzle game
![Page 18: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/18.jpg)
Dynamic Programming (DP) DP keeps track of and reuses of multiple
interacting and interrelated subproblems
An example might be reuse the subseries solutions within the solution of the Fibonacci series
The technique of subproblem caching for reuse is sometimes called memorizing partial subgoal solutions
![Page 19: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/19.jpg)
Dynamic Programming (DP) One of the most famous current
application in DP is “sequence alignment”
Suppose we want to find the best possible alignment for the characters in the strings BAADDCABDDA BBADCBA
![Page 20: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/20.jpg)
Dynamic Programming (DP)
One optimal alignment, among several possible, would be:
BAADDCABDDA BBA_DC_B_ _A
![Page 21: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/21.jpg)
Dynamic Programming (DP)
DP requires a data structure to keep track of the subproblem related to the state currently being processed
BAADDCABDDABBADCBA
![Page 22: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/22.jpg)
Dynamic Programming (DP) The array reflects the global alignment
success to that point in the matching process
There are 3 possible costs for creating the current state: Cost is 0 when characters are identical Cost is 1 when a character is shifted or inserted Cost is 2 when a character is shifted and
inserted
![Page 23: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/23.jpg)
Dynamic Programming (DP)
Start with a simple example BCA BA
We know the answer is BCA B_A
![Page 24: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/24.jpg)
Dynamic Programming (DP) The function is try to find the minimum
of (x-1,y),(x,y-1),(x-1,y-1) for (x,y)
If there’s a match for (x,y), add 0 to (x-1,y-1)
If there’s no match for (x,y), add 1 to (x-1,y),(x,y-1), as well as add 2 to (x-1,y-1)
![Page 25: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/25.jpg)
Dynamic Programming (DP)
_ B C A
_ 0 1 2 3
B 1 0 1 2A 2 1 2 1
![Page 26: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/26.jpg)
Dynamic Programming (DP)
Once the array is filled, we begin the backward stage of the algorithm that produces particular solutions
We select where the match came from
![Page 27: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/27.jpg)
Dynamic Programming (DP)
_ B C A
_ 0 1 2 3
B 1 0 1 2
A 2 1 2 1
_ B C A_ B _ A
![Page 28: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/28.jpg)
Dynamic Programming (DP)
_ B A A D D C A B D D A
_ 0 1 2 3 4 5 6 7 8 9 10 11
B 1 0 1 2 3 4 5 6 7 8 9 10
B 2 1 2 3 4 5 6 7 6 7 8 9
A 3 2 1 2 3 4 5 6 7 8 9 8
D 4 3 2 3 2 3 4 5 6 7 8 9
C 5 4 3 4 3 4 3 4 5 6 7 8
B 6 5 4 5 4 5 4 5 4 5 6 7
A 7 6 5 4 5 6 5 4 5 6 7 6
![Page 29: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/29.jpg)
Dynamic Programming (DP)
BAADDCABDDABBA_DC_B_ _A
![Page 30: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/30.jpg)
Dynamic Programming (DP)
_ G A A T T C A G T T A
_ 0 1 2 3 4 5 6 7 8 9 10 11
G 1 0 1 2 3 4 5 6 7 8 9 10
G 2 1 2 3 4 5 6 7 6 7 8 9
A 3 2 1 2 3 4 5 6 7 8 9 8
T 4 3 2 3 2 3 4 5 6 7 8 9
C 5 4 3 4 3 4 3 4 5 6 7 8
G 6 5 4 5 4 5 4 5 4 5 6 7
A 7 6 5 4 5 6 5 4 5 6 7 6
![Page 31: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/31.jpg)
Dynamic Programming (DP)
G A A T T C A G T T A G G A _ T C _ G _ _ A
![Page 32: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/32.jpg)
Introduction
The following topics in Heuristic includes: Hill-climbing and dynamic
programming Best-first-search Using heuristic in Games
![Page 33: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/33.jpg)
Best First Search
For the 8-puzzle game, we may add 3 different types of information into the code: The simplest heuristic counts the tiles
out of space in each state A “better” heuristic would sum all the
distances by which the tiles are out of space
![Page 34: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/34.jpg)
Best First Search Both of these heuristics
can be criticized for failing to acknowledge the difficulty of tile reversals
That is, if two tiles are next to each other and the goal requires their being in opposite locations, it takes several moves to put them back
2 1 3
8 4
7 6 5
![Page 35: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/35.jpg)
Best First Search
![Page 36: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/36.jpg)
Best First Search In previous figure, the sum of distance
heuristics does provide a much accurate estimate of the work
This example illustrates the difficulty of devising good heuristics
The design of good heuristic is an empirical problem; judgment and intuition help, but the final measure of a heuristic must be its actual performance
![Page 37: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/37.jpg)
Best First Search
If two states have the same or nearly the same heuristic evaluation, it is generally preferable to examine the state that is nearest to the root
So that we may obtain the shortest path to the goal
![Page 38: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/38.jpg)
Best First Search For 8-puzzle problem, let’s make our
evaluation function f to be :
f(n) = g(n) + h(n) g(n) means the actual length of path from n
to the root h(n) is a heuristic estimate (sum of distance
out of space) of the distance from state n to a goal
![Page 39: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/39.jpg)
Best First Search
![Page 40: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/40.jpg)
![Page 41: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/41.jpg)
Best First Search
In step 3, both e and f have a heuristic of 5
State e is examined first, producing h and i
Compare with all children, select the best move
![Page 42: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/42.jpg)
Best First Search Compare with BFS & DFS:
![Page 43: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/43.jpg)
Introduction
The following topics in Heuristic includes: Hill-climbing and dynamic
programming Best-first-search Using heuristic in Games
![Page 44: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/44.jpg)
Minimax Procedure on Exhaustively Search Graphs
Games have always been an important application area for heuristic algorithm
Two person games are more complicated than simple puzzle because of the existence of a “hotile” and unpredictable opponent
![Page 45: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/45.jpg)
Minimax Procedure on Exhaustively Search Graphs Let’s consider a variant of the game nim
To play this game, a number of tokens are placed on a table between the two players
At each move, the player must divide a pile of tokens into two nonempty piles of different sizes
Thus, 6 tokens my be divided into piles of 5&1 or 4&2 but not 3&3
The first player who can no longer make a move loses the game
![Page 46: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/46.jpg)
Minimax Procedure on Exhaustively Search Graphs
Let’s have fun ^^ Now we play a game with 7 cards
![Page 47: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/47.jpg)
Minimax Procedure on Exhaustively Search Graphs
State space for a variant of nim. Each state partitions the seven matches into one or more piles.
![Page 48: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/48.jpg)
Minimax Procedure on Exhaustively Search Graphs In playing games whose state space
may be exhaustively delineated, the primary difficulty is in accounting for the actions of the opponent
A simple way to handle this assumes that your opponent uses the same knowledge
Minimax searches the games space under this assumption
![Page 49: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/49.jpg)
Minimax Procedure on Exhaustively Search Graphs
The opponents in a game are referred to as MIN and MAX MAX represents the player trying to
win MIN is the opponent who attempts to
minimize MAX’s score
![Page 50: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/50.jpg)
Minimax Procedure on Exhaustively Search Graphs
We label each level in the search space according to whose move it is at the point in the game
Each leaf node is given a value of 1 or 0, depending on whether a win for MAX (1) or for MIN (0)
![Page 51: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/51.jpg)
Minimax Procedure on Exhaustively Search Graphs
![Page 52: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/52.jpg)
Minimax Procedure on Exhaustively Search Graphs
Minimax propagates these values up the graph through successive parent nodes according to the rule: If the parent is a MAX node, give it
the maximum value among its children
If the parent is a MIN node, give it the minimum value among its children
![Page 53: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/53.jpg)
Minimax Procedure on Exhaustively Search Graphs
![Page 54: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/54.jpg)
Minimax Procedure on Exhaustively Search Graphs
Because all of MIN’s possible first moves lead to nodes with a derived values of 1, the second player always can force the game to a win, regardless of MIN’s first move
![Page 55: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/55.jpg)
Minimax to Fixed Ply Depth
In applying minimax to more complicated games, it is seldom possible to expand the state space search graph out to the leaf node
Instead, the state space is searched to a predefined number of levels
This is called an n-ply look ahead
![Page 56: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/56.jpg)
Minimax to Fixed Ply Depth As the leaves of this subgraph is not
complete, it is not possible to give them win or loss
Instead, each node is given a value according to some heuristic evaluation In chess, you may consider the number of
pieces belonging to MAX and MIN A more sophisticated strategy might assign
different values to each piece
![Page 57: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/57.jpg)
Minimax to Fixed Ply Depth
Minimax propagates these values up the graph through successive parent nodes according to the rule: If the parent is a MAX node, give it
the maximum value among its children
If the parent is a MIN node, give it the minimum value among its children
![Page 58: Ch4 Heuristic Search](https://reader030.vdocuments.net/reader030/viewer/2022033100/56812bce550346895d9027a1/html5/thumbnails/58.jpg)
Minimax to Fixed Ply Depth