简体   繁体   English

制定Levenberg-Marquart的残差

[英]Formulate residual for Levenberg-Marquart

I want to minimize a cost function with the form, 我想用表格最小化成本函数,

成本

with the Levenberg-Marquart method with the scipy.optimize.least_squares function. 使用带有scipy.optimize.least_squares函数的Levenberg-Marquart方法。 But I do not see how to formulate it in terms of residuals, so that I can use such method. 但是我看不到如何根据残差来表述它,因此我可以使用这种方法。 Otherwise I get the error message "Method 'lm' doesn't work when the number of residuals is less than the number of variables." 否则,我将收到错误消息“当残差数小于变量数时,方法'lm'不起作用。”

My cost function is defined as follows: 我的成本函数定义如下:

def canonical_cost(qv, t, A, B, C, delta, epsilon, lam):
    assert(type(qv) is np.ndarray and len(qv) == 4)
    # assert(type(t) is np.ndarray and len(t) == 3)

    q = Quaternion(*qv)
    qv, tv = qv.reshape(-1, 1), np.vstack(([0], t.reshape(-1, 1)))

    f1 = qv.T @ (A + B) @ qv
    f2 = tv.T @ C @ tv + delta @ tv + epsilon @ (q.Q.T @ q.W) @ tv
    qnorm = (1 - qv.T @ qv)**2
    return np.squeeze(f1 + f2 + lam*qnorm)

And I try to optimize with, 我尝试以

def cost(x):
    qv, t = x[:4], x[4:]
    return canonical_cost(qv, t, A, B, C, delta, epsilon, lam)

result = opt.least_squares(cost, initial_conditions, method='lm',
                               **kwargs)

Thank you 谢谢

As per my understanding, the LM algorithm performs sum of squares of the residual vector and tries to minimize that value. 根据我的理解,LM算法执行残差矢量的平方和,并尝试最小化该值。 We need to return a vector accordingly so that the sum of squares of the elements in that vector is minimized. 我们需要相应地返回一个向量,以使该向量中元素的平方和最小。 And the requirement of the size of this residual vector being more than the number of variables makes sense because it basically implies that number of unkno 并且要求此残差矢量的大小大于变量的数量是有道理的,因为它基本上暗示了未知数的数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM