Professional Documents
Culture Documents
Mod2.2, Part 2
Mod2.2, Part 2
Suppose we want to find the maximum value of the function f(x) = -x^2 + 4x. We'll use hill
climbing to find the peak of this function.
2. Calculate the value of the function at this point: f(2) = -2^2 + 4*2 = 4.
4. Calculate the value of the function at the neighboring point to the right: f(2 + 0.1) =
-1.69.
7. Repeat steps 4-6 until you reach a point where f(x + Δx) is not greater than f(x). This
means you've found a local maximum.
In this case, hill climbing will converge to the local maximum of the function at x = 2. The
maximum value of the function f(x) is 4 at this point. Keep in mind that hill climbing is not
guaranteed to find the global maximum, and its effectiveness depends on the choice of
initial values and step size.Hill climbing algorithm vs simulated annealing algorithm
● Hill climbing algorithm is a greedy algorithm, meaning that it always moves towards a
better solution at each step.
● Simulated annealing algorithm is a probabilistic algorithm, meaning that it may move
towards a worse solution with a certain probability.
● Hill climbing algorithm is usually implemented using a simple iterative loop.
● Simulated annealing algorithm is usually implemented using a cooling schedule, which
gradually reduces the probability of moving towards a worse solution over time.
Overall, simulated annealing algorithm is a more powerful algorithm than hill climbing
algorithm, but it is also slower. Hill climbing algorithm is a good choice for simple
problems, but simulated annealing algorithm is a better choice for complex problems
with many local optima.