Top Banner
Artificial Intelligence & Expert Systems Heuristic Search
67

Artificial Intelligence & Expert Systems

Jan 22, 2016

Download

Documents

Ally

Artificial Intelligence & Expert Systems. Heuristic Search. Heuristics. Heuristic means “rule of thumb”. To quote Judea Pearl, - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Artificial Intelligence  &   Expert Systems

Artificial Intelligence &

Expert Systems

Heuristic Search

Page 2: Artificial Intelligence  &   Expert Systems

Heuristics

Heuristic means “rule of thumb”. To quote Judea Pearl,

“Heuristics are criteria, methods or principles for deciding which among several alternative courses of action promises to be the most effective in order to achieve some goal”.

In heuristic search or informed search, heuristics are used to identify the most promising search path.

Page 3: Artificial Intelligence  &   Expert Systems

Heuristics . . .

“The study of the methods and rules of discovery and invention” defined by George Polya

Greek root word is euisco which means “I discover” Archimedes emerged and shouted “Eureka”

meaning “I have found it” In state space search, heuristics are formalized as

rules for choosing those branches in a state space that are most likely to lead to an acceptable solution

Page 4: Artificial Intelligence  &   Expert Systems

AI problem solvers employ heuristics in two basic situation

(1) A problem may not have an exact solution because of inherent ambiguities in the problem statement or available data.

A given set of symptoms may have several possible causes; doctors use heuristics to choose the most likely diagnosis and formulate a plan of treatment

Page 5: Artificial Intelligence  &   Expert Systems

(2) A problem may have an exact solution, but the computational cost of finding it may be prohibitive. In many problems (such as chess),state space growth is combinatorially explosive, with the number of possible states increasing exponentially or factorially with the depth of the search. In these cases, exhausive, bruce-force search techniques such as depth-first or breadth-first search may fail to find a solution within any practical length of time. Heuristics attack this complexity by guiding the search along the most “promising” path through the space. By eliminating unpromising states and their descendants from consideration, a heuristics algorithm can defeat this combinatorial explosion and find an acceptable solution.

Page 6: Artificial Intelligence  &   Expert Systems

Inherent limitation of heuristic search

Heuristic is only an informed guess of the next step to be taken in solving a problem.

Because heuristics use limited information, they are seldom able to predict the exact behavior of the state space farther along in the search.

a heuristic can lead a search algorithm to a sub-optimal solution or fail to find any solution at all.

Page 7: Artificial Intelligence  &   Expert Systems

Importance of heuristics

But heuristics and the design of algorithms to implement heuristic search have long been a core concern of artificial intelligence research

It is not feasible to examine every inference that can be made in a mathematics domain

heuristic search is often the only practical answer more recently, expert systems research has

affirmed the importance of heuristics as an essential component of problem solving

Page 8: Artificial Intelligence  &   Expert Systems

Algorithms for Heuristic Search

Heuristic Search

Hill Climbing Best first search A* Algo

Page 9: Artificial Intelligence  &   Expert Systems

Hill Climbing To implementation of heuristic search is through a

procedure called hill climbing Hill climbing strategies expand the current state in

the search and evaluate its children the best child is selected for further expansion;

neither its siblings nor its parent are retained search halts when it reaches a state that is better

than any of its children go uphill along the steepest possible path until it can

go no farther because it keeps no history, the algorithm cannot

recover from failures of its strategy

Page 10: Artificial Intelligence  &   Expert Systems

Hill Climbing . . .

• If the Node is better, only then you proceed to that Node.Algorithm:1. Start with current-state (cs) = initial state2. Until cs = goal-state or there is no change in the cs do:

(a) Get the successor of cs and use the EVALUATION FUNCTION to assign a score to each successor

(b) If one of the successor has a better score than cs then set the new state to be the successor with the

best score.

Page 11: Artificial Intelligence  &   Expert Systems

Example-1: Tic-Tac-Toe

In tic-tac-toe problem,

the combinatorics for exhaustive search are high but not insurmountable

total number of states that need to be considered in an exhaustive search at 9x8x7x….or 9!

Symmetry reduction decrease the search space Symmetry reductions on the second level further

reduce the number of paths through the space to 12x7!

Page 12: Artificial Intelligence  &   Expert Systems

First three levels of the tic-tac-toe state space reduced by symmetry.

Page 13: Artificial Intelligence  &   Expert Systems

The “most wins” heuristic applied to the first children in tic-tac-toe.

Page 14: Artificial Intelligence  &   Expert Systems

Which one to choose???

Heuristic: calculate winning lines and move to state with

most winning lines.

Page 15: Artificial Intelligence  &   Expert Systems

Heuristically reduced state space for tic-tac-toe.

Page 16: Artificial Intelligence  &   Expert Systems

Example-2:

Page 17: Artificial Intelligence  &   Expert Systems

Devise any heuristic to reach goal: Start : Library Goal : University

Page 18: Artificial Intelligence  &   Expert Systems

Evaluation Function: Distance between two place Adopt the one with minimum distance from goal

Probable route will be:

Library Hospital Newsagent

University

Page 19: Artificial Intelligence  &   Expert Systems

Suppose S2 < S1

Then what will happen?

The algorithm will always go to park from hospital instead of going to newsagent. The algorithm will get stuck here.

Page 20: Artificial Intelligence  &   Expert Systems

Drawback of Hill Climbing

Page 21: Artificial Intelligence  &   Expert Systems

Ridge = sequence of local maxima difficult for hill climbing to navigate

Plateaux = an area of the state space where the evaluation function is flat.

GETS STUCK 86% OF THE TIME.

Page 22: Artificial Intelligence  &   Expert Systems

Simulated Annealing

A method to get rid of the local minima/maxima problem.

It is an optimization method that employ certain techniques to take small steps in the direction indicated by the gradient, but occasionally large steps in the gradient direction / same other directional taken.

Page 23: Artificial Intelligence  &   Expert Systems

Best-First Search

A major problem of hill climbing strategies is their tendency to become stuck at local maxima

if they reach a state that has a better evaluation than any of its children, the algorithm halts

hill climbing can be used effectively if the evaluation function is sufficiently informative to avoid local maxima and infinite paths

heuristic search requires a more flexible algorithm: this is provided by best-first search, where, with a priority queue, recovery from local maxima is possible

Page 24: Artificial Intelligence  &   Expert Systems
Page 25: Artificial Intelligence  &   Expert Systems

Heuristic search of a hypothetical state space

Page 26: Artificial Intelligence  &   Expert Systems

A trace of the execution of best-first search

Page 27: Artificial Intelligence  &   Expert Systems

Heuristic search of a hypothetical state space with open and closed highlighted

Page 28: Artificial Intelligence  &   Expert Systems

The best-first search algorithm always select the most promising state on open for further expansion

as it is using a heuristic that may prove erroneous, it does not abandon all the other states but maintains then on open

In the event a heuristic leads the search down a path that proves incorrect, the algorithm will eventually retrieve some previously generated, “next best” state from open and shift its focus to another part of the space

In best-first search, as in depth-first and breadth-first search algorithms, the open list allows backtracking from paths that fail to produce a goal

Page 29: Artificial Intelligence  &   Expert Systems

Evaluation Function

1. Count the no. of tiles out of place in each state when compared with the goal.

Out of place tiles

2, 8, 1, 6

In place tiles

3, 4, 5, 7

2 8 3

1 6 4

7 5

1 2 3

8 4

7 6 5

Initial state

Goal

Page 30: Artificial Intelligence  &   Expert Systems
Page 31: Artificial Intelligence  &   Expert Systems

Heuristic Function f(n) = h(n)

Drawback:

The heuristic defined does not take into account the distance each tile has to be moved to bring it to the correct place.

Page 32: Artificial Intelligence  &   Expert Systems

Sum the no. of boxes the tile has to be moved to reach the goal

for example:

41

1

Total places to be moved = ‘2’

21

1

1

No. of places to be moved = ‘3’

Page 33: Artificial Intelligence  &   Expert Systems

2 8 3

1 6 4

7 5

Total tiles out of place = 5

Sum of distances out of place = 6

Tiles Distance

1 1

2 1

8 2

6 1

7 1 total: 6

Page 34: Artificial Intelligence  &   Expert Systems

Another ScenarioThe first picture shows the current state n, and the second picture the goal state. h(n) = 5 because the tiles 2, 8, 1, 6 and 7 are out of place.

Page 35: Artificial Intelligence  &   Expert Systems

Manhattan Distance Heuristic: Another heuristic for 8-puzzle is the Manhattan distance heuristic.

This heuristic sums the distance that the tiles are out of place.

The distance of a tile is measured by the sum of the differences in the x-positions and the y-positions.

For the above example, using the Manhattan distance heuristic,

h(n) = 1 + 1 + 0 + 0 + 0 + 1 + 1 + 2 = 6

Page 36: Artificial Intelligence  &   Expert Systems

3 5 6

1 4

2 8 7

Total tiles out of place = 7

Sum of distances

Tiles Distance

3 2

1 1

2 2

8 2

7 2

6 3

5 3 total: 15

Page 37: Artificial Intelligence  &   Expert Systems
Page 38: Artificial Intelligence  &   Expert Systems

Complete Heuristic function (sum of two functions)

f(n) = g(n) + h(n)

where h(n) = Sum of the distances

g(n) = tiles out of places

Anther Heuristic Could be:

g(n) = level of search

h(n) = number of tiles out of place

Page 39: Artificial Intelligence  &   Expert Systems
Page 40: Artificial Intelligence  &   Expert Systems
Page 41: Artificial Intelligence  &   Expert Systems

In general,

Best-first search is a general algorithm for heuristically search any state space graph (as were in the breadth-and depth-first algorithms)

It is equally appropriate data-and goal-driven searches and supports a variety of heuristic evaluation functions

Because of its generality, best-first search can be used with a variety of heuristics, ranging from subjective estimates of state’s “goodness” to sophisticated measure based on the probability of a state leading to a goal

Page 42: Artificial Intelligence  &   Expert Systems

Drawbacks with BFS

Problems with Best First Search It reduces the costs to the goal but

It is not optimal nor complete Uniform cost

Page 43: Artificial Intelligence  &   Expert Systems

Algorithm A

Consider the evaluation function

f(n) = g(n) + h(n)

wheren is any state encountered during the searchg(n) is the cost of n from the start stateh(n) is the heuristic estimate of the distance n to the goal

If this evaluation algorithm is used with the best_first_search algorithm, the result is called algorithm A.

Page 44: Artificial Intelligence  &   Expert Systems

Algorithm A*

If the heuristic function used with algorithm A is admissible, the result is called algorithm A* (pronounced A-star).

A heuristic is admissible if it never overestimates the cost to the goal.

The A* algorithm always finds the optimal solution path whenever a path from the start to a goal state exists.

Page 45: Artificial Intelligence  &   Expert Systems

Monotonicity

A heuristic function h is monotone if

1. For all states ni and nJ, where nJ is a descendant of ni,

h(ni) - h(nJ) cost (ni, nJ),

where cost (ni, nJ) is the actual cost (in number of moves) of going from state ni to nJ.

2. The heuristic evaluation of the goal state is zero, or h(Goal) = 0.

Page 46: Artificial Intelligence  &   Expert Systems

Informedness

For two A* heuristics h1 and h2, if

h1 (n) h2 (n), for all states n in the search space,

heuristic h2 is said to be more informed than h1.

Page 47: Artificial Intelligence  &   Expert Systems

Condition for Admissible Search

h(n) <= h*(n)

Estimated Heuristic Cost

Actual Heuristic Cost

This Condition Ensures Shortest Path

Page 48: Artificial Intelligence  &   Expert Systems

A* Search

Evaluation function:

f(n) = g(n) +h(n)

Path cost to node n + heuristic cost at n

Constraints:

h(n) <= h*(n) (Admissible)

g(n) >= g*(n) (Coverage)

Page 49: Artificial Intelligence  &   Expert Systems

Coverage: g(n) >= g*(n)

g(n)

g*(n)

Goal will never be reached

Page 50: Artificial Intelligence  &   Expert Systems

Example of A*

Path: (P1): Best First/Hill Climbing

ABDEF: Cost P1 = 14 (not optimal)

For A* algorithm

F(A)=0+10=10,

F(B)=2+8=10, f(C) = 2+9=11, Expand B

F(D)=(2+5)+6=13, f(C)=11, Expand C

F(G)=(2+3)+3=8, f(D)=13, Expand G

F(f)=(2+3+2)+0=7, GOAL achieved

Path ACGF: Cost P2=7 (Optimal)

Path Admissibility

Cost P2 < Cost P1 hence P2 is admissible Path

A:10

2 2

B:8 C:9

5 3

D:6 G:3

3

E:4 2

4

F:0

Page 51: Artificial Intelligence  &   Expert Systems

ExplanationFor A* algorithm Path (P2)

Now lets start from A, should we

move from A to B or A to C.

Lets check the path cost SAME,

So lets see the total cost

(fb=hb+gb=8+2=10)

(fc=hc+gb=9+2=11), hence moving through

B is better

Next move to D, total path cost to D is 2+5 = 7, and heuristic cost is 6, total is 7+6=13.

On the other side If you move through C to G, then the path cost is 2+3=5, and heuristic cost is 3, total = 3+5=8, which is much better than moving through state D. So now we choose to change path and move through G

A:10

2 2

B:8 C:9

5 3

D:6 G:3

3

E:4 2

4

F:0

Page 52: Artificial Intelligence  &   Expert Systems

Explanation

Now from G we move to the Goal node F

Total Path cost via G is 2+3+2=7

And Total Path cost via D is 2+5+3+4=14

Hence moving through G is much better will give the optimal path.

A:10

2 2

B:8 C:9

5 3

D:6 G:3

3

E:4 2

4

F:0

Page 53: Artificial Intelligence  &   Expert Systems

For A*never throw away For A*never throw away unexpanded nodes:unexpanded nodes:

Always compare paths through Always compare paths through expanded and unexpanded nodesexpanded and unexpanded nodes

Avoid expanding paths that are already expensive

Page 54: Artificial Intelligence  &   Expert Systems

A* search

Best-known form of best-first search. Idea: avoid expanding paths that are already

expensive. Evaluation function f(n)=g(n) + h(n)

g(n) the cost (so far) to reach the node. h(n) estimated cost to get from the node to the goal. f(n) estimated total cost of path through n to goal.

Page 55: Artificial Intelligence  &   Expert Systems

A* search

A* search uses an admissible heuristic A heuristic is admissible if it never overestimates

the cost to reach the goal Are optimistic

Formally:

1. h(n) <= h*(n) where h*(n) is the true cost from n

2. h(n) >= 0 so h(G)=0 for any goal G.

e.g. hSLD(n) never overestimates the actual road distance

Page 56: Artificial Intelligence  &   Expert Systems

Romania example

Page 57: Artificial Intelligence  &   Expert Systems

A* search example

Starting at Arad f(Arad) = g(Arad,Arad)+h(Arad)=0+366=366

Page 58: Artificial Intelligence  &   Expert Systems

A* search example

Expand Arad and determine f(n) for each node f(Sibiu)= g(Arad,Sibiu)+h(Sibiu)=140+253=393 f(Timisoara)=g(Arad,Timisoara)+h(Timisoara)=118+329=447 f(Zerind)=g(Arad,Zerind)+h(Zerind)=75+374=449

Best choice is Sibiu

Page 59: Artificial Intelligence  &   Expert Systems

A* search example

Expand Sibiu and determine f(n) for each node f(Arad)= g(Sibiu,Arad)+h(Arad)=280+366= 646 f(Fagaras)=g(Sibiu,Fagaras)+h(Fagaras)=239+179= 415 f(Oradea)=g(Sibiu,Oradea)+h(Oradea)=291+380= 671 f(Rimnicu Vilcea)=g(Sibiu,Rimnicu Vilcea)+

h(Rimnicu Vilcea)=220+192= 413 Best choice is Rimnicu Vilcea

Previous Pathsf(Timisoara)=c(Arad,Timisoara)+h(Timisoara)=118+329=

447f(Zerind)=c(Arad,Zerind)+h(Zerind)=75+374=449

Page 60: Artificial Intelligence  &   Expert Systems

A* search example

f(Timisoara)=g(Arad,Timisoara)+h(Timisoara)=118+329= 447 f(Zerind)=g(Arad,Zerind)+h(Zerind)=75+374= 449 f(Arad)=g(Sibiu,Arad)+h(Arad)=280+366= 646 f(Fagaras)=g(Sibiu,Fagaras)+h(Fagaras)=239+179= 415 f(Oradea)=g(Sibiu,Oradea)+h(Oradea)=291+380= 671

Expand Rimnicu Vilcea and determine f(n) for each node f(Craiova)=g(Rimnicu Vilcea, Craiova)+h(Craiova)=360+160= 526 f(Pitesti)=g(Rimnicu Vilcea, Pitesti)+h(Pitesti)=317+100= 417 f(Sibiu)=g(Rimnicu Vilcea,Sibiu)+h(Sibiu)=300+253= 553

Best choice is Fagaras

Page 61: Artificial Intelligence  &   Expert Systems

A* search example

f(Timisoara)=g(Arad,Timisoara)+h(Timisoara)=118+329= 447

f(Zerind)=g(Arad,Zerind)+h(Zerind)=75+374= 449 f(Arad)=g(Sibiu,Arad)+h(Arad)=280+366= 646 f(Fagaras)=g(Sibiu,Fagaras)+h(Fagaras)=239+179= 415 f(Oradea)=g(Sibiu,Oradea)+h(Oradea)=291+380= 671

Expand Rimnicu Vilcea and determine f(n) for each node f(Craiova)=g(Rimnicu Vilcea, Craiova)+h(Craiova)=360+160= 526 f(Pitesti)=g(Rimnicu Vilcea, Pitesti)+h(Pitesti)=317+100= 417417 f(Sibiu)=g(Rimnicu Vilcea,Sibiu)+h(Sibiu)=300+253= 553

Expand Fagaras and determine f(n) for each node f(Sibiu)=g(Fagaras, Sibiu)+h(Sibiu)=338+253= 591 f(Bucharest)=g(Fagaras,Bucharest)+h(Bucharest)=450+0= 450

Best choice is Pitesti !!!

Page 62: Artificial Intelligence  &   Expert Systems

A* search example

Expand Pitesti and determine f(n) for each node f(Bucharest)=g(Pitesti,Bucharest)+h(Bucharest)=418+0=418

Best choice is Bucharest !!! Optimal solution (only if h(n) is admissable)

Note values along optimal path !!

Page 63: Artificial Intelligence  &   Expert Systems

A* search, evaluation

Completeness: YES Since bands of increasing f are added Unless there are infinitely many nodes with f<f(G)

Page 64: Artificial Intelligence  &   Expert Systems

A* search, evaluation

Completeness: YES Time complexity:

Number of nodes expanded is still exponential in the length of the solution.

Page 65: Artificial Intelligence  &   Expert Systems

A* search, evaluation

Completeness: YES Time complexity: (exponential with path

length) Space complexity:

It keeps all generated nodes in memory Hence space is the major problem not time

Page 66: Artificial Intelligence  &   Expert Systems

Heuristic Search & Expert Systems

Expert Systems:

Human Extract Heuristic Develop Rules

Expert Knowledge

No certainties

are involved Knowledge Base

Manipulates the

knowledge to run

the system

Page 67: Artificial Intelligence  &   Expert Systems

Using Heuristics in Games Games have always been an important application area for

heuristic algorithms Two-person games are more complicated than simple puzzles

because of the existence of a “hostile” and essentially unpredictable opponent

consider games whose state space is small enough to be exhaustively searched; here the problem is systematically searching the space of possible moves and countermoves by the opponent

look at games in which it is either impossible or undesirable to exhaustively search the game graph

Because only a portion of the state space can be generated and searched, the game player must use heuristics to guide play along a path to a winning state