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?
1条答案
按热度按时间0aydgbwb1#
查看GitHub上的源代码,可以在
_minimize_bfgs
的工作位中找到以下代码片段:这是一个很大的循环,用来进行最小化,你可以看到你传入的
gtol
和maxiter
.BUT -如果行搜索没有找到更好的解决方案,则例程将跳出
while
,而不考虑您指定的容差或迭代次数。最好的解决方案是创建一个不跳出while循环的自定义版本,我不确定这对你来说实际上会起到什么作用,因为答案不会变得更好,但这取决于你。