Informed Search Methods

51
Informed Search Methods Artificial Intelligence Second Term Fourth Year (08 CS)

description

Informed Search Methods. Artificial Intelligence Second Term Fourth Year (08 CS). Heuristic. Origin: from Greek Word ‘ heuriskein ’, means, “to discover”. Webster’s New World Dictionary defines Heuristic as, “helping to discover or learn” As an adjective, means, serving to discover - PowerPoint PPT Presentation

Transcript of Informed Search Methods

Page 1: Informed Search Methods

Informed Search Methods

Artificial IntelligenceSecond Term Fourth Year (08 CS)

Page 2: Informed Search Methods

Heuristic • Origin: from Greek Word ‘heuriskein’, means, “to discover”.• Webster’s New World Dictionary defines Heuristic as, “helping

to discover or learn”• As an adjective, means, serving to discover• As noun, a heuristic is an aid to discovery.

A heuristic is a method to help solve a problem, commonly informal. It is particularly used for a method that often rapidly leads to a solution that is usually reasonably close to the best possible answer.

Heuristics are "rules of thumb", educated guesses, intuitive judgments or simply common sense.

A heuristic contributes to the reduction of search in a problem-solving activity.

Page 3: Informed Search Methods

Heuristic Search• Uses domain-dependent (heuristic) information in order to search

the space more efficiently.

Ways of using heuristic information:

• Deciding which node to expand next, instead of doing the

expansion in a strictly breadth-first or depth-first order;

• In the course of expanding a node, deciding which successor or

successors to generate, instead of blindly generating all possible

successors at one time;

• Deciding that certain nodes should be discarded, or pruned, from

the search space.

Page 4: Informed Search Methods

Heuristic Search

• A moment's reflection will show ourselves constantly using heuristics in the course of our everyday lives.

• If the sky is grey we conclude that it would be better to put on a coat before going out.

• We book our holidays in August because that is when the weather is best.

Page 5: Informed Search Methods

Heuristic Function

• It is a function that maps from problem state description to

measure of desirability, usually represented as number.

• Which aspects of the problem state are considered, how

those aspects are evaluated, and the weights given to

individual aspects are chosen in such a way that the value

of the heuristic function at a given node in the search

process gives as good an estimate as possible of whether

that node is on the desired path.

Page 6: Informed Search Methods

Major Benefits of Heuristics

1. Heuristic approaches have an inherent flexibility, which allows them to be used on ill-structured and complex problems.

2. These methods by design may be simpler for the decision maker to understand, especially when it is composed of qualitative analysis. Thus chances are much higher for implementing proposed solution.

3. These methods may be used as part of an iterative procedure that guarantees the finding of an optimal solution.

Page 7: Informed Search Methods

Major Disadvantages and Limitations of Heuristics

• The inherent flexibility of heuristic methods can lead to misleading or even fraudulent manipulations and solutions.

• Certain heuristics may contradict others that are applied to the same problem, which generates confusion and lack of trust in heuristic methods.

• Heuristics are not as general as algorithms;

Page 8: Informed Search Methods

Generate and Test• 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.

• 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.

• If a solution has been found, Quit, otherwise return to step1.

Page 9: Informed Search Methods

Best First Search• Depth first search is good because is allows a solution

to be found without all competing branches to be expanded.

• Breadth first search is good because it does not get trapped on dead-end paths.

• Best First Search combines the advantages of the two.• At each step of the best first search process, we select

the most promising of the nodes we have generated so far.

• This is done by applying an appropriate heuristic function to each of them.

Page 10: Informed Search Methods

Best First Search: Algorithm1. Start with OPEN containing just the initial state.2. Until a goal is found or there are no nodes left on

OPEN do:a) Pick the best node on OPENb) Generate its successors.c) For each successor do:

i. If it has not been generated before, evaluate it, add it to OPEN, and record its parent.

ii. If it has been generated before, change the parent if this new path is better than the previous one. In that case, update the cost of getting to this node and to any successors that this node may already have.

Page 11: Informed Search Methods

Best First Search: Example 1

A

B C D

E FG H

I J

3 1 5

6 5 4 6

2 1

A

DB

E

J

An OR Graph

Page 12: Informed Search Methods

Best First Search: Example 2

A

B C D

I

Q

E F

M O

4 6 4

5 6 4 6

7

1

A

B C

G H

K L

S T

N P

J

R

3

2 3 5 7

6

H 4

4

Note: P is the goal

4 8

H.W: Repeat the same example when T is the goal.

Open closed

Page 13: Informed Search Methods

Greedy Best First Search• This is like DFS, but picks the path that gets you closest

to the goal.• Needs a measure of distance from the goal.

h(n) = estimated cost of cheapest path from n to goal. h(n) is a heuristic.

• Analysis– Greed tends to work quite well (despite being one of the sins)– But, it does not always find the shortest path.– Susceptible to false starts.– May go down an infinite path with no way to reach goal.– The algorithm is incomplete without cycle checking. The

algorithm is also not optimal .

Page 14: Informed Search Methods

Greedy Best Fit Search

StartH = 1

Ah = 10

Bh = 20

Ch = 8

Dh = 7

Eh = 5

Fh = 20

Gh = 12

Goalh = 0

Starth = 1

Ah = 10

Dh = 7

Eh = 5

Goalh = 0

The path from start to goal is: Start A D E Goal.

Page 15: Informed Search Methods

The A* Search• A search algorithm to find the shortest path

through a search space to a goal state using a heuristic.f(n) = g(n) + h(n)

• f(n) - function that gives an evaluation of the state

• g(n) - the cost of getting from the initial state to the current state

• h(n) - the cost of getting from the current state to a goal state

Page 16: Informed Search Methods

E

C B9 + 1 = 106 + 2 = 87 + 3 = 10

A

F

D

B F6+5=11 8+2=10 9+4=13 6+2=8 4+5=9 E

EG A 8B 9C 6D 7E 5F 2G 0Distance todestination

D

Page 17: Informed Search Methods

A* Search: An Example

Distance Travelled = gDistance to be covered = hf = g + hA 8B 9C 6D 7E 5F 2G 0Distance todestination

Page 18: Informed Search Methods

An 8-Puzzle game

2 8 31 6 47 5

Start State 1 2 38 47 6 5

Goal

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

g(n) = actual distance from n to the start state.

h(n) = number of tiles out of place.

Page 19: Informed Search Methods

2 8 31 6 47 5

2 8 31 6 4

7 5

2 8 31 47 6 5

2 8 31 6 47 5

2 8 31 4

7 6 5

2 31 8 47 6 5

2 8 31 47 6 5

2 8 37 1 4

6 5

2 31 8 47 6 5

2 31 8 47 6 5

8 32 1 47 6 5

1 2 38 4

7 6 5 1 2 38 47 6 5

1 2 37 8 4

6 5

State Af(A) = 4

State Bf(B) = 1+5 = 6

State Cf(C) = 1+3 = 4

State Df(D) = 1+5 = 6

State Ef(E) = 2+3 = 5

State Ff(F) = 2+3 = 5

State Gf(G) = 2+4 = 6

State Hf(H) = 3+3 = 6

State If(I) = 3+4 = 7

State Jf(J) = 3+2 = 5

State Kf(K) = 3+4=7

State Lf(L) = 4+1 = 5State M

f(M) = 5+0 = 5

State Nf(N) = 5+2 = 7

Page 20: Informed Search Methods

Hill Climbing• Searching for a goal state = Climbing to the top

of a hill

• Generate-and-test + direction to move.

• Heuristic function to estimate how close a given state is to a goal state.

Page 21: Informed Search Methods

Simple Hill ClimbingAlgorithm

1. Evaluate the initial state.

2. Loop until a solution is found or there are no new operators left to be applied:- Select and apply a new operator- Evaluate the new state:goal quitbetter than current state new current state

Page 22: Informed Search Methods

Simple Hill ClimbingEvaluation function as a way to inject task

specific knowledge into the control process.

Page 23: Informed Search Methods

Steepest-Ascent Hill Climbing (Gradient Search)

