Vous êtes sur la page 1sur 55

(TES3111 / TIC3151 )

Artificial Intelligence
Lecture 5
Informed Search
1

Contents
5.1 Introduction to Informed Search Methods
5.2 Best-First Search
5.2.1 Greedy best-first search
5.2.2 A* search
5.2.3 Best-First Search Analysis
5.2.4 Heuristic Functions

5.3 Memory Bounded Search


5.3.1 Iterative Deepening A* Search
5.3.2 Simplified Memory Bounded A*

5.4 Local Search Algorithms


5.4.1 Hill-Climbing Search
5.3.2 Simulated Annealing, Local beam search and Genetic Algorithm
2

Informed Search Methods


Relies on additional knowledge about the problem or domain
frequently expressed through heuristics (rules of thumb)

The term heuristic refers to a technique that is likely, but not


guaranteed, to produce a good (not necessarily best) answer
Informed search also called heuristic search

It can distinguish more promising paths towards a goal


But, may be misleading, depending on the quality of the
heuristic
In general, performs much better than uninformed search
but frequently still exponential in time and space for realistic
problems
3

Informed Search Methods


Best-first search is the general approach for informed search
An evaluation function, f(n) is used to evaluate a node n in a
search tree
so that best node can be selected for expansion
A key component of an evaluation function is a heuristic
function, h(n)
estimates the cost of the cheapest path from node n to a goal
node
The most common form to impart additional knowledge to
search algorithm

Informed Search Methods


Often, we can decompose f:

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


Evaluation function
Cost function:
cost to get to node n

Heuristic function:
estimated cost of the cheapest
path from node n to goal node

If n is goal then h(n)=0


If h(n) = then n is a
dead end; a goal cannot
be reached
5

Informed Search Methods

f(n) = g(n)

(uniform-cost)

f(n) = h(n)

(greedy algorithm)

f(n) = g(n) + h(n) (algorithm A*)


6

Greedy Best-First Search


Greedy search expands the node that appears to be closest to goal
on the grounds that it will lead to a solution quickly

Thus, the evaluation function is:

f(n) = h(n)

Evaluation function
Heuristic function:
estimated cost of the cheapest
path from node n to goal node

Greedy Best-First Search


Romania driving problem
Let hSLD(n) = straight-line distance heuristic
If the goal is Bucharest, we will need to know the straight-line
distances to Bucharest

hSLD(n) cannot be computed from the problem description


itself
Note: hSLD is correlated with actual road distances and thus a
useful heuristic

Greedy Best-First Search

Greedy Best-First Search

Greedy best-first search


finds a solution without ever
expanding a node (i.e., not on
the solution path), hence its
search cost is minimal
10

Greedy Best-First Search


However, greedy best-first search is not optimal

Actual path cost of the solution:


Arad-Sibu-Fagaras-Bucharest = 140 + 99 + 211 = 450
32 km longer

But, consider the path


Arad-Sibu-Rimnicu-Pitesti-Bucharest = 140 + 80 + 97 + 101 = 418
Refer to slide 14, lecture 3,
for the path distance (in km)

This is why the algorithm is called greedy since at each step it tries
to get as close to the goal as it can11

Greedy Best-First Search


Contrast with uniform-cost search which expands the lowest
cost path from the start

Greedy best-first search resembles depth-first search since it


prefers to follows a single path all the way to the goal, but it
will backup when it hits a dead end.
So,
it is not complete

it is not optimal
time and space complexity is O(bm)

12

Greedy Best-First Search


Properties of greedy search
Completeness: No
Fails in infinite-depth spaces
- E.g. going from Iasi-Neamt-Iasi-Vaslui-

Complete in finite spaces with repeated state checking


Initial

Goal

Goal

13

Based on heuristic, Neamt


will be expanded first since
it is closest to Fagaras, but
it is a dead end

Greedy Best-First Search


Properties of greedy search
Optimality: No. Optimal path goes through Pitesti, not through
Fagaras.
Time Complexity: O(bm), like depth-first, but a good heuristic
function gives dramatic improvement on average
Space Complexity : O(bm), keeps all nodes in memory
b = branching factor

m = maximum depth of the search

14

Greedy Best-First Search


For greedy best-first search, evaluation function is:

f(n) = h(n)
estimated cost of the cheapest
path from node n to goal node

[Recall]: For uniform cost search, evaluation function is:

f(n) = g(n)
cost to get to node n

15

A* Search
Best-known form of best-first search.
Combines greedy and uniform-cost search to find the (estimated)
cheapest path through the current node
Evaluation function:
f(n) = g(n) + h(n)

cost to get to node n

estimated cost of the cheapest path


