DSPRelated.com
Forums

any standard C library for curve fitting?

Started by anu22 November 18, 2011
Hi 

Does anyone know a good C library that i can use for implement a curve fit
. I want to to do a.) linear  b.) nonlinear power law decay type

linear one is very simple but i m not able to get a good fit parameters for
the non-linear case. i have implemented the numerical recipes in C
levenberg-Marquardt algorithm  and also the gnu gsl library one and for
some data sets it takes very long to converge.

any other method less sensitive to initial guess value or standard library
that would take lesser time to converge would be ideal for me. please
suggest !

thanks 
Anu
On Nov 18, 11:43&#4294967295;am, "anu22" <anu.p.selvaraj@n_o_s_p_a_m.gmail.com>
wrote:
> Hi > > Does anyone know a good C library that i can use for implement a curve fit > . I want to to do a.) linear &#4294967295;b.) nonlinear power law decay type > > linear one is very simple but i m not able to get a good fit parameters for > the non-linear case. i have implemented the numerical recipes in C > levenberg-Marquardt algorithm &#4294967295;and also the gnu gsl library one and for > some data sets it takes very long to converge. > > any other method less sensitive to initial guess value or standard library > that would take lesser time to converge would be ideal for me. please > suggest ! > > thanks > Anu
Hello Anu, Have you tried a linear fit to the logarithm of the data? Clay
Hi 

i have tried the logarithm one too it give me the fit but i need a more
accurate one! 

Anu

>On Nov 18, 11:43=A0am, "anu22" <anu.p.selvaraj@n_o_s_p_a_m.gmail.com> >wrote: >> Hi >> >> Does anyone know a good C library that i can use for implement a curve
fi=
>t >> . I want to to do a.) linear =A0b.) nonlinear power law decay type >> >> linear one is very simple but i m not able to get a good fit parameters
f=
>or >> the non-linear case. i have implemented the numerical recipes in C >> levenberg-Marquardt algorithm =A0and also the gnu gsl library one and
for
>> some data sets it takes very long to converge. >> >> any other method less sensitive to initial guess value or standard
librar=
>y >> that would take lesser time to converge would be ideal for me. please >> suggest ! >> >> thanks >> Anu > > >Hello Anu, > >Have you tried a linear fit to the logarithm of the data? > >Clay > > >
(snip, someone wrote, and moved up)
>>Have you tried a linear fit to the logarithm of the data?
(snip) anu22 <anu.p.selvaraj@n_o_s_p_a_m.gmail.com> wrote:
> i have tried the logarithm one too it give me the fit but i need > a more accurate one!
What do you mean by "more accurate?" If you really are fitting to an exponential, or exponential plus constant, then it should give accurate results. If you want "least squares" in the original (non-log) coordinates, then you add a weighting function to give the appropriate weight to each point. If the function can't be transformed such that it is linear in the coefficients (which doesn't mean the function needs to be linear) then you need to look into non-linear solvers, such as non-linear least squares. -- glen
anu22 wrote:
> Hi > > Does anyone know a good C library that i can use for implement a curve fit > I want to to do a.) linear b.) nonlinear power law decay type > > linear one is very simple but i m not able to get a good fit parameters for > the non-linear case. i have implemented the numerical recipes in C > levenberg-Marquardt algorithm and also the gnu gsl library one and for > some data sets it takes very long to converge. > > any other method less sensitive to initial guess value or standard library > that would take lesser time to converge would be ideal for me. please > suggest ! > > thanks > Anu
Why isn't Excel good enough? -- Les Cargill
On 18 Nov, 17:43, "anu22" <anu.p.selvaraj@n_o_s_p_a_m.gmail.com>
wrote:
> Hi > > Does anyone know a good C library that i can use for implement a curve fit > . I want to to do a.) linear &#4294967295;b.) nonlinear power law decay type
What does the power law look like? Can it be transformed to the linear form?
> linear one is very simple but i m not able to get a good fit parameters for > the non-linear case. i have implemented the numerical recipes in C > levenberg-Marquardt algorithm &#4294967295;and also the gnu gsl library one and for > some data sets it takes very long to converge.
That's how iterative methods work. You need to include various safeguards against limit cycles, as well as 'convergence enhancing' tricks. Numerical algorithms are as much art as science. Rune
On 11/18/2011 8:43 AM, anu22 wrote:
> Hi > > Does anyone know a good C library that i can use for implement a curve fit > . I want to to do a.) linear b.) nonlinear power law decay type > > linear one is very simple but i m not able to get a good fit parameters for > the non-linear case. i have implemented the numerical recipes in C > levenberg-Marquardt algorithm and also the gnu gsl library one and for > some data sets it takes very long to converge. > > any other method less sensitive to initial guess value or standard library > that would take lesser time to converge would be ideal for me. please > suggest ! > > thanks > Anu
Maybe this will help point you in a useful direction. "Choosing fitting algorithms" seems a useful guide: http://www.alglib.net/interpolation/leastsquares.php#header2 Fred
1: by accurate i meant  that i need to minimize the error by least square
on the non-log scale.
2: excel works good but i need the final result to be in c so i dont know
how excel performed the optimization , it isnt helpful


>(snip, someone wrote, and moved up) >>>Have you tried a linear fit to the logarithm of the data? > >(snip) >anu22 <anu.p.selvaraj@n_o_s_p_a_m.gmail.com> wrote: > >> i have tried the logarithm one too it give me the fit but i need >> a more accurate one! > >What do you mean by "more accurate?" > >If you really are fitting to an exponential, or exponential >plus constant, then it should give accurate results. > >If you want "least squares" in the original (non-log) coordinates, >then you add a weighting function to give the appropriate weight >to each point. > >If the function can't be transformed such that it is linear >in the coefficients (which doesn't mean the function needs to >be linear) then you need to look into non-linear solvers, such >as non-linear least squares. > >-- glen >
On 21 Nov, 17:52, "anu22" <anu.p.selvaraj@n_o_s_p_a_m.gmail.com>
wrote:
> 1: by accurate i meant &#4294967295;that i need to minimize the error by least square > on the non-log scale.
Why? Is that constraint so decisive that you rather skip the task than settle for a solution that minimizes the RMS in log scale?
> 2: excel works good but i need the final result to be in c so i dont know > how excel performed the optimization , it isnt helpful
Fair enough; chances are that Excel optimizes the log transformed data anyway. The simple 1D linear solvers are fairly easy to implement in C. Again, get your priorities straight: What is more important? - A solution implemented in C? - A solution that minimizes the error in non-transformed domain? - A solution that is available for free? If you have $$$ to spend on this, it shouldn't be too hard to find something. Intel used to provide several numerical libraries where one might expect to find this kind of functionality. First of all, don't top post! Rune
(after I wrote)
>>If you want "least squares" in the original (non-log) coordinates, >>then you add a weighting function to give the appropriate weight >>to each point.
anu22 <anu.p.selvaraj@n_o_s_p_a_m.gmail.com> wrote:
> 1: by accurate i meant that i need to minimize the error by least square > on the non-log scale.
> 2: excel works good but i need the final result to be in c so i dont know > how excel performed the optimization , it isnt helpful
Last I knew, excel does the unweighted fit in log coordinates. I don't remember if it has an option to supply your own weights. This is usually described in books with titles similar to Statistical Treatment of Experimental Data. Reasonably often people are happy with the unweighted version, but if you want least-squares in the non-log coordinate, weighting will do it. You can also weight based on the uncertainty (error bars) of the data points. -- glen