• Considers all the moves from the current

state.

• Selects the best one as the next state.

Page 24: Informed Search Methods

Steepest-Ascent Hill Climbing (Gradient Search)

Algorithm1. Evaluate the initial state.

2. Loop until a solution is found or a complete iteration produces no change to current state:- SUCC = a state such that any possible successor of the current state will be better than SUCC (the worst state). - For each operator that applies to the current state, evaluate the new state:goal quitbetter than SUCC set SUCC to this state - SUCC is better than the current state set the current state to SUCC.

Page 25: Informed Search Methods

Hill Climbing: DisadvantagesLocal MaximumA state that is better than all of its neighbours,

but not better than some other states far away.

Page 26: Informed Search Methods

Hill Climbing: DisadvantagesPlateauA flat area of the search space in which all

neighbouring states have the same value.

Page 27: Informed Search Methods

Hill Climbing: DisadvantagesRidgeThe orientation of the high region, compared to

the set of available moves, makes it impossible to climb up.

However, two moves executed serially may increase the height.

Page 28: Informed Search Methods

Hill Climbing: Disadvantages

Ways Out

• Backtrack to some earlier node and try going in a different direction.

• Make a big jump to try to get in a new section.

• Moving in several directions at once.

Page 29: Informed Search Methods

Hill Climbing: Disadvantages

• Hill climbing is a local method: Decides what to do next by looking only at the “immediate” consequences of its choices.

• Global information might be encoded in heuristic functions.

Page 30: Informed Search Methods

Hill Climbing: Example 1

A

B C D

E

I

F G H

J

8

4

2

13

3

11

7 5

1 Goal

A

B

E

I

D

HG

J

Page 31: Informed Search Methods

Hill Climbing: Example 2

Page 32: Informed Search Methods

Simulated Anealing Annealing refers to a physical process that proceeds as follows:

• A solid in a heat bath is heated by raising the temperature to a maximum value at which all particles of the solid arrange themselves randomly in the liquid phase.

• Then the temperature of the heat bath is lowered, pertaining all particles of the solid arrange themselves in the low energy ground state of a corresponding lattice.

It is presumed that the maximum temperature in phase 1 is sufficiently high, and the cooling in phase 2 is carried-out sufficiently slowly. However, if the cooling is too rapid, that is if the solid is not allowed enough time to reach thermal equilibrium at each temperature value – the resulting crystal will have many defects.

Page 33: Informed Search Methods

Simulated Anealing in AI

Idea: escape local maxima by allowing some "bad" moves but gradually decrease their frequency.

• Picks random moves• Keeps executing the move if the situation is actually

improved; otherwise, makes the move of a probability less than 1

• Number of cycles in the search is determined according to probability

• The search behaves like hill-climbing when approaching the end

Page 34: Informed Search Methods

Problem Reduction: AND-OR GRAPHS• AND-OR Graph 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.

• This decomposition or reduction generates arcs that we call AND arcs. 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.

• AND arcs are represented by line connecting all the components or states.

• In order to find solutions in an AND-OR graph, we need an algorithm

similar to best first search but with the ability to handle the AND arcs

appropriately.•

Page 35: Informed Search Methods

Areas of Usage:

• Route finding• Design• Symbolic integration• Game playing• Theorem proving

P

P3P2P1Q3Q2Q1

Q

a)To solve P, solve any one of P1 or P2 or P3

b) To solve Q, solve all Q1, Q2 and Q3

OR and AND Relations

OR Graph AND Graph

Page 36: Informed Search Methods

AND-OR Graphs: Example

1

1 11

3

2

2 36

a

d

cb

e

i

gf

ha

d

b

e

h

1

1

6

1

Cost = 9

(ii)

a

c

i

gf

h Cost = 8

(iii)

(i)

Achieve goal h via node b.Achieve the goal h via node c.

Page 37: Informed Search Methods

Route Finding Example:Finding a route from a to z in a road mapTo find a path between a and z, find either(1) a path from a to z via f, or(2) a path from a to z via g.

d

b

a

c

e

f

g

j

i

k

h