from node n to goal node

f(n) is the estimated cost of cheapest solution that passes through node n
16

A* Search
Its goal is to find a minimum total cost path.
A* expands node with the lowest f(n) value first
This leads to both complete and optimal search algorithm, provided
that h(n) satisfies certain conditions
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.
A* is optimal if h(n) is an admissible heuristic
provided that h(n) never overestimates the cost to reach the
goal
17

A* Search
hSLD
g(n)

18

A* Search

220+193

19

A* Search
from Arad

20

A* Search
Properties of A*
Complete? Yes (when the branching factor is finite and every operator
has a fixed positive cost)

Time? Exponential

Drawback

Space? Keeps all nodes in memory


Optimal? Yes (optimally efficient among all such algorithms)

21

Heuristic Functions
The effect of heuristic accuracy on performance
One way to determine the quality of a heuristic is the
effective branching factor, b*
N + 1 = 1 + b* + (b*)2 + (b*)3 + ... + (b*)d
N: total number of nodes generated by A*
d: solution depth

b*: branching factor that a uniform tree of depth d would have in order to
contain N + 1 nodes

22

Heuristic Functions
Dominance
1

Start state

3
4

h1(s) = 7
h2(s) = 2 + 3+ 3 + 2 + 4 + 2 + 0 + 2 = 18

Goal state

h2 dominates h1
if h2(s) >= h1(s) for all s

If h2 dominates h1
then A* is more efficient with h2 (i.e., it expands fewer states)

23

Heuristic Functions
Given two admissible heuristics h1(n) and h2(n), which is better?
If h2(n) h1(n) for all n, then
h2 is said to dominate h1
h2 is better for search

24

Memory-bounded Search
Limitations of A*
It can use a lot of memory
In principal, O(no. of states)
For really big search spaces, A* will run out of memory

Good news: A* is optimally efficient


For a given h(.), no other optimal algorithm will expand few
nodes

25

Memory-bounded Search
Search algorithms that try to conserve memory
Most are modifications of A*
Iterative-deepening A* (IDA*)
Recursive best-first search (RBFS)
Simplified memory-bounded A* (SMA*)

26

Memory-bounded Search
Iterative-deepening A* (IDA*)
The main difference between IDA* and IDA:
The cutoff used is f-cost (g+h) rather than depth
At each iteration, the cutoff value is the smallest f-cost of
any node that exceeded the cutoff on the previous iteration;
It can avoid the substantial overhead associated with keeping
a sorted queue nodes.

27

Memory-bounded Search
Recursive Best-First Search (RBFS)
Mimic the operation of best-first search, but using only linear
space
It is similar to that of a recursive depth-first search with record
keeping to prevent following the current path indefinitely
It records the f-cost of the best alternative path available from any
ancestor of the current node
if current f-cost is greater, backtrack to the alternative path as
unwind recursion, store best f-cost of any child node
This allows revisiting abandoned subtree if the current f-cost
becomes greater
Issue:
possible repeated re-generation of subtrees
28

Memory-bounded Search
Recursive Best-First Search (RBFS)

f-limit for
recursive calls

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

Path to Rimnicu Vilcea is already expanded


Follows path to Pitesti: f-cost worse than the f-limit (417>415)
29

Memory-bounded Search
Recursive Best-First Search (RBFS)

Update

Unwind the recursion


Update best f-cost from that of current best leaf: Pitesti
Now Fagaras is best, expand Fagaras
Best value is now 450
30

Memory-bounded Search

Update

Unwind the recursion


Update best f-cost from that of current best leaf: Bucharest
Now Rimnicu Vilcea is best, expand Rimnicu Vilcea
Because the best alternative path (through Timisoara) costs 447,
expansion continues to Bucharest
31

Memory-bounded Search
Simplified Memory-bounded A* (SMA*)
Uses all available memory for the search
drops nodes from the queue when it runs out of space
those with the highest f-value
Basic idea:
Do A* until runs out of memory
Expand the best (lowest f-value) leaf until memory is full

Throw away node with highest f-value


Store f-value in ancestor node
Expand node again if all other nodes in memory are worse
32

Local Search Algorithms


Idea: start with an initial guess at a solution and incrementally
improve it until it is one
Advantages:
Use very little memory

Find often reasonable solutions in large or infinite state spaces.


Since only information about the current state is kept, such
methods are called local

33

Local Search Algorithms


Local search algorithms are also useful for solving pure
optimization problems

The aim is to find the best state according to an objective


function for some problems
This class of problems includes many applications such as
Integrated-circuit design
Factory-floor layout

Job-shop scheduling
Telecommunications network design
Vehicle routing
Portfolio management
34

