3 heuristic serch

25
Artificial Intelligence (Heuristic Search) KR Chowdhary, Professor & Head Email: [email protected] Department of Computer Science and Engineering MBM Engineering College, Jodhpur kr chowdhary heuristic search 1/ 25

Upload: john-william

Post on 30-Dec-2015

25 views

Category:

Documents


0 download

DESCRIPTION

Heuristic Search

TRANSCRIPT

Page 1: 3 Heuristic Serch

Artificial Intelligence

(Heuristic Search)

KR Chowdhary, Professor & HeadEmail: [email protected]

Department of Computer Science and EngineeringMBM Engineering College, Jodhpur

kr chowdhary heuristic search 1/ 25

Page 2: 3 Heuristic Serch

Heuristic definition

Heuristic, adj.

1. Serving to promote discovery or learning; – used especially oftheories or paradigms which stimulate new ideas for discovering factsin experimental sciences.

2. Pertaining to or based on trial-and-error and experimentalmethods of learning and evaluation.

3. (Computers) Based on the use of an efficient trial-and errormethod to search a space of possible solutions to a problem, or tofind an acceptable approximate solution, when an exact algorithmicmethod is unavailable or too time-consuming.

Heuristic, n.

A theory or approach which serves to promote discovery or learningby encouraging experimentation.

kr chowdhary heuristic search 2/ 25

Page 3: 3 Heuristic Serch

Heuristic Search Techniques

Direct techniques (blind search) are not always possible (they requiretoo much time or memory).

Heuristic techniques can be effective if applied correctly on the rightkinds of tasks.

Typically require domain specific information.

Figure: Initial and final states of 8-puzzle game

kr chowdhary heuristic search 3/ 25

Page 4: 3 Heuristic Serch

Heuristic Search Techniques

8 Puzzle Heuristics:

- Blind search techniques used an arbitrary ordering (no priority) ofoperations.

- Heuristic search techniques make use of domain specific information- a heuristic.

- What heurisitic(s) can we use to decide which 8-puzzle move is“best”(worth considering first).

Figure: Heuristic search.

kr chowdhary heuristic search 4/ 25

Page 5: 3 Heuristic Serch

8-puzzle Heuristic

Heuristic techniques use a heuristic function, which when applied ona state as argument, return a value indicting how close this state isto the goal.

For now - we just want to establish some ordering to the possiblemoves (the values of our heuristic does not matter as long as itranks the moves).

Later - we will worry about the actual values returned by theheuristic function.

Number of tiles in the correct position.

- The higher the number the better.

- Easy to compute (fast and takes little memory).

- Probably the simplest possible heuristic.

kr chowdhary heuristic search 5/ 25

Page 6: 3 Heuristic Serch

8-puzzle Heuristic: another approach

Number of tiles in the incorrect position.

- This can also be considered a lower bound on the number of movesfrom a solution!

- The “best”move is the one with the lowest number returned by theheuristic.

- Is this heuristic more than a heuristic (is it always correct?).

- Given any two states, does it always order them properly withrespect to the minimum number of moves away from a solution?

kr chowdhary heuristic search 6/ 25

Page 7: 3 Heuristic Serch

8-puzzle Heuristic: another approach

Count how far away (how many tile movements) each tile is fromit’s correct position.

Sum up this count over all the tiles.

This is another estimate on the number of moves away from asolution.

Figure: Heuristic search.

kr chowdhary heuristic search 7/ 25

Page 8: 3 Heuristic Serch

Heuristic search techniques

There are a variety of search techniques that rely on the estimateprovided by a function.

In all cases - the quality (accuracy) of the heuristic is important inreal-life application of the technique!

Generate-and-test:

Very simple strategy - just keep guessing.

- do while goal not accomplished

- generate a possible solution

- test solution to see if it is a goal

Heuristics may be used to determine the specific rules for solutiongeneration.

kr chowdhary heuristic search 8/ 25

Page 9: 3 Heuristic Serch

Heuristic search techniques

Example - Traveling Salesman Problem (TSP)

Traveler needs to visit n cities.

Know the distance between each pair of cities.

Want to know the shortest route that visits all the cities once.

n=80 will take millions of years to solve exhaustively!

Figure: TSP

kr chowdhary heuristic search 9/ 25

Page 10: 3 Heuristic Serch

TSP

Figure: TSP

kr chowdhary heuristic search 10/ 25

Page 11: 3 Heuristic Serch

TSP

Hill Climbing:

Variation on generate-and-test:

- generation of next state depends on feedback from the testprocedure.

- Test now includes a heuristic function that provides a guess as tohow good each possible state is.

- There are a number of ways to use the information returned by thetest procedure.

Simple Hill Climbing:

- Use heuristic to move only to states that are better than the currentstate.

- Always move to better state when possible.

- The process ends when all operators have been applied and none ofthe resulting states are better than the current state.

kr chowdhary heuristic search 11/ 25

Page 12: 3 Heuristic Serch

Hill climbing

Potential Problems with Simple Hill Climbing:- Will terminate when at local optimum.- The order of application of operators can make a big difference.- Cannot see past a single move in the state space.

Figure: Hill Climbing

Simple Hill Climbing Example:- TSP - define state space as the set of all possible tours.- Operators exchange the position of adjacent cities within the currenttour.

