[SciPy-User] Orthogonal distance regression in 3D

Robert Kern robert.kern@gmail....
Fri Mar 2 05:48:40 CST 2012


On Fri, Mar 2, 2012 at 06:02, Владимир <draft2008@bk.ru> wrote:
> Hello!
> I'm working with orthogonal distance regression (scipy.odr).
> I try to fit the curve to a point cloud (3d), but it doesn work properly, it
> returns wrong results
>
> For example I want to fit the simple curve y = a*x + b*z + c to some point
> cloud (y_data, x_data, z_data)
>
>
>     def func(p, input):
>
>     x,z = input
>
>     x = np.array(x)
>
>     z = np.array(z)
>
>     return (p[0]*x + p[1]*z + p[2])
>
>
>     initialGuess = [1,1,1]
>
>     myModel = Model(func)
>
>     myData = Data([x_data, z_daya], y_data)
>
>     myOdr = ODR(myData, myModel, beta0 = initialGuess)
>
>     myOdr.set_job(fit_type=0)
>
>     out = myOdr.run()
>
>     print out.beta
>
> It works perfectly in 2d dimension (2 axes), but in 3d dimension the results
> are not even close to real, moreover it is very sensitive to initial Guess,
> so it returns different result even if i change InitiaGuess from [1,1,1]
> to [0.99,1,1]
>
> What do I do wrong?

Can you provide a complete runnable example including some data? Note
that if you do not specify any errors on your data, they are assumed
to correspond to a standard deviation of 1 for all dimensions. If that
is wildly different from the actual variance around the "true"
surface, then it might lead the optimizer astray.

-- 
Robert Kern


More information about the SciPy-User mailing list