[SciPy-User] Orthogonal distance regression in 3D

136 views
Skip to first unread message

Владимир

unread,
Mar 2, 2012, 1:02:43 AM3/2/12
to scipy...@scipy.org
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?
 
Im not very strong in mathematics, but may be I should specify some additional parameters such as Jacobian matrix or weight matrix or something else?

Robert Kern

unread,
Mar 2, 2012, 6:48:40 AM3/2/12
to Владимир, SciPy Users List
On Fri, Mar 2, 2012 at 06:02, Владимир <draf...@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
_______________________________________________
SciPy-User mailing list
SciPy...@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

Reply all
Reply to author
Forward
0 new messages