模拟退火,归一化温度

2024-06-10 20:31:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个问题,我需要最大化给定函数的值X:

math formula

这是公式的python代码:2 ** (-2 *((((x-0.1) / 0.9)) ** 2)) * ((math.sin(5*math.pi*x)) ** 6)

我正在使用模拟退火算法来完成这项工作,但我遇到了一个问题

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

我的“成本”(我试图优化的)是一个非常短的数字,通常在0到0.1之间,但我的温度,在另一边,是100

所以,当我应用概率函数时,我的结果总是99%,这使得我的算法在所有迭代中都接受负值,而不是在整个迭代过程中降低这个概率

我如何调整温度值以通过迭代改变概率


Tags: 函数代码算法pimathsin温度概率
1条回答
网友
1楼 · 发布于 2024-06-10 20:31:42

可以在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.

相关问题 更多 >