我的问题:我正在使用scipy
curve_fit
来拟合曲线(https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html),但在很多情况下,估算此曲线的参数是指当地的许多参数之一"本地" 最低点,而不是"全球" 最低要求。现在考虑curve_fit
的设计方式,我们可以预料到这一点。不过,我真的需要全球最低限度。
为了找到它,我最初的预感是乘以初始起点,运行多个curve_fit
个实例并选择具有最低拟合误差的实例,但我会在个人初始中遇到一些偏差猜测估计(也可能是组合的数量可能相当大,这对性能有害)。
您是否碰巧知道更好,更快和/或方法上更健全的方法如何进行? (他们不需要传递至少正方形,如果有必要,我可以建立临时的东西)
答案 0 :(得分:2)
There are a couple possible approaches. One would be to do a "brute force" search through your parameter space to find candidate starting points for the local solver in curve_fit
. Another would be to use a global solver such as differential evolution. For sure, both of these can be much slower than a single curve_fit
, but they do aim at finding "global minima". Within scipy.optimize
, these methods are brute
and differential_evolution
, respectively. It should be noted neither of these is actually global optimizers, as they both require upper and lower bounds for the search space of all parameters. Still, within those boundaries, they do attempt to find the best result, not just a local minimum close to your starting values.
A common approach is to use brute
with medium-sized steps for each parameter, then take the best ten of those and use Levenberg-Marquardt (from leastsq
, as used in curve_fit
) starting from each of these. Similarly, you can use differential_evolution
and then refine.
You might find lmfit
(https://lmfit.github.io/lmfit-py) helpful, as it allows you to set up the model once and switch between solvers, including
brute
, differential_evolution
, and leastsq
. Lmfit also makes it easy to fix some parameters or place upper/lower bounds on some parameters. It also provides a higher-level interface to model building and curve-fitting, and methods to explore the confidence intervals of parameters.