2
Outline
•
Hill climbing•
Best-first searchLocal and Global max and min
• A real-valued function f defined on a domain X has
a global (or absolute) maximum
point at x∗ if f (x ∗) ≥ f(x) for all x in X.
Similarly, the function has
a global (or absolute) minimum
point at x∗ if f(x∗) ≤ f(x) for all x in X. The value
of the function at a maximum point is called the maximum value of the function and the value of the function at a minimum point is called the minimum value of the function.
4
Hill Climbing
Hill Climbing - Algorithm
1. Pick a random point in the search space 2. Consider all the neighbors of the
current state
3. Choose the neighbor with the best quality and move to that state
4. Repeat 2 thru 4 until all the neighboring states are of lower quality
Hill Climbing - Algorithm
Function HILL-CLIMBING(Problem) returns a solution state
Inputs:Problem, problem
Local variables:Current, a node
Next, a node
Current = MAKE-NODE(INITIAL-STATE[Problem]) Loop do
Next = a highest-valued successor of Current
If VALUE[Next] < VALUE[Current] then return
Current
Current = Next
10
Hill Climbing
•
Generate-and-test + direction to move.11
Simple Hill Climbing
Algorithm
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 quit
12
Simple Hill Climbing
13
Steepest-Ascent Hill Climbing
(Gradient Search)
14
Steepest-Ascent Hill Climbing
(Gradient Search)
Algorithm
1. 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 quit
better than SUCC set SUCC to this state
15
Hill Climbing: Disadvantages
Local maximum
A state that is better than all of its neighbours, but not
16
Hill Climbing: Disadvantages
Plateau
A flat area of the search space in which all neighbouring
17
Hill Climbing: Disadvantages
Ridge
The 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
18
Hill Climbing: Disadvantages
Ways Out
•
Backtrack to some earlier node and try going in a different direction.19
Hill Climbing: Disadvantages
•
Hill climbing is a local method:Decides what to do next by looking only at the “immediate” consequences of its choices.
20
Hill Climbing: Conclusion
•
Can be very inefficient in a large, rough problem space.•
Global heuristic may have to pay forcomputational complexity.
•
Often useful when combined with otherSimulated Annealing Search
• Idea: escape local maxima by allowing some "bad" moves but gradually decrease their frequency
• One can prove: If T decreases slowly enough, then simulated annealing search will find a global optimum with probability approaching 1
What is Annealing
• Annealing is a thermal process for obtaining
low energy states of a solid in a heat bath.
• The process contains two steps:
– Increase the temperature of the heat bath to a maximum value at which the solid melts.
– Decrease carefully the temperature of the heat bath until the particles arrange themselves in the ground state of the solid. Ground state is a minimum energy state of the solid.
Simulated Annealing
• To apply simulated annealing with
optimization purposes we require the
following:
– A successor function that returns a “close” neighboring solution given the actual one. This will work as the “disturbance” for the particles of the system.
– A target function to optimize that depends on the current state of the system. This
Simulated Annealing
• The search starts with a randomized
state.
• In a polling loop we move to
neighboring states
• We always accept the moves that
decrease the energy
Simulated Annealing
• Decrease the temperature slowly, accepting
less bad moves at each temperature level until at very low temperatures the algorithm
27
Simulated Annealing
•
A variation of hill climbing in which, at the beginning of the process, some downhill moves may be made.•
To do enough exploration of the whole spaceearly on, so that the final solution is relatively insensitive to the starting state.
28
Simulated Annealing
Physical Annealing
•
Physical substances are melted and then gradually cooled until some solid state is reached.•
The goal is to produce a minimal-energy state.•
Annealing schedule: if the temperature is lowered sufficiently slowly, then the goal will be attained.29
Simulated Annealing
Algorithm
1. Evaluate the initial state.
2. Loop until a solution is found or there are no new operators left to be applied:
Set T according to an annealing schedule
Selects and applies a new operator
Evaluate the new state: goal quit
E = Val(current state) Val(new state)
E < 0 new current state
30
Best-First Search
•
Depth-first search: not all competing branches having to be expanded.•
Breadth-first search: not getting trapped on dead-end paths.Simply Logical – Chapter 6
© Peter Flach, 2000
Hill-climbing
search_hc(Goal,Goal ):-goal(Goal).
search_hc(Current
,Goal):-children(Current,Children), select_best(Children,Best), search_hc(Best,Goal).
p.128
% hill_climbing as a variant of best-first search
% hill_climbing as a variant of best-first search
search_hc([
search_hc([GoalGoal|_],Goal|_],Goal):- ):-goal(
goal(GoalGoal).). search_hc([
search_hc([CurrentCurrent|_],Goal):- |_],Goal):-children(
children(CurrentCurrent,,ChildrenChildren),), add_bstf(
add_bstf(ChildrenChildren,[],NewAgenda,[],NewAgenda),), search_hc(
Code of c++
• #include <cmath> • #include <random> • #include <utility> • #include <algorithm>
• // To find a status with lower energy according to the given condition template<typename status, typename count, typename energy_function, typename temperature_function, typename next_function, typename generator> status simulated_annealing(status i_old, count c, const
energy_function& ef, const temperature_function& tf, const next_function& nf, generator& g)
• { auto e_old = ef(i_old); status i_best = i_old; auto e_best = e_old; std::uniform_real_distribution<decltype(e_old)> rf(0, 1);
• for(; c > 0; --c)
• { status i_new = nf(i_old, g);
• auto e_new = ef(i_new); if(e_new < e_best){ i_best = i_new ; e_best = e_new ; } if( e_new < e_old || std::exp( (e_old - e_new) / tf(c) ) > rf(g) ){ i_old =
std::move(i_new); e_old = std::move(e_new); } } return(i_best); }