强制scipy.optimize.minimize采用最大数量的迭代步骤

nfs0ujit  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(182)

I am using scipy.optimize.minimize with method="L-BFGS-B" to numerically minimize a cost function over a set of parameters. I have set maxiter manually in the parameters, but the optimizer terminates early when it meets method-specific criteria (according to ftol and gtol ).
I would like to force the optimizer to take the maximum number of steps ( maxiter ) for the purposes of comparing different systems/cost functions - that is, I want to entirely switch off the early termination conditions. I have looked through the documentation and can't seem to find a way to do this. I've tried setting ftol=0 and gtol=0 , or at least setting them to be extremely small values, and neither of these seem to stop the early termination. How would I go about forcing it to take the maximum number of allowed steps?

0aydgbwb

0aydgbwb1#

查看GitHub上的源代码,可以在_minimize_bfgs的工作位中找到以下代码片段:

while (gnorm > gtol) and (k < maxiter):
    pk = -np.dot(Hk, gfk)
    try:
        alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
                 _line_search_wolfe12(f, myfprime, xk, pk, gfk,
                                      old_fval, old_old_fval, amin=1e-100, amax=1e100)
    except _LineSearchError:
        # Line search failed to find a better solution.
        warnflag = 2
        break

这是一个很大的循环,用来进行最小化,你可以看到你传入的gtolmaxiter.
BUT -如果行搜索没有找到更好的解决方案,则例程将跳出while,而不考虑您指定的容差或迭代次数。
最好的解决方案是创建一个不跳出while循环的自定义版本,我不确定这对你来说实际上会起到什么作用,因为答案不会变得更好,但这取决于你。

相关问题