Local Search Algorithms


State space landscape
Landscape has both location (defined by the state) and
elevation (defined by the value of the heuristic cost function or
objective function)

elevation

35

Local Search Algorithms


If the elevation corresponds to cost
Then, the aim is to find lowest valley global minimum

If the elevation corresponds to an objective function,


Then the aim is to find the highest peak global maximum
One can convert one to the other just by inserting a minus (-) sign
Local search algorithms explore this landscape
A complete local search algorithm always finds a goal if one exists

An optimal algorithm always finds a global minimum/maximum.

36

Hill-Climbing Search
Hill climbing on a surface of states
It is a simply loop that continuously moves in the direction of
increasing value that is, uphill.

37

Hill-Climbing Search
Properties
Terminates when a peak is reached, where no neighbor has a higher
value
It does not maintain a search tree,

current node data structure only record the state and its objective
function value
Does not look ahead of the immediate neighbors of the current state.

Chooses randomly among the set of best successors, if there is more


than one.
Doesnt backtrack, since it doesnt remember where its been
38

Hill-Climbing Search
Algorithm

At each step, the current node is replaced by


the best neighbor, i.e., neighbor with the
highest value

Note: if a heuristic cost estimate h is used, find the neighbor with the lowest h
39

Hill-Climbing Search
8-queens problem

Use a complete-state formulation, where each state has 8 queens


on the board, one per column
40

Hill-Climbing Search
8-queens problem
Successor function:
- move a single queen to another
square in the same column.
- It returns all possible states
generated by moving a single queen
to another square in the same column
- Each state has 8 x 7 = 56 successors

41

Hill-Climbing Search
8-queens problem
Heuristic function, h(n):
- The no. of pairs of queens that are
attacking each other (directly/indirectly)

- Thus, h = 17

42

Hill-Climbing Search
8-queens problem

A local minimum with h = 1 with only five steps and very nearly a solution
43

Hill-Climbing Search
Also called greedy local search
Tries to grab a good neighbor state without thinking ahead where to
go next
Problem: depending on initial state, can get stuck in local maxima

It is simply loop continually moves in the direction of increasing value that


is, uphill
Hill-climbing also known as
gradient ascent/descent;
steepest ascent

Like climbing Everest in


thick fog with amnesia

44

Hill-climbing Search
Problems with Hill Climbing
Local maxima (foothills): a local maximum is a peak i.e, higher
than each of its neighboring states, but lower than the global
maximum

Every move of
a single queen
makes the
situation worse

A local maximum (i.e., a local minimum for cost h)


45

Hill-climbing Search
Problems with Hill Climbing
Plateaus: All neighbors look the same (the space has a broad flat
region that gives the search algorithm no direction)
Ridges: going through a sequence of local maxima

46

Hill-climbing Search
Overcoming Local Optimum and Plateau
Simulated annealing
Genetic algorithms
Etc.

47

Genetic Algorithms
Combine two parent states, rather than modifying a single state to
generate successor states

GA begin with a set of k randomly generated states: population


Each state is represented as a string over a finite alphabet, most
commonly a string of 0s and 1s

16257483

52

Genetic Algorithms

A state or individual is rated by an evaluation function/


objective function (fitness function)

A fitness function returns higher values for better states

Fitness is used in selecting the parent pair

The probability of being chosen for reproducing is directly


proportional to the fitness score

Produce the next generation of states (offspring):


Crossover
Mutation

53

Genetic Algorithms
Genetic operators: Crossover

Generate two offspring


Use Parent 1 for the first part of the string and up to the
crossover point and Parent 2 for the rest
Parent 1
Parent 2

54

Genetic Algorithms
Genetic operators: Mutation

The value of each element of the string is changed with some


probability.

55

Genetic Algorithms
function GENETIC_ALGORITHM( population, FITNESS-FN) return an individual
input: population, a set of individuals
FITNESS-FN, a function which determines the quality of the individual
repeat
new_population empty set
loop for i from 1 to SIZE(population) do
x RANDOM_SELECTION(population, FITNESS_FN)
y RANDOM_SELECTION(population, FITNESS_FN)
child REPRODUCE(x,y)
if (small random probability) then child MUTATE(child )
add child to new_population
population new_population
until some individual is fit enough or enough time has elapsed
return the best individual in population, according to FITNESS-FN

56

Genetic Algorithms
function REPRODUCE(x,y) returns an individual
inputs: x, y, parent individual
n LENGTH(x)
c random number from 1 to n
return APPEND(SUBSTRING(x, 1, c), SUBSTRING(y, c+1, n))

57

No. of nonattacking
pairs of queens

58

The End

59

Vous aimerez peut-être aussi