我想知道^{
当我实施它们时,它们产生的chi^2差异最小:
>>> solution0 = ((p0.fun).reshape(100,100))
>>> # p0.fun are the residuals of my fit function np.ravel'ed as returned by least_squares
>>> print(np.sum(np.square(solution0)))
0.542899505806
>>> solution1 = np.square((median-solution1))
>>> # solution1 is the solution found by least_sq, it does not yield residuals thus I have to subtract it from the median to get the residuals (my special case)
>>> print(np.sum((solution1)))
0.54402852325
有谁能详细说明一下,或者指出我在哪里可以找到其他的文档,scipy的文档有点神秘。在
从
least_squares
的文档来看,leastsq
似乎是一个旧的包装器。在所以您应该使用
least_squares
。似乎least_squares
具有其他功能。其中最重要的是使用的默认“方法”(即算法)不同:旧的
leastsq
算法只是lm
方法的包装器,正如文档所说,它只适用于小的无约束问题。在您在结果中看到的差异可能是由于所采用的算法的不同。在
编写新Scipy函数least_squares的主要原因是允许变量的上下界(也称为“框约束”)。这是一个强烈要求的功能。在
这个看似简单的添加实际上远不是琐碎的,需要全新的算法,特别是dogleg(
method="dogleg"
中的least_squares
)和信任域反射(method="trf"
),它们允许对框约束进行健壮和有效的处理(有关算法的详细信息请参阅相关Scipydocumentation )。在同样重要的是对大规模问题和稀疏雅可比的支持。在
当不需要变量的边界,并且问题不是很大时,新Scipy函数
least_squares
中的算法与旧的leastsq
中使用的Levenberg-Marquardt-MINPACK实现相比几乎没有优势(如果有的话)。在但是,旧的
leastsq
和新的least_squares
使用选项method="lm"
调用相同的minpackfortran代码。由于这个原因,旧的leastsq
现在已被废弃,不建议用于新代码。在在
least_squares
中,可以为每个变量指定上下边界如果比较docstrings,leatsq还没有提供更多的特性
相关问题 更多 >
编程相关推荐