forum.alglib.net

ALGLIB forum
It is currently Mon Dec 23, 2024 7:06 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: nonlinear fitting:circle fuction
PostPosted: Tue Jun 19, 2012 7:24 pm 
Offline

Joined: Tue Jun 19, 2012 9:27 am
Posts: 10
Hello!
I really studied the manuals and the discussions in forum, but I did not found solution for my problem. My fitting program runs, but the solution of the parameters is strange.
I try to fit measured points with the function y=(r^2-(x-xm)^2)^(1/2)+ym ( upper half of a circle), because I scan a cylindrical object. I tried the example with lsfitcreatefg and lsfitcreatefgh, but both time the result I get is the same, namely as the initial value for the parametervector creal_1d_array c = "[9,9,4]" (expected [10,10,5])
The lsfitresults function puts the parameter 4 out, what means: gradient norm is no more than EpsG.
I tried to scale the parameters and to use bound constraints, but it does not work, I still get [9,9,4].
Please help me.


Attachments:
main.cpp [5.8 KiB]
Downloaded 754 times
main.rtf [8.93 KiB]
Downloaded 656 times
Top
 Profile  
 
 Post subject: Re: nonlinear fitting:circle fuction
PostPosted: Tue Jun 19, 2012 7:50 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Try to reformulate your problem. You tried to minimize sum of squared vertical distances from circle. But vertical distance is not good measure of fit quality.

For example, if you have (x,y) = (5,5) and R=4 - what is value of your merit function? f(x=5)=sqrt(4^2-5^2) = sqrt(-9) = 3*sqrt(-1). You can see that your target function is not defined for some reasonable values of R/xm/ym.

You should get better results with following parameterization: error(x_i, y_i, xm, ym, R) = (x_i-xm)^2+(y_i-ym)^2-R^2.


Top
 Profile  
 
 Post subject: Re: nonlinear fitting:circle fuction
PostPosted: Thu Jun 21, 2012 10:34 am 
Offline

Joined: Tue Jun 19, 2012 9:27 am
Posts: 10
Hello mr. Bochkanov!
Thank you very much for the fast response. I tried to ipliment your suggestion (I have chosen func=(x-x_m)^2+(y-y_m)^2-r^2 )and it works, but still I get the same results as before.
I just can't understand, why I always get the result of what I inserted as initial value, namely real_1d_array c = "[9,9,4.5]";


Attachments:
File comment: code
main1.rtf [6.34 KiB]
Downloaded 669 times
File comment: code
main1.cpp [3.54 KiB]
Downloaded 777 times
File comment: Here are some "pseudo measured" values. The values scatter +/- 4 micrometer(thats the precision of my Triangulationlaser) from the real cylinder dimensions (y_m=10,x_m=10, r=5).
graph_1.jpg
graph_1.jpg [ 54.33 KiB | Viewed 7635 times ]
Top
 Profile  
 
 Post subject: Re: nonlinear fitting:circle fuction
PostPosted: Thu Jun 21, 2012 2:16 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Upppppsss, I MUST have noticed it at the very beginning :) You have an error in the gradient calculation code. Your code is

Code:
    grad[0] = 2*(x[0]-c[0]);
    grad[1] = 2*(x[1]-c[1]);
    grad[2] = -2*c[2];


and it should be

Code:
    grad[0] = -2*(x[0]-c[0]);
    grad[1] = -2*(x[1]-c[1]);
    grad[2] = -2*c[2];


after fixing this mistake, everything works fine. In case you still have some problems, feel free to post them here :)


Top
 Profile  
 
 Post subject: Re: nonlinear fitting:circle fuction
PostPosted: Thu Jun 21, 2012 3:07 pm 
Offline

Joined: Tue Jun 19, 2012 9:27 am
Posts: 10
Dear mr. Bochkanov!
It works, I get super solution :-). You are wonderful!
If there is a way I can express my thankfullness, let me know.
Thank you, Thank you Thank you!


Top
 Profile  
 
 Post subject: Re: nonlinear fitting:circle fuction
PostPosted: Wed Nov 07, 2012 8:24 am 
Offline

Joined: Tue Jun 19, 2012 9:27 am
Posts: 10
Hallo Mr. Bochkanov,
I am again working on the projekt in the University. Still have to fit measured data with a circle function (x-x_m)^2 + (y-y_m)^2=r^2 . I thought I understood how to do it, but now I have many doubts. In the example I posted on June 19 th I calculated the values of real_1d_array y by inserting the values of real_2d_array x in (x-x_m)^2 + (y-y_m)^2-r^2.
Is it possible to find the parameters x_m,y_m and r without calculating the values real_1d_array y. So is there a way just to put measured values x_i in real_2d_array x and measured values y_i in real_1d_array y.

I tried to do it, with y=sqrt(sqr(r) -sqr(x-x_m)) - y_m as circle function, but it does not work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group