z

2 3

2

13

2

2

2

2

1

4

3

3

3

1

5

RIVER

3

a-z

a-z via f

a-f f-z

a-f via d f-z via i

d-fa-d f-i i-z

a-d via b

a-b b-d

Page 38: Informed Search Methods

AND-OR Graph• In the following tree, the number at each node

represents the heuristic value. Also assume that every operation has a uniform cost of 1.

A

DC B5 3 4

9AA

B B C D

E F G H I J

38

17 9 27

5 10 3 4 15 10

A

F

B

E

Page 39: Informed Search Methods

Decisions in Two-Persons GamesA game may be formally defined as a kind of search problem

with the following components:• Initial State: the board position and an indication of whose

move it is.• Operators: These define the legal moves that a player can

make.• Terminal Test: This test determines when the game is over.

States where the game has ended are called terminal states.• Utility Function or Pay-off Function: It gives a numerical

value for the outcome of a game.– Example: In chess, the outcome is a win, loss or draw, which we

can represent by the values +1, -1 and 0 respectively.

Page 40: Informed Search Methods

Two Player Game: Max and MinObjective of both Max and Min is to optimize

winningsoMax must reach a terminal state with the

highest utilityoMin must reach a terminal state with the

lowest utilityGame ends when either Max and Min have reached a

terminal stateupon reaching a terminal state points maybe

awarded or sometimes deducted

Page 41: Informed Search Methods

Two Player Game: Max and MinSimple problem is to reach a favorable terminal state

Problem Not so simple...oMax must reach a terminal state with as high a

utility as possible regardless of Min’s moves

Max must develop a strategy that determines best possible move for each move Min makes.

Page 42: Informed Search Methods

Tic Tac Toe Game

Page 43: Informed Search Methods

Min Max Algorithm• Minmax Algorithm determines optimum strategy for

Max:• Generate entire search tree• Apply utility function to terminal states• use utility value of current layer to determine

utility of each node for the upper layer• continue when root node is reached

• Minmax Decision - maximizes the utility for Max based on the assumption that Min will attempt to Minimize this utility.

Page 44: Informed Search Methods

Minmax Algorithm: Example

3 2 2

3

3 12 8 2 4 6 14 5 2

Page 45: Informed Search Methods

An Analysis• This algorithm is only good for games with a low branching factor, Why?

• In general, the complexity is:

O(bd) where: b = average branching factord = number of plies

Page 46: Informed Search Methods

Alpha-Beta Pruning• What is pruning?– The process of eliminating a branch of the search

tree from consideration without examining it.• Why prune?– To eliminate searching nodes that are potentially

unreachable.– To speedup the search process.

Page 47: Informed Search Methods

Alpha-Beta Pruning• A particular technique to find the optimal

solution according to a limited depth search using evaluation functions.

• Returns the same choice as minimax cutoff decisions, but examines fewer nodes.

• Gets its name from the two variables that are passed along during the search which restrict the set of possible solutions.

Page 48: Informed Search Methods

Alpha-Beta Pruning: Definitions

• Alpha – the value of the best choice so far along the path for MAX.

• Beta – the value of the best choice (lowest value) so far along the path for MIN.

Page 49: Informed Search Methods

Implementation

• Set root node alpha to negative infinity and beta to positive infinity.

• Search depth first, propagating alpha and beta values down to all nodes visited until reaching desired depth.

• Apply evaluation function to get the utility of this node.

• If parent of this node is a MAX node, and the utility calculated is greater than parents current alpha value, replace this alpha value with this utility.

Page 50: Informed Search Methods

Implementation (Cont’d)• If parent of this node is a MIN node, and the

utility calculated is less than parents current beta value, replace this beta value with this utility.

• Based on these updated values, it compares the alpha and beta values of this parent node to determine whether to look at any more children or to backtrack up the tree.

• Continue the depth first search in this way until all potentially better paths have been evaluated.

Page 51: Informed Search Methods

Example

A1 A3A2

A11 A12 A13 A21 A22 A23 A31 A32 A33

3 12 8 2 14 3 2

3 2 2

3