Mik*_*key 5 java algorithm simulated-annealing hill-climbing stochastic
我正在尝试用Java实现Stoachastic Hill Climbing.据我所知,这个algorthim提出了一个新的解决方案,随机挑选,然后根据它的好坏来接受解决方案.例如,如果它非常糟糕,那么它将有一个很小的机会,如果它很糟糕,那么它将有更多的机会被选中,但我不知道如何在java中实现这个概率.
虽然在谷歌上浏览,我偶然发现了这个等式,
我不太确定如何解释这个等式.
有人可以帮助我如何在Java中实现这一点吗?
等式的左侧p将是介于 0 和 1 之间的双精度值(包括 0 和 1)。oldFitness,newFitness并且T也可以是双打。
您的代码中将包含与此类似的内容:
double p = 1 / (1 + Math.exp((oldFitness - newFitness) / T));
if (Math.random() < p) {
// accept the new solution
Run Code Online (Sandbox Code Playgroud)