我正在尝试使用模拟退火来优化天线放置和方向问题。我相信 scipy.basinhopping 会做我需要的事情,但我不明白accept_test函数中f_new和f_old的含义。我在文档中没有看到解释。如果有人能启发我这些 kwargs 的含义,那就太好了。我感到困惑的具体可调用对象是:
accept_test : callable, accept_test(f_new=f_new, x_new=x_new, f_old=fold, x_old=x_old), optional
谢谢,
兰加
最佳答案
accept_test : callable, ``accept_test(f_new=f_new, x_new=x_new, f_old=fold, x_old=x_old)``, optional
Define a test which will be used to judge whether or not to accept the
step. This will be used in addition to the Metropolis test based on
"temperature" ``T``. The acceptable return values are True,
False, or ``"force accept"``. If any of the tests return False
then the step is rejected. If the latter, then this will override any
other tests in order to accept the step. This can be used, for example,
to forcefully escape from a local minimum that ``basinhopping`` is
trapped in.
您可以从中收集的信息是,调用参数a
:
a
是可调用的,因此您可以提供一个函数。a
充当进化算法的决策。可能的返回值为 True 和 False,它们与 Metropolis 条件(即两个条件必须返回 True 才能接受步骤)和“强制接受”结合使用。当您想要在 Metropolis 拒绝的情况下强制接受时,必须使用后一个选项。- 您可以使用当前步骤
x_old
和f_old
的值(这些是此处的值,不是可调用值)以及新步骤x_new
的值> 和f_new
在您的自定义标准中。
下面,我设置了一个玩具示例,其中当步骤位于参数空间的右侧时,accept_test 函数强制接受参数空间
def f(x):
return x**2
def a(f_new, x_new, f_old, x_old):
if x_new>x_old:
return "force accept"
else:
return True
basinhopping(f, 1, accept_test=a)
关于python - scipy盆地跳跃接受测试: what is f_new and f_old,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42543681/