Академический Документы
Профессиональный Документы
Культура Документы
Ms Smita Selot
Contents
A framework for describing search methods is provided and several general purpose search techniques are discussed. All are varieties of Heuristic Search:
Generate and test Hill Climbing Best First Search (A*) Problem Reduction (AO*) Constraint Satisfaction Branch and bound Means-ends analysis
Heuristic
Is a technique that improves the search method Like our tour guides Improve the quality of search path Example general purpose heuristicnearest neighbourhood Applying it to Travelling salesman problem
Select a city arbitrarily Select the next city closest to current city and not visited yet Repeat step 2 till all cities have been visited
A 6 4 C
3 B 5 2 D 1
Next city it B as cost is minimum From B select D From D select C Finally A-B-D-C This executes in time proportional to N*N better than !N
A 3 4 B 5 C C 2 D 1 C 6 D
Heuristic
Word heuristic come from greek word heuriskein meaning to discover Heuristics is a technique that improves the efficiency of search process by sacrificing the claims of completeness Good heuristic leads in promising direction Bad heuristic will yield inefficient search path Heuristic function is a function that map from problem state descriptions to measure of desirability, represented as numbers They describe goodness of a state Heuristics are not always as general as TSP problem h=f(x,y) where f can be squaring, identity, function
Heuristics
Heuristics are important in real life problem solving process- why?
Rarely we look for optimum solutions
Good solutions do well People are satisfier rather than optimizers Seek solution which satisfy requirements and quit as they find one- example parking space
Approximation produced may not be very good in worst case. Worst case hardly occur in real time Analysing heuristic- leads to better understanding of the problem
Heuristic function
There are 2 ways in which domain specific , heuristic knowledge can be incorporated in rule based search procedure
In rule themselves, where rule depicts set of sensible moves instead of all moves A heuristic function that evaluates individual problem states and determine the degree of desirability
Problem state description Measure of desirability ( number)
Heuristic function
Can be simple or complex At times
higher values - good position Lower values good position
Objective of heuristic function : is to guide search process in most profitable direction by suggesting path to follow when more than one are available Good heuristic function less time in search Bad heuristic function will not improve the search Cost of computing heuristic overweighs the effort saved in search process There is trade-off between cost of evaluating hf and the saving in search time that function provides
Problem characteristics
Heuristics are applicable to variety of problems and effectiveness of heuristic depends on class of problem Before applying the heuristic we must analyse the problem under following heads
Is problem decomposable? Can solution step be ignored? Is problem universal predictable? Is good solution to the problem is obvious? Is desired solution a state or path to state? Is knowledge required to solve problem or constraint the search
Problem characteristics
Is problem decomposable?
Take two problems
Integration Block domain problem
Problem characteristics
Is the universe predictable?
8 puzzle can use planning to identify the exact solution Bridge exact planning not possible so navigate several plans and then choose Difference is due to certain outcome and uncertain outcome Hardest type of problem is one with uncertain outcome and irrecoverable
playing bridge controlling robot arm lawyer helping to defend client from murder charge
Problem characteristics
Is good solution to problem is obvious
Example problem using logic (FOPL) and TSP In logic one may ask question and interested in answer here optimum path does not matter In TSP best path matters Difference is any path solution or best path solution Best path problem is computationally harder to achieve
Problem classification
When actual problems are analysed , we find that there are several broad classes into which problem falls So classes can be associated with generic control strategy for solving the problem Example classification problem
Medical diagnosis ,fault diagnosis in vehicle
Problem classification
Various problem solving method No single way to solve all kind of problem Each problem may not require a complete new strategy Instead
Analyse the problem Sort the various problem solving method by kinds of problem which they solve We can solve the new problem
Production system
A good way to describe operations that can be performed in a search for solution to problem A production system consist of A set of rules One or more knowledge base A control strategy A rule applier
Can production system be represented by set of characteristics What relation exists between problem types and types of production system
backward reasoning
Final to initial moving right to left
Generate-and-Test
Algorithm:
1. Generate a possible solution. For some problems, this means generating a particular point in the problem space. For others it means generating a path from a start state 2. Test to see if this is actually a solution by comparing the chosen point or the endpoint of the chosen path to the set of acceptable goal states. 3. If a solution has been found, quit, Otherwise return to step 1.
Generate-and-Test
It is a depth first search procedure since complete solutions must be generated before they can be tested. In its most systematic form, it is simply an exhaustive search of the problem space. Operate by generating solutions randomly. Also called as British Museum algorithm If a sufficient number of monkeys were placed in front of a set of typewriters, and left alone long enough, then they would eventually produce all the works of Shakespeare. Dendral: which infers the struture of organic compounds using NMR spectrogram. It uses plan-generate-test.
Generate-and-Test
Problem
solution
valid solution
Generator
Tester
Rejected solution
Hill Climbing
Is a variant of generate-and test in which feedback from the test procedure is used to help the generator decide which direction to move in search space. The test function is augmented with a heuristic function that provides an estimate of how close a given state is to the goal state. Computation of heuristic function can be done with negligible amount of computation. Hill climbing is often used when a good heuristic function is available for evaluating states but when no other useful knowledge is available.
c.
If the SUCC is better than the current state, then set current state to SUCC,
: Hill-climbing
This simple policy has three well-known drawbacks:
(a)
1. Local Maxima: a local maximum as opposed to global maximum. 2. Plateaus: An area of the search space where evaluation function is flat, thus requiring random walk. 3. Ridge: Where there are steep slopes and the search direction is not towards the top but towards the side.
(b)
(c)
Figure 5.9 Local maxima, Plateaus and ridge situation for Hill Climbing
Hill-climbing
In each of the previous cases (local maxima, plateaus & ridge), the algorithm reaches a point at which no progress is being made. A solution is to do a random-restart hill-climbing - where random initial states are generated, running each until it halts or makes no discernible progress. The best result is then chosen.
Apply two or more rules before doing the testmoving in several direction at once .Good for ridges
OR-graph
It is sometimes important to search graphs so that duplicate paths will not be pursued. An algorithm to do this will operate by searching a directed graph in which each node represents a point in problem space. Each node will contain:
Description of problem state it represents Indication of how promising it is Parent link that points back to the best node from which it came List of nodes that were generated from it
OR-Graph
Parent link will make it possible to recover the path to the goal once the goal is found. The list of successors will make it possible, if a better path is found to an already existing node, to propagate the improvement down to its successors. This is called OR-graph, since each of its branches represents an alternative problem solving path
BFS
Step 1 A B Step 4 A B C D B Step 2 A B
3
Step 3 A C D
1 Step 5 A C D E 4 F 6
F 6
5 I
4 J
F 6 1
Implementation of OR graphs
We need two lists of nodes:
OPEN LIST
Nodes that have been generated and have had the heuristic function applied to them but which have not yet been examined. OPEN is actually a priority queue in which the elements with the highest priority are those with the most promising value of the heuristic function.
CLOSED LIST
Nodes that have already been examined. We need to keep these nodes in memory if we want to search a graph rather than a tree since whenever a new node is generated, we need to check whether it has been generated before.
BFS
Step 1 A B Step 4 A B C D B Step 2 A B
3
Step 3 A Close 5 D
3
1 Step 5 A C D
open
E 4 F 6
F 6
5 I
4 J
F 6 1
Algorithm: BFS
Given : s-starting state, n-any node, g- goal state, o-set of operators, c()-cost function
1. 2.
ii
=4
f2
8 5
=4
= 1 + 4 + 2 + 3 = 10
45
Heuristics: Example
8-puzzle: h(n) = tiles out of place
Goal state
1 2 3 8 6 7 5 4
h(n) = 3
1 8 7
2 6
3 4 5
Example - cont
1 2 3 8 6 7 5 4
h(n) = 3 h(n) = 2 h(n) = 4 h(n) = 3
1 8 7
3 6
1 2 3 8 6 4 7 5
1 2 8 6 3 7 5 4
1 2 3 8 6 7 5 4
h(n) = 3
h(n) = 3
h(n) = 2
h(n) = 4
1 8 7
3 6
1 2 3 8 6 4 7 5
h(n) = 3 h(n) = 1
1 2 8 6 3 7 5 4 1 2 3 8 6 4
1 2 8 6 7 5
A* Algorithm
BFS is a simplification of A* Algorithm Presented by Hart et al Algorithm uses:
f: Heuristic function that estimates the merits of each node we generate. This is sum of two components, g and h and f represents an estimate of the cost of getting from the initial state to a goal state along with the path that generated the current node. g : The function g is a measure of the cost of getting from initial state to the current node. h : The function h is an estimate of the additional cost of getting from the current node to a goal state. OPEN CLOSED
A* Algorithm
1. Start with OPEN containing only initial node. Set that nodes g value to 0, its h value to whatever it is, and its f value to h+0 or h. Set CLOSED to empty list.
Initialize open = {s} closed = { } g(s)=0 f(s)=h(s)
2.
Until a goal node is found, repeat the following procedure: (a)If there are no nodes on OPEN, report failure.
fail if open={ } terminate with failure
A* Algorithm
(b)Otherwise pick the node on OPEN with the lowest f value. Call it BESTNODE. Remove it from OPEN. Place it in CLOSED. Select Select minimum cost state n from OPEN Save n in CLOSE (c )See if the BESTNODE is a goal state. If so exit and report a solution. terminate if n G terminate with success and f(n)
A* algorithm
d)Otherwise, generate the successors of BESTNODE For each of the SUCCESSOR, do the following: expand: SUCC m of n if m ~ {open U close } set g(m) = g(n)+C(n,m) set f(m)=g(m)+h(m) Insert m in open set the link to parent node if m {open U close } set g(m)=min[g(m),g(n)+C(n,m)] set f(m)=g(m)+h(m) if f(m) has decreased and m {close } move it to open if f(m) has decreased and m {open} update the cost and change the link to parent node
Observations about A*
Role of g function: This lets us choose which node to expand next on the basis of not only of how good the node itself looks, but also on the basis of how good the path to the node was. h, the distance of a node to the goal. If h is a perfect estimator of h, then A* will converge immediately to the goal with no search.
Playing 8-Puzzle
4 2 1 7 8 6 3 4 5
2 1
8 6 7
3 4 5
2 1 7
8 6
3 4 5
2 1 7
8 6 5
3 4
Playing 8-Puzzle
4 2 1 7 6 8 3 4 5
2 7
8 1 6
3 4 5
2 1 7 8 6
3 4 5
2 1 7
8 4 6
3 5
6 2 7
8 1 6
3 4 5
2 7
8 1 6
3 4 5
2 1 8 7 6
3 4 5
2 1 7
3 8 6 4 5
Playing 8-Puzzle
5 1 7 2 8 6 3 4 5
1 7
2 8 6
3 4 5
1 2 8 7 6
3 4 5
1 7
2 8 6
3 4 5
When g(n) = 1, h(n) = 0 => Breadth First When g(n)=0 => Best First Search/A* If non-admissible heuristic
g(n) = 0, h(n) = 1/depth => depth first
Behavior of A* search Underestimation and overestimation Underestimation: If we can guarantee that h never over estimates actual value from current to goal, then A* algorithm is guaranteed to find an optimal path to a goal, if one exists. Consider the following example.
Overestimation:
Now consider another situation. We expand B to E, E to F and F to G for a solution path of length 4.But suppose that there a direct path from D to a solution giving a path of length 2. We will never find it because of overestimating h(D). We may find some other worse solution without ever expanding D. So by overestimating h, we can not be guaranteed to find the cheaper path solution.
(1+4)
(1+5) D
Properties of A*
A* generates an optimal solution if h(n) is an admissible heuristic and the search space is a tree: h(n) is admissible if it never overestimates the cost to reach the destination node A* generates an optimal solution if h(n) is a consistent heuristic and the search space is a graph: h(n) is consistent if for every node n and for every successor node n of n: h(n) c(n,n) + h(n) h(n)
n d c(n,n) n If h(n) is consistent then h(n) is admissible h(n)
Admissibility of A*
A search algorithm is admissible, if for any graph, it always terminates in an optimal path from initial state to goal state, if path exists. If heuristic function h is underestimate of actual value from current state to goal state, then the it is called admissible function. So, we can say that A* always terminates with the optimal path in case h(x) is an admissible heuristic function.
Monotonicity: A heuristic
function h is monotone if 1. states Xi and Xj such that Xj is successor of Xi h(Xi) h(Xj) cost (Xi, Xj) i.e., actual cost of going from Xi to Xj 2. h (goal) = 0
AND-OR graphs
AND-OR graph (or tree) is useful for representing the solution of problems that can be solved by decomposing them into a set of smaller problems, all of which must then be solved. One AND arc may point to any number of successor nodes, all of which must be solved in order for the arc to point to a solution.
Goal: Acquire TV Set
9 H 4 I
27 J 15 10
Problem Reduction
FUTILITY is chosen to correspond to a threshold such than any solution with a cost above it is too expensive to be practical, even if it could ever be found. Algorithm : Problem Reduction 1. Initialize the graph to the starting node. 2. Loop until the starting node is labeled SOLVED or until its cost goes above FUTILITY:
a.
b.
Problem reduction
c. Change the f estimate of the newly expanded node to reflect the new information provided by its successors. Propagate this change backward through the graph.
Note:This propagation of revised cost estimates back up the tree was not necessary in the BFS algorithm because only unexpanded nodes were examined. But now expanded nodes must be reexamined so that the best current path can be selected.
AO* algorithm
GRAPH consist of node representing initial state call this state as INIT
Let G={s}
Initialize S ={n} Select from S a node m (select a node possibly whose descendent occurs in G).Remove m from S If s={ } return Compute the cost of each arc emerging from m
If m is AND node with succ r1, r2, r3 ........... rk
Set h(m)= h(ri)+C(m,ri) Mark each succ of m If every succ is SOLVED , mark m as SOLVED
If cost of m has changed then change must be propagated , hence insert all ancestor of m in S for which m is marked successor
Some observations
Cost must be propagated to all path backwards . Hence all ancestor must be added to S- why? Problem may come if graph contain cycles At time longer path may be better than shorter path Disadvantage : No interaction amongst subgoals
Constraint Satisfaction
Constraint Satisfaction problems in AI have goal of discovering some problem state that satisfies a given set of constraints. Design tasks can be viewed as constraint satisfaction problems in which a design must be created within fixed limits on time, cost, and materials. Constraint satisfaction is a search procedure
that operates in a space of constraint sets. The initial state contains the constraints that are originally given in the problem description. A goal state is any state that has been constrained enough where enough must be defined for each problem. For example, in crypt arithmetic, enough means that each letter has been assigned a unique numeric value.
Constraint Satisfaction
Constraint Satisfaction is a two step process:
First constraints are discovered and propagated as far as possible throughout the system. Then if there still not a solution, search begins. A guess about something is made and added as a new constraint Propagation can then occur with this new constraint
Constraint propagation also occurs due to presence of inference rules that allow additional constraints to be added which are inferred form the given ones.
Set OPEN to set of all objects that must have values assigned to them in a complete solution. Then do until an inconsistency is detected or until OPEN is empty:
Select an object OB from OPEN. Strengthen as much as possible the set of constraints that apply to OB. If this set is different from the set that was assigned the last time OB was examined or if this is the first time OB has been examined, then add to OPEN all objects that share any constraints with OB. Remove OB from OPEN.
iii.
2.
If the union of the constraints discovered above defines a solution, then quit and report the solution.
1. 2.
The solution process proceeds in cycles. At each cycle, two significant things are done:
Constraints are propagated by using rules that correspond to the properties of arithmetic. A value is guessed for some letter whose value is not yet determined.
A few Heuristics can help to select the best guess to try first: If there is a letter that has only two possible values and other with six possible values, there is a better chance of guessing right on the first than on the second. Another useful Heuristic is that if there is a letter that participates in many constraints then it is a good idea to prefer it to a letter that participates in a few.
E=5 E=2
N=6; 6+R=5 or 15 R=8,9=> R=8
C2= 0
2+D =Y N+R = 10+E R =9 S =8
C2= 1
2+D = 10 +Y D = 8+Y D = 8 or 9 C2+N+R=14 E=4;Conflict
C2= 0
E=5
C2= 1
C2+N+R=15
D=8
Y= 0 ; Conflict
D=9
Y =1 ; Conflict
D+5=10+Y D=7;Y=2
Game Playing
Games as search problems Efforts in developing game playing algorithm
Charles Babbage and Bowden thought of extending analytical engine to play chess Shannon wrote a paper describing program that can play chess Alan Turing described chess playing algo, which could not be built Samuel succeeded in building first significant operational game playing program
checkers it could play and learn from mistake
Game Playing
Two main reason that game appears to be a good domain for machine intelligence: Provide a structured task in which it is easy to find success or failure Did not require large amount of knowledge Second reason is true only for small games (tic-tac-toe) Example Chess
Average branching factor = 35 On an average game one player can make 50 moves To examine a complete tree we would have to examine 35100 positions
Game Playing
Search Algorithm like generate and test
Generate: generates all possible moves Tester: Evaluates each move
In Chess all 35 moves are genearte and tester must evaluate each of them A better solution is to have
Improved generator which will produce only good path Improved test procedure so that best moves will be recognized first
Game Playing
Use Plausible move generator in which small number of promising move are generated With such a generator, test procedure can spend more time in evaluating these nodes. Search procedure will find a path till goal is reached
Game Playing
Goal: winning / loosing state Hence, like heuristics , use static evaluation function to find the best node Tic-tac-toe = number of winning moves for X- number of winning moves for O Chess: add number of blacks(w), add number of whites(W) quotient W/BTwo concern parameter in game search is depth and branching factor Even with plausible generator, in games like chess, it is not possible to search till goal is found.
MinMax Algorithm
Idealization and simplification:
Depth first depth limited search Two players Alternate moves
MAX player MIN player
Available information:
Perfect: chess, chequers, tic-tac-toe (no chance, same knowledge for the two players) Imperfect: poker, Stratego, bridge
Game representation
Searching a game tree using OR graph with two types of nodes
Min Node: select minimum cost successor Max Node: select maximum cost successor Terminal nodes: winning or loosing states Usually impossible to search upto terminal nodes
Max
Min
Can propagate W or L from bottom up to root node Difficult is state space is large Can be done for simple game like tic-tac-toe
Game playing-MinMax
Games like chess ;complete state space cannot be analyzed We expand the nodes to certain depth (ply) Apply heuristic function Knowledge of game is required to calculate the cost Apply minmax: its like look ahead strategy Also called zero sum game as
if A gets more B will get less If A win B will loose
Minimax
Minimax-value(n): utility for MAX of being in state n, assuming both players are playing optimally =
Utility(n), maxs Successors(n) Minimax-value(s), mins Successors(n) Minimax-value(s), if n is a terminal state if n is a MAX state if n is a MIN state
Example: tic-tac-toe
e (evaluation function integer) = number of available rows, columns, diagonals for MAX - number of available rows, columns, diagonals for MIN MAX plays with X and desires maximizing e. MIN plays with 0 and desires minimizing e. Symmetries are taken into account. A depth limit is used (2, in the example).
Example: tic-tac-toe
Example: tic-tac-toe
Example: tic-tac-toe
Uses plausible move generator to generate the promising successor(moves/nodes) Uses Static evaluation function with large values indicating good values for us +10 -------------------------- -10 Win for us win for opponent Value generated by static evaluation function is backed up to parents node Since static evaluation function is an estimate , it is better to carry search more than one ply in game tree look ahead
99 99
E (9)
F (-6)
G (0)
H (0)
I (-2)
(-4) (-3)
100
100
101
101
Minmax (position, depth, player ) { Step1:If DEEP-ENOUGH(position,player) then return structure VALUE=STATIC(position , player) PATH=nil Step2:Else { SUCCESSORS=MOVE_GEN(position,player) Step3: if (SUCCESSOR= empty) return structure // same as DEEP_ENOUGH Step4: if (! Empty(SUCCESSORSvalue )) { BEST_SCORE=min that STATIC can generate For every SUCC of SUCCESSOR 4(a) { RESULT_SUCC= MINMAX(SUCC, depth+1,OPPOSITE(player) 4(b) NEW-VALUE= - VALUE(RESULT_SUCC) 4(c) if NEW-VALUE > BEST_SCORE (i) { BSET_SCORE=NEW-VALUE (ii) BEST-PATH= SUCC + PATH(RESULT_SUCC) path from CURRENT to SUCC . }// end if }// end for
102
Step5: value=BEST_SCORE path=BEST_PATH return structure }// end if }// else }// minmax
Minmax(A,0,p1) 1 false 2 move-gen(A,p1) 3F 4 succ=(B,C,D) for B result_suc=minmax(B,1,p2) 1F 2 move-gen(b,p2) 3 F 4 succ=(E,F,G) for E result_succ=minmax(E,2,p1) 1. T val=static(E,p1)=9 path=nil return (path=nil,val(9)) newval=-9 best-score=-9 best-path=E return(BP,BS)
and uses the Utility function on them to discover that their values are 3, 12 and105 8.
Then it takes the minimum of these values, 3, and returns it as the backed-up value of node B. 106 Similar process for the other nodes. 106
107
107
108
108
Unfortunately, the exponent cant be 109 eliminated, but it can be cut in half. 109
Alpha-beta pruning
It is possible to compute the correct minimax decision without looking at every node in the game tree. Alpha-beta pruning allows to eliminate large parts of the tree from consideration, without influencing the final decision.
110
110
Alpha-beta pruning
The leaves below B have the values 3, 12 and 8. The value of B is exactly 3. It can be inferred that the value at the root is at least 3, because MAX has a choice worth 3.
111 111
Alpha-beta pruning
C, which is a MIN node, has a value of at most 2. But B is worth 3, so MAX would never choose C. Therefore, there is no point in looking at the other successors of C.
112 112
Alpha-beta pruning
D, which is a MIN node, is worth at most 14. This is still higher than MAXs best alternative (i.e., 3), so Ds other successors are explored.
113 113
Alpha-beta pruning
Alpha-beta pruning
The third successor is worth 2, so now D is worth exactly 2. MAXs decision at the root is to move to B, giving a value of 3
115 115
Alpha-beta pruning
Alpha-beta pruning gets its name from two parameters.
They describe bounds on the values that appear anywhere along the path under consideration:
= the value of the best (i.e., highest value) choice found so far along the path for MAX = the value of the best (i.e., lowest value) choice found so far along the path for MIN
116 116
Alpha-beta pruning
Alpha-beta search updates the values of and as it goes along. It prunes the remaining branches at a node (i.e., terminates the recursive call)
as soon as the value of the current node is known to be worse than the current or value for MAX or MIN, respectively.
117
117
Alpha-beta bounds
Alpha bound of j
Maximum current value of all max ancestor of j Exploration of a min node ,j, is stopped when its value equals or falls below alpha In min node we update beta
Beta bound of j
The minimum current of all MIN ancestor of j Exploration of a max node j is stopped when its value equals or exceeds beta In a MAX node we update beta
Alpha-beta pruning
MAX {, }
Vi
MIN
{, }
Return
and bounds are transmitted from parent to child in the order of node visit. The effectiveness of pruning highly depends on the order in which successors are examined.
{alpha = -, beta = +}
{3, +} {-, +}
{-, 3} {-, +}
D
3 {-, 3}
D A
{3, +}
{3, +}
{3, +}
D F G H
The I subtree can be pruned, because I is a min node and the value of v(K) = 0 is < = 3
{3, +}
{3, +} {3, +}
B F G H D J A
{3, +} {3, 5}
3
D
5 {3, +}
3 5
F
{3, 5}
5
A
4 4
3
D
The G subtree can be pruned, because G is a max node and the value of v(M) = 7 is > = 5
This idea can be extended to cut off path that are only slightly better than current path
Exploration of subtree is terminated that offers little possibility of improvement , hence called futility cut off
Additional refinements
Waiting for Quiescence
At times great difference in value is observed as we move from one level to another Our decision to change path should not occur on such short term measures
Secondary search
If total expansion was upto n level we can expand one node an extra level to reassure the path-singular extension
Book moves maintaining the catalogue of all moves (list of possible moves
Incorporates knowledge and search together
Summary
Four steps to design AI Problem solving: 1. Define the problem precisely. Specify the problem space, the operators for moving within the space, and the starting and goal state. 2. Analyze the problem to determine where it falls with respect to seven important issues. 3. Isolate and represent the task knowledge required 4. Choose problem solving technique and apply them to problem.
Summary
What the states in search spaces represent. Sometimes the states represent complete potential solutions. Sometimes they represent solutions that are partially specified. How, at each stage of the search process, a state is selected for expansion. How operators to be applied to that node are selected. Whether an optimal solution can be guaranteed. Whether a given state may end up being considered more than once. How many state descriptions must be maintained throughout the search process. Under what circumstances should a particular search path be abandoned.