AIMA - Informed Search
AIMA - Informed Search
2
Informed (Heuristic) Search
Strategies
• There is a whole family of Best-First Search
algorithms with different evaluation functions
– Each has a heuristic function h(n)
• Implementation
– expand the “most desirable” node into the fringe queue
– sort the queue in decreasing order of desirability
6
Greedy Best-First Search
• hSLD(In(Arid)) = 366
8
Greedy Best-First Search
9
Greedy Best-First Search
10
Greedy Best-First Search
• Complete
– No, GBFS can get stuck in loops (e.g. bouncing back
and forth between cities)
• Time
– O(bm) but a good heuristic can have dramatic
improvement
• Space
– O(bm) – keeps all the nodes in memory
• Optimal
– No!
11
A Quick Review - Again
• g(n) = cost from the initial state to the
current state n
13
A* Search
• When h(n) = actual cost to goal
– Only nodes in the correct path are expanded
– Optimal solution is found
• When h(n) < actual cost to goal
– Additional nodes are expanded
– Optimal solution is found
• When h(n) > actual cost to goal
– Optimal solution can be overlooked
14
A* Search
• A* is optimal if it uses an admissible
heuristic
– h(n) <= h*(n) the true cost from node n
– if h(n) never overestimates the cost to reach
the goal
• Example
– hSLD never overestimates the actual road
distance
15
Greedy Best-First Search
16
A* Search
17
A* Search
18
A* Search
19
A* Search
20
A* Search
21
A* Search
• A* expands nodes in increasing f value
– Gradually adds f-contours of nodes (like
breadth-first search adding layers)
– Contour i has all nodes f=fi where fi < fi+1
22
A* Search
• Complete
– Yes, unless there are infinitely many nodes with f <= f(G)
• Time
– Exponential in [relative error of h x length of soln]
– The better the heuristic, the better the time
• Best case h is perfect, O(d)
• Worst case h = 0, O(bd) same as BFS
• Space
– Keeps all nodes in memory and save in case of repetition
– This is O(bd) or worse
– A* usually runs out of space before it runs out of time
• Optimal
– Yes, cannot expand fi+1 unless fi is finished
23
Memory-Bounded Heuristic Search
• Iterative Deepening A* (IDA*)
– Similar to Iterative Deepening Search, but cut off at (g(n)+h(n))
> max instead of depth > max
– At each iteration, cutoff is the first f-cost that exceeds the cost
of the node at the previous iteration
25
Heuristic Functions
• To use A* a heuristic function must be
used that never overestimates the number
of steps to the goal
27
Dominance
• If h2(n) > h1(n) for all n (both admissible)
then h2(n) dominates h1(n) and is better
for the search
28
Relaxed Problems
• A Relaxed Problem is a problem with
fewer restrictions on the actions
– The cost of an optimal solution to a relaxed
problem is an admissible heuristic for the
original problem
31
Learning Heuristics From
Experience
• h(n) is an estimate cost of the solution
beginning at state n
• How can an agent construct such a function?
• Experience!
– Have the agent solve many instances of the problem
and store the actual cost of h(n) at some state n
– Learn from the features of a state that are relevant to
the solution, rather than the state itself
• Generate “many” states with a given feature and determine
the average distance
• Combine the information from multiple features
– h(n) = c(1)*x1(n) + c(2)*x2(n) + … where x1, x2, … are
features
32
Optimization Problems
• Instead of considering the whole state
space, consider only the current state
• Limits necessary memory; paths not
retained
• Amenable to large or continuous (infinite)
state spaces where exhaustive search
algorithms are not possible
• Local search algorithms can’t backtrack
33
Local Search Algorithms
• They are useful for solving optimization
problems
– Aim is to find a best state according to an objective
function
• Optimization techniques
– Direct (closed-form)
– Search (generate-test)
– Heuristic search (e.g Hill Climbing)
– Genetic Algorithm
35
Direct Optimization
• The slope of a function at the maximum or minimum is 0
– Function is neither growing nor shrinking
– True at global, but also local extreme points
36
Hill Climbing
• Consider all possible successors as “one
step” from the current state on the
landscape.
• At each iteration, go to
– The best successor (steepest ascent)
– Any uphill move (first choice)
– Any uphill move but steeper is more probable
(stochastic)
• All variations get stuck at local maxima
37
Hill Climbing
38
Hill Climbing
39
Hill Climbing
• Local maxima = no uphill step
– Algorithms on previous slide fail (not complete)
– Allow “random restart” which is complete, but might
take a very long time
• Plateau = all steps equal (flat or shoulder)
– Must move to equal state to make progress, but no
indication of the correct direction
• Ridge = narrow path of maxima, but might have
to go down to go up (e.g. diagonal ridge in 4-
direction space)
40
Simulated Annealing
• Idea: Escape local maxima by allowing some “bad”
moves
– But gradually decreasing their frequency
• Algorithm is randomized:
– Take a step if random number is less than a value based on both
the objective function and the Temperature
41
Simulated Annealing
42
Genetic Algorithms
• Quicker but randomized searching for an optimal
parameter vector
• Operations
– Crossover (2 parents -> 2 children)
– Mutation (one bit)
• Basic structure
– Create population
– Perform crossover & mutation (on fittest)
– Keep only fittest children
43
Genetic Algorithms
• Children carry parts of their parents’ data
44
Genetic Algorithms
• Representation
– Children (after crossover) should be similar to parent,
not random
– Binary representation of numbers isn’t good - what
happens when you crossover in the middle of a
number?
– Need “reasonable” breakpoints for crossover (e.g.
between R, xcenter and ycenter but not within them)
• “Cover”
– Population should be large enough to “cover” the
range of possibilities
– Information shouldn’t be lost too soon
– Mutation helps with this issue
45
Experimenting With GAs
• Be sure you have a reasonable “goodness”
criterion
• Choose a good representation (including
methods for crossover and mutation)
• Generate a sufficiently random, large enough
population
• Run the algorithm “long enough”
• Find the “winners” among the population
• Variations: multiple populations, keeping vs. not
keeping parents, “immigration / emigration”,
mutation rate, etc.
46