
Good curvefitting routine
I am looking for a reliable curve fitting routine (preferrably in C or C++). Currently I use LevenbergMarquardt routine from numerical recipes but it fails frequently. Your adivce will be appreciated.
 bobbym
 Administrator
Re: Good curvefitting routine
Hi JamesW;
Doesn't Numerical recipes have a least square routine?
Or why not try Octave, Maxima or geogebra they all have built in routines for least square curve fitting. Octave, uses LevenbergMarquardt!
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Hi bobbym
Thank you for your reply. The problem with these general packages is that they are not flexible to use especially when the fitting model is too complicated. I spent several days in vain trying to do the fitting by Matlab. I don't think these packages can do better than Matlab.
 bobbym
 Administrator
Re: Good curvefitting routine
Hi;
They sure can. Matlab is actually not even on my list. It actually is a very weak Computer Algebra system.
Some general questions:
1) This is a least squares fit or minimax or collocation?
2)What does one of your fitting models look like?
3) How many points are you fitting to?
4) The most important question, how many variables are you fitting for. Or how high is the degree of the polynomial you are fitting for. Because if you have more than 15 variables or higher than a 15 degree polynomial then least squares using the 1, x, x^2, x^3... as the basis is going to be a dismal failure in C++.
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Hi;
1) It is a least squares fit.
2) It consists of several Fano profiles (typically 5) superimposed on a logarithmic quadratic polynomial. It is not a simple model.
3) Between 30004000 points.
4) Typically 8 variables. The maximum is usually 13.
Do you think Octave, Maxima or geogebra can do this and which one would you recommend most.
By the way, I used LevenbergMarquardt from numerical recipes and it sometimes produces a very good fit, but in most cases it goes wild. I tried many tricks but no one can do the fitting in all cases correctly.
Many thanks for your advice
 bobbym
 Administrator
Re: Good curvefitting routine
Hi;
That is a monstrously over determined system ( more equations than unknowns )
but in most cases it goes wild. I tried many tricks but no one can do the fitting in all cases correctly.
Let me ask what you mean by correctly and a good fit. Take a look at the drawing below. You can click on it to make it larger. It represents a least squares fit through 11 points using a linear equation.
That may look like a bad, a very bad fit but it is actually a very good one. My point is, sometimes a fit that does not go through a single point is the best that can be done with the model you are using.
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Hi
I appreciate your point and agree with most of your post, but my problem is different because first my data have a very distinctive shape (profiles sitting on a background) and not like your data which are scattered. My aim is to try to fit a curve to be as close as possible to the original data points. What I get from LevenbergMarquardt in most cases is not an ideal fit because when I play with my initial values I get better fits (both visually and in a least squares sense). Because the model is complex and the data is large, I cannot afford playing with the initial values to get the 'best fit'. What I am looking for is some routine that is not easy to be trapped in local minima and could find its way to the global minimum spontaneously without interaction and manual adjustment.
 bobbym
 Administrator
Re: Good curvefitting routine
That is what I meant. If it is failing in a least square sense then it is failing.
Is the data in integer values or is it in decimal? If it is in decimal, what precision is it?
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
All the data are in decimal double precision.
 bobbym
 Administrator
Re: Good curvefitting routine
They are in (x,y) coordinate form?
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
 bobbym
 Administrator
Re: Good curvefitting routine
What kind of forms are you fitting for? Please give me one that failed.
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Hi bobbym
Can you recommend any good books on interpolation and/or curvefitting available online?
The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
 bobbym
 Administrator
Re: Good curvefitting routine
Hi;
Good books are hard to find. I have used the Scheid book on numerical analysis my whole life. Except for Forman's stuff it is the best ever written.
If you hunt around you might find it online. I did, I do not know where though or if it is still there.
I would be willing to go over it as we have done with everything else. Open up a thread and ask a question and I will be there.
Did you know that when I was your age or a little younger, curve fitting ( collocation ) was the reason I got into mathematics?
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
I attach examples for good and bad fits.
 bobbym
 Administrator
Re: Good curvefitting routine
I presume you are interested in the drawing on the right.
What equations did you use for those fits, right and left?
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Yes, I wish to get fits as good as the one on the right. In most cases I get fits between these two extremes.
In both cases I used 5 Fano profiles with a quadratic background. (Please refer to Fano resonance on Wiki)
 bobbym
 Administrator
Re: Good curvefitting routine
Hi James;
Here is the way I work. Slowly and step by step. Empirically coming to the solution (hopefully). That means experimentally, call me a dabbler if you like but that is what gets the cheese in numerical and computational analysis.
What does this mean to you? It means like your doctor you can not hold anything back from me. I have to know what you know. If the data you have for some reason you feel is secret then I can not assist. I need the equations you are using and hopefully the data.
I have worked on two jobs in my life that the person who hired me would not tell me what the job was for. Wished to keep everything a secret. It took ten times longer and the solution was not maximal. There is a guy in here right now who is asking me all kinds of questions about a roulette wheel. I am unable to help him any further because he is unwilling to provide the data.
I need to see and know everything about the job to have any chance of solving it. If this is impossible please let me know now.
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Hi bobbym
I have no secret project. Please give me your eamil and I will send you the data and the equations which I used to do these fittings.
Many thanks!
 bobbym
 Administrator
Re: Good curvefitting routine
Hi;
I have sent you an email. I have used the email you registered with.
I am going to go eat now and may the force be with me for your question.
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
Hi;
I sent the data and detailed description of the model. Please let me know if anything is missing or ambiguous.
Many thanks!
Re: Good curvefitting routine
bobbym wrote:Hi;
Good books are hard to find. I have used the Scheid book on numerical analysis my whole life. Except for Forman's stuff it is the best ever written.
If you hunt around you might find it online. I did, I do not know where though or if it is still there.
I would be willing to go over it as we have done with everything else. Open up a thread and ask a question and I will be there.
Did you know that when I was your age or a little younger, curve fitting ( collocation ) was the reason I got into mathematics?
I have found a book of his called Schaum's outline of theory and problems in numerical analysis. Is that the one?
The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
 bobbym
 Administrator
Re: Good curvefitting routine
Hi anonimnystefy;
Is it the 2nd edition?
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
Re: Good curvefitting routine
The limit operator is just an excuse for doing something you know you can't. “It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman “Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
 bobbym
 Administrator
Re: Good curvefitting routine
Hi;
Is it in english? I can not tell because it is already gone!
In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof.
