python - scipy盆地跳跃接受测试: what is f_new and f_old

标签 python numpy scipy

我正在尝试使用模拟退火来优化天线放置和方向问题。我相信 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

谢谢,

兰加

最佳答案

来自文档https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.basinhopping.html#scipy-optimize-basinhopping

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:

  1. a 是可调用的,因此您可以提供一个函数。
  2. a 充当进化算法的决策。可能的返回值为 True 和 False,它们与 Metropolis 条件(即两个条件必须返回 True 才能接受步骤)和“强制接受”结合使用。当您想要在 Metropolis 拒绝的情况下强制接受时,必须使用后一个选项。
  3. 您可以使用当前步骤 x_oldf_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/

相关文章:

python - 使用 Scippy 的 ndimage.map_coordinates 进行插值时出现意外结果

javascript - JSON.parse 需要转义哪些字符

python - 如何获得比 numpy.dot 更快的代码用于矩阵乘法?

python - 安装后找不到Numpy

python - np.array - 太多值无法解包

python - 在 scipy 中将稠密向量添加到稀疏矩阵(通过广播)

python - Flask 处理带有 URL 编码参数的请求时出现问题

python - 错误 UnicodeDecodeError : 'utf-8' codec can't decode byte 0xbe in position 2: invalid start byte

python - Odoo/OpenERP "Unable to login on database odoo"

numpy.sum() 给出 `TypeError: sum() got an unexpected keyword argument ' dtype'`