You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向L-BFGS-B优化器传递maxcor参数时触发TypeError求助

Fixing the "unexpected keyword argument 'maxcor'" Error with L-BFGS-B in Basinhopping

Hey there! I spot the issue immediately—this is a super common mix-up when working with scipy's optimization tools. Let's get this sorted quickly.

What's Going Wrong

The maxcor parameter is specific to the L-BFGS-B optimizer, but you're passing it directly as a top-level key in minimizer_kwargs. The problem is that scipy.optimize.minimize() (which basinhopping uses under the hood) doesn't accept maxcor as a direct argument. Method-specific parameters like this need to be wrapped inside an options dictionary instead.

The Corrected Code

Here's how to adjust your code to pass maxcor properly:

minimizer_kwargs = {
    "method": "L-BFGS-B",
    "bounds": bounds,
    "options": {"maxcor": 190}  # Move maxcor into the options sub-dictionary
}
BH_result = optimize.basinhopping(
    obj_Basinhopping, 
    initial_guess, 
    minimizer_kwargs=minimizer_kwargs, 
    accept_test=mybounds,
    callback=printx, 
    disp=True
)

Why This Fixes It

  • Top-level keys in minimizer_kwargs are parameters that minimize() accepts universally (like method, bounds, or jac).
  • Settings that are unique to a specific optimizer (like maxcor for L-BFGS-B, which controls the number of stored history updates for the limited-memory BFGS approximation) belong in the options dict. This tells minimize() to pass those settings directly to the chosen optimization method.

内容的提问来源于stack exchange,提问作者Paul Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:48:40