Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

32
Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1

Transcript of Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Page 1: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

1

Princess Nora University

Artificial Intelligence

Chapter (4)Informed search algorithms

Page 2: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Outline

• Best-first search• Greedy best-first search• A* search• Heuristics• Local search algorithms• Hill-climbing search• Simulated annealing search• Local beam search• Genetic algorithms

Page 3: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

3

Informed Search

Idea: use problem specific knowledge to pick which node to expand

• Typically involves a heuristic function h(n) estimating the cheapest path from

n.STATE to a goal state

A search strategy is defined by picking the order of node expansion

Page 4: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

4

Best-first search

• We can use it to direct our search towards the goal.

• Best first search simply chooses the unvisited node with the best heuristic value to visit next.

• It can be implemented in the same algorithm as lowest-cost Breadth First Search.

• Idea: use an evaluation function f(n) for each node– estimate of "desirability"Expand most desirable unexpanded node

• Implementation:• Order the nodes in fringe in decreasing order of

desirabilitySpecial cases:

– greedy best-first search– A* search

Page 5: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Romania with step costs in km

Page 6: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Greedy best-first search

• Evaluation function f(n) = h(n) (heuristic)• = estimate of cost from n to goal

• e.g., hSLD(n) = straight-line distance from n to Bucharest

• Greedy best-first search expands the node that appears to be closest to goal

Page 7: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Greedy best-first search example

Page 8: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Greedy best-first search example

Page 9: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Greedy best-first search example

Page 10: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Greedy best-first search example

Page 11: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Properties of greedy best-first search

Complete? No – can get stuck in loops, e.g., Iasi Neamt Iasi Neamt •• Time? O(bm), but a good heuristic can give

dramatic improvement•• Space? O(bm) -- keeps all nodes in memory• Optimal? No

Page 12: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search

• Idea: avoid expanding paths that are already expensive

• Evaluation function f(n) = g(n) + h(n)• g(n) = cost so far to reach n• h(n) = estimated cost from n to goal• f(n) = estimated total cost of path through n

to goal

Page 13: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search example

Page 14: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search example

Page 15: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search example

Page 16: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search example

Page 17: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search example

Page 18: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

A* search example

Page 19: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Admissible heuristics

• A heuristic h(n) is admissible if for every node n,

h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n.

• An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic

• Example: hSLD(n) (never overestimates the actual road distance)

• Theorem: If h(n) is admissible, A* using TREE-SEARCH is optimal

Page 20: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Properties of A*

• Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) )

• Time? Exponential• Space? Keeps all nodes in memory• Optimal? Yes

Page 21: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Local search algorithms

• In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

• State space = set of "complete" configurations• Find configuration satisfying constraints, e.g., n-

queens

• In such cases, we can use local search algorithms• keep a single "current" state, try to improve it.• Very memory efficient (only remember current

state)

Page 22: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

22

Hill-climbing search

• “ a loop that continuously moves in the direction of increasing value”– terminates when a peak is reached

• Value can be either– Objective function value– Heuristic function value (minimized)

• Hill climbing does not look ahead of the immediate neighbors of the current state.

• Can randomly choose among the set of best successors, if multiple have the best value.

• Characterized as “trying to find the top of Mount Everest while in a thick fog”

Page 23: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

23

Example: n-queens

• Put n queens on an n × n board with no two queens on the same row, column, or diagonal

Page 24: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Hill-climbing search

Page 25: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

25

Hill climbing and local maxima

• When local maxima exist, hill climbing is suboptimal

• Local maxima: a local maximum, as opposed to a global maximum, is a peak that is lower than the highest peak in the state space.

• Once on a local maximum, the algorithm will halt• even though the solution may be far from

satisfactory.• Simple (often effective) solution

– Multiple random restarts

Page 26: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Hill-climbing search: 8-queens problem

• A local minimum with h = 1

Page 27: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Simulated annealing search

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

Page 28: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Properties of simulated annealing search

• One can prove: If T decreases slowly enough, then simulated annealing search will find a global optimum with probability approaching 1

• Widely used in VLSI layout, airline scheduling, etc

Page 29: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Local beam search

• Keep track of k states rather than just one

• Start with k randomly generated states

• At each iteration, all the successors of all k states are generated

If any one is a goal state, stop; else select the k best successors from the complete list and repeat.•

Page 30: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Genetic algorithms• A successor state is generated by combining two

parent states

• Start with k randomly generated states (population)

• A state is represented as a string over a finite alphabet (often a string of 0s and 1s)

• Evaluation function (fitness function). Higher values for better states.

• Produce the next generation of states by selection, crossover, and mutation

Page 31: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Genetic algorithms

• Fitness function: number of non-attacking pairs of queens (min = 0, max = 8 × 7/2 = 28)

• 24/(24+23+20+11) = 31%• 23/(24+23+20+11) = 29% etc

Page 32: Princess Nora University Artificial Intelligence Chapter (4) Informed search algorithms 1.

Genetic algorithms