pythonalgorithmmathematical-optimizationsimulated-annealing

Simulated annealing, normalized temperature


I have a problem that I need to maximize the value X of the given function:

math formula

This is the python code for the formula: 2 ** (-2 *((((x-0.1) / 0.9)) ** 2)) * ((math.sin(5*math.pi*x)) ** 6).

I'm using the simulated annealing algorithm to this job, but I'm having a problem.

probability = pow(math.e, (actual_cost - best_cost) / temperature)

My "cost" (what I'm trying to optimize) is a very short number, most often between 0 and 0.1, but my temperature, in the other side, is like 100.

So, when I apply the probability function, my result is always something like 99%, which makes my algorithm accept negative values in all iterations, instead of decreasing this probability throughout the iterations.

How can I adapt the value of my temperature to change the probability through the iterations?


Solution

  • The solution to this can be found in the docs for scipy.optimize.basinhopping:

    Choosing T: The parameter T is the “temperature” used in the Metropolis criterion. Basinhopping steps are always accepted if func(xnew) < func(xold). Otherwise, they are accepted with probability:

    exp( -(func(xnew) - func(xold)) / T )

    So, for best results, T should to be comparable to the typical difference (in function values) between local minima. (The height of “walls” between local minima is irrelevant.)

    If T is 0, the algorithm becomes Monotonic Basin-Hopping, in which all steps that increase energy are rejected.