- Heuristic function is the length of a tour.

kr chowdhary heuristic search 12/ 25

Page 13: 3 Heuristic Serch

Hill climbing

Hill climbing:

Figure: Hill Climbing

kr chowdhary heuristic search 13/ 25

Page 14: 3 Heuristic Serch

Hill climbing

Steepest-Ascent Hill Climbing

- A variation on simple hill climbing.

- Instead of moving to the first state that is better, move to the bestpossible state that is one move away.

- The order of operators does not matter.

- Not just climbing to a better state, climbing up the steepest slope.

kr chowdhary heuristic search 14/ 25

Page 15: 3 Heuristic Serch

Hill Climbing Termination

- Local Optimum: all neighboring states are worse or the same.

- Plateau - all neighboring states are the same as the current state.

- Ridge - local optimum that is caused by inability to apply 2operators at once.

Heuristic Dependence

- Hill climbing is based on the value assigned to states by the heuristicfunction.

- The heuristic used by a hill climbing algorithm does not need to be astatic function of a single state.

- The heuristic can look ahead many states, or can use other means toarrive at a value for a state.

kr chowdhary heuristic search 15/ 25

Page 16: 3 Heuristic Serch

Best-First Search

Combines the advantages of Breadth-First and Depth-First searches.

- DFS: follows a single path, do not need to generate all competingpaths.

- BFS: does not get caught in loops or dead-end-paths.

Best First Search: explore the most promising path seen so far.

While goal not reached:

1. Generate all potential successor states and add to a list of states.

2. Pick the best state in the list and go to it.

Similar to steepest-ascent, but do not throw away states that are notchosen.

kr chowdhary heuristic search 16/ 25

Page 17: 3 Heuristic Serch

Best-First Search

procedure best_first_search {

open := [Start]; % Initialize

closed := [];

while open != [] do { % While states remain

remove the leftmost state from open, call it X;

if X = goal then return path from Start to X;

else {

generate children of X;

for each child of X do

case {

the child is not on open or closed: {

assign the child a heuristic value;

add the child to open;

}

the child is already on open: {

if this child was reached by a shorter path

then give the state on open the shorter path

}

kr chowdhary heuristic search 17/ 25

Page 18: 3 Heuristic Serch

Best-First Search

the child is already on closed: {

if this child was reached by a shorter path {

then remove the state from closed;

add this child to open;

}

}

} % cases

put X on closed;

re-order states on open by heuristic merit (best leftmost)

} % else

} % while

return failure % open is empty

} % best_first

kr chowdhary heuristic search 18/ 25

Page 19: 3 Heuristic Serch

Simulated Annealing

Based on physical process of annealing a metal to get the best(minimal energy) state.

Hill climbing with a twist:

- allow some moves downhill (to worse states)

- start out allowing large downhill moves (to much worse states) andgradually allow only small downhill moves.

The search initially jumps around a lot, exploring many regions ofthe state space.

The jumping is gradually reduced and the search becomes a simplehill climb (search for local optimum).

Figure: Simulated Anealing

kr chowdhary heuristic search 19/ 25

Page 20: 3 Heuristic Serch

A* Algorithm (a sure test topic)

The A* algorithm uses a modified evaluation function and aBest-First search.

A* minimizes the total path cost.

Under the right conditions A* provides the cheapest cost solution inthe optimal time!

A* evaluation function

- The evaluation function f is an estimate of the value of a node x

given by:

f (x) = g(x)+h′(x)

g(x) is the cost to get from the start state to state x .

h′(x) is the estimated cost to get from state x to the goal state (theheuristic).

kr chowdhary heuristic search 20/ 25

Page 21: 3 Heuristic Serch

A* Algorithm (a sure test topic) contd..

Modified State Evaluation:

Value of each state is a combination of:

- the cost of the path to the state

- estimated cost of reaching a goal from the state.

The idea is to use the path to a state to determine (partially) therank of the state when compared to other states.

This does not make sense for DFS or BFS, but is useful forBest-First Search.

kr chowdhary heuristic search 21/ 25

Page 22: 3 Heuristic Serch

A* Algorithm

The general idea is:

- Best First Search with the modified evaluation function.

- h’(x) is an estimate of the number of steps from state x to a goalstate.

- loops are avoided - we do not expand the same state twice.

- Information about the path to the goal state is retained.

A* Algorithm

1. Create a priority queue of search nodes (initially the start state).Priority is determined by the function f

2. While queue not empty and goal not found:

get best state x from the queue.

If x is not goal state:

generate all possible children of x (and save path information witheach node).

Apply f to each new node and add to queue.

Remove duplicates from queue (using f to pick the best).

kr chowdhary heuristic search 22/ 25

Page 23: 3 Heuristic Serch

A* Algorithm

Figure: Example - Maze

kr chowdhary heuristic search 23/ 25

Page 24: 3 Heuristic Serch

A* Algorithm

Figure: Example - Maze

kr chowdhary heuristic search 24/ 25

Page 25: 3 Heuristic Serch

Merits and demerits of Astar

merits:

- A* is guaranteed to terminate.

demerits:

- A* can use lot of memory. in principle O(n), where n is total countof states.

- For really big search spaces, A* will run put of memory.

kr chowdhary heuristic search 25/ 25