简体   繁体   English

多维ODR配件

[英]Multi-dimensional ODR fitting

I want to fit M=2 sets of N=3 observations (X,Y) using scipy.odr in a single fitting step, from which I expect to get 2*M best-fit values (slope and intercept estimates within each of the M sets of observations). 我想在一个拟合步骤中使用scipy.odr拟合M = 2组N = 3个观测值(X,Y),从中我希望得到2*M最佳拟合值(每个模型中的斜率和截距估计值) M套观察值)。 From reading the scipy.odr documentation and a few related stackoverflow questions, it seems that this should be possible, but when I try using the following minimal example, the fitting fails to converge ( Reason(s) for Halting: NP < 1 or NP > N ). 通过阅读scipy.odr文档和一些相关的stackoverflow问题,似乎应该可以,但是当我尝试使用以下最小示例时,拟合无法收敛( Reason(s) for Halting: NP < 1 or NP > N )。

I'm starting with a reasonably good approximation of the best-fit beta values. 我从最合适的beta值的合理近似值开始。 Any ideas why this fails so miserably? 有什么想法为什么会如此惨败?

from pylab import *
from scipy import odr

x = array([[1.0,2.0,3.0],[1.1,2.1,3.1]])
y = array([[1.1,2.3,3.1],[5.9,7.0,8.2]])
sx = x*0 + .1
sy = y*0 + .1

def f(B, x):
    out = x * 0
    for k in range(x.shape[0]) :
        out[k,:] = B[2*k] * x[k,:] + B[2*k+1]
    return out

result = odr.ODR(
    odr.RealData( x, y, sx = sx, sy = sy ),
    odr.Model(f), beta0 = array([1.,0.,1.,5.])
    ).run()

result.pprint()

The error message has nothing to do with your start values. 该错误消息与您的起始值无关。 I am not sure if the ODR can handle this data, as it is virtually x,y,z . 我不确定ODR可以处理此数据,因为它实际上是x,y,z My interpretation is that it counts the members of x and y , which is N=2 each (arrays, but nevertheless) and compares this to your free parameters, which is NP=4 , so NP>N . 我的解释是,它计算xy的成员, xy每个成员均为N=2 (但仍然是数组),并将其与您的自由参数NP=4 ,因此NP>N

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

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