comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Curvefit
items: Re: Curvefit
items: Re: curvefit
items: Re: CURVEFIT

Curvefit
type: item
description: Hi, I use CURVEFIT (on PV-WAVE CL Version 6.05 (sun4 solaris sparc)) to perform non-linear least sqares fitting. It works rather well, but once the fit is performed, the vector of standard deviations for parameters (named Sigmaa) seems to give very large values: for a given set of data, the error on parameters is ten times greater with Curvefit than, for exemple, with Kaleidagraph. In fact, Curvefit is based on the Gradient-expansion algorithm, and the way the programm calculates the error (i.e SIGMAA = SQRT(ARRAY(DIAG)/ALPHA(DIAG)) ) is perharps wrong (something missing ???). Does anybody has an idea ? Thanks for help. J.Marc _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/_/_/_/ Jean-Marc Zanotti _/ _/_/_/ _/_/_/_/ Laboratoire Leon Brillouin _/_/_/_/ _/_/_/_/ C.E.A Saclay _/_/_/_/ _/_/_/_/ F-91191 Gif-sur-Yvette Cedex _/_/_/_/ _/_/_/_/ _/_/_/_/ _/_/_/_/ Tel:(33)(0)1-69-08-97-01 _/_/_/_/ _/_/_/_/ Fax:(33)(0)1-69-08-82-61 _/_/_/_/ _/_/_/_/ Email: zanotti@bali.saclay.cea.fr _/_/_/_/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
creator: zanotti
date: 1997-05-21T07:00:00-00:00

Re: Curvefit
type: item
description: zanotti@bali.saclay.cea.fr (J.M. Zanotti) writes: > Hi, > I use CURVEFIT (on PV-WAVE CL Version 6.05 (sun4 solaris sparc)) to perform > non-linear least sqares fitting. It works rather well, but once the fit is > performed, the vector of standard deviations for parameters (named Sigmaa) > seems to give very large values: > for a given set of data, the error on parameters is ten times greater with > Curvefit than, for exemple, with Kaleidagraph. > In fact, Curvefit is based on the Gradient-expansion algorithm, and the way > the programm calculates the error (i.e SIGMAA = SQRT(ARRAY(DIAG)/ALPHA(DIAG)) > ) is perharps wrong (something missing ???). > Does anybody has an idea ? It probably depends on the weighting function that you give it. If the weights are related to true errors on the measurements, i.e. 1/sigma^2, then the SIGMAA values should normally be realistic. However, if the weights have an arbitrary normalization, then the SIGMAA values will also be off. A good test is to look at the chi-squared value, which is returned in the keyword CHI2. Realistic weights should result in a chi-squared close to 1. If far away from 1, then the SIGMAA values will be off as well. One way to adjust for this is to multiply the SIGMAA values by SQRT(CHI2). Bill Thompson
creator: thompson
date: 1997-05-21T07:00:00-00:00

Re: curvefit
type: item
description: tom (tom2959@21cn.com) writes: > there are only two program in IDL which can be used to fit curves with > non-linear least squares method. Sometimes they work not well. Are there any > other programs to do such work? I'd have a look at Curve Fit Central: http://cow.physics.wisc.edu/~craigm/idl/fitting.html Cheers, David -- David W. Fanning, Ph.D. Fanning Software Consulting, Inc. Phone: 970-221-0438, E-mail: david@dfanning.com Coyote's Guide to IDL Programming: http://www.dfanning.com/ Toll-Free IDL Book Orders: 1-888-461-0155
creator: David Fanning
date: 2003-01-08T04:13:05-00:00

Re: CURVEFIT
type: item
description: In article <c9krj3$3r5$1@news.urz.uni-heidelberg.de>, Andreas Ernst <aernst@ari.nis> wrote: > Hi, > > (1) I am using CURVEFIT to fit a straight line > through my data points.> > (2) I had problems with fitting data points with > polynomials higher than third order, like fourth > or fifth order. Is this problem known? For polynomial fits, you could try REGRESS (or LINFIT or POLY_FIT). Ken Bowman
creator: K. Bowman
date: 2004-06-02T15:56:43-00:00

Re: CURVEFIT
type: item
description: Andreas Ernst <aernst@ari.nis> writes: > Hi, > > (1) I am using CURVEFIT to fit a straight line > through my data points. My user-supplied > function looks like this: > > PRO gerade, X, A, F, PDER > F=A[0]+A[1]*X > IF N_PARAMS() GE 4 THEN $ > PDER = [[REPLICATE(1.0, N_ELEMENTS(X))], [X]] > RETURN > END > > Anyway, even though it defines a straight line, > the routine CURVEFIT seems to fit some other > curve through the data points, which is something A linear fit is trivial, and CURVEFIT shouldn't produce problems like you found. My guess is that it is more likely that you have a data handling problem. For example, if you perform a data selection on the X values but forget to do the same for the Y values. As the other poster said, you can use LINFIT/POLYFIT* to do the simple fits you desire. For more complicated fits, or as a cross check, you can use my own fitting program, MPFIT + MPCURVEFIT, which have a wide acknowledgement in the IDL community. As a combination, they are a drop-in replacement for CURVEFIT (although if you don't have the requirement to keep CURVEFIT compatibility, then I recommend using MPFITFUN). Happy fitting! Craig -- ------------------------------------------------------------ -------------- Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response ------------------------------------------------------------ --------------
creator: Craig Markwardt
date: 2004-06-02T18:40:37-00:00

Re: curvefit
type: item
description: nolan.smith1@gmail.com wrote: > Hello, > > I am new in IDL and I am trying to fit my data (x,y coordinates) in a > function of this form: > > y(x)=A/[(1+x/B)^1/2]^2 > > so that I can calculate A and B. > > I have read the documentation but I am very confused as to how I should > set up my function to use it at the curvefit. > Could you please explain to me how to set up the function and how to > use curvefit correctly? > > Thank you, > Nolan Smith > Most people use Craig Markwardt's fitting routines rather than the ones provided with IDL: http://cow.physics.wisc.edu/~craigm/idl/idl.html Good luck, Benjamin
creator: Benjamin Hornberger
date: 2005-06-13T19:46:33-00:00

Re: curvefit
type: item
description: Thank you. I had already looked at those routines as well but the problems I had with those routines were the same with the curvefit routine. I do not know how set up the function correctly and use it in the curvefit or mpcurvefit program. Any help will be greatly appreciated. Thank you, Nolan
creator: nolan.smith1
date: 2005-06-13T19:59:36-00:00

Re: curvefit
type: item
description: In article <1118691431.765056.244800@f14g2000cwb.googlegroups.com>, <nolan.smith1@gmail.com> wrote: > Hello, > > I am new in IDL and I am trying to fit my data (x,y coordinates) in a > function of this form: > > y(x)=A/[(1+x/B)^1/2]^2 > > so that I can calculate A and B. > > I have read the documentation but I am very confused as to how I should > set up my function to use it at the curvefit. > Could you please explain to me how to set up the function and how to > use curvefit correctly? > > Thank you, > Nolan Smith > Create a new procedure, say testfun.pro: pro testfun,x,y,par,dfdpar y=par[0]/((1+x/par[1])^(1./2.))^2 ;question: why is this not y=par[0]/(1+x/par[1]) ? dfdpar=fltarr(n_elements(x),2) dfdpar[*,0]=y/par[0] dfdpar[*,1]= {partial}y/{partial}B .. ;calculation left as an exercise for the reader! return end and then call curvefit as yfit=curvefit(x,y,weights,par,function_name='testfun') vinay -- ____________________________________________________________ __________________ kashyap@head.cfa.harvard.edu 617 495 7173 [CfA/P-145] 617 496 7173 [F]
creator: kashyap
date: 2005-06-13T21:50:12-00:00

Re: curvefit
type: item
description: nolan.smith1@gmail.com writes: > Thank you. I had already looked at those routines as well but the > problems I had with those routines were the same with the curvefit > routine. > I do not know how set up the function correctly and use it in the > curvefit or mpcurvefit program. Greetings, Did this tutorial page not help? http://cow.physics.wisc.edu/~craigm/idl/mpfittut.html Yours, Craig -- ------------------------------------------------------------ -------------- Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response ------------------------------------------------------------ --------------
creator: Craig Markwardt
date: 2005-06-13T22:24:38-00:00

Re: curvefit
type: item
description: It was really helpful. I just wanted a little more details on how to set up the function but now I understand it better. Thank you for the help, Nolan
creator: nolan.smith1
date: 2005-06-14T03:07:34-00:00

Re: curvefit
type: item
description: Thank you! I had a little typo in the function that I gave you, it is y(x)=A/(1+x/B)^2. Your answer was really helpful so thanks again!!! Nolan Vinay L. Kashyap wrote: > In article <1118691431.765056.244800@f14g2000cwb.googlegroups.com>, > <nolan.smith1@gmail.com> wrote: >> Hello, >> >> I am new in IDL and I am trying to fit my data (x,y coordinates) in a >> function of this form: >> >> y(x)=A/[(1+x/B)^1/2]^2 >> >> so that I can calculate A and B. >> >> I have read the documentation but I am very confused as to how I should >> set up my function to use it at the curvefit. >> Could you please explain to me how to set up the function and how to >> use curvefit correctly? >> >> Thank you, >> Nolan Smith >> > > Create a new procedure, say testfun.pro: > > pro testfun,x,y,par,dfdpar > y=par[0]/((1+x/par[1])^(1./2.))^2 > ;question: why is this not y=par[0]/(1+x/par[1]) ? > dfdpar=fltarr(n_elements(x),2) > dfdpar[*,0]=y/par[0] > dfdpar[*,1]= {partial}y/{partial}B .. > ;calculation left as an exercise for the reader! > return > end > > and then call curvefit as > yfit=curvefit(x,y,weights,par,function_name='testfun') > > vinay > -- > ____________________________________________________________ __________________ > kashyap@head.cfa.harvard.edu 617 495 7173 [CfA/P-145] 617 496 7173 [F]
creator: nolan.smith1
date: 2005-06-14T04:02:00-00:00

Re: curvefit
type: item
description: I spoke too soon! So I have set up my function: (the model I am trying to fit is y=a/((1+(x/b))^2) ) FUNCTION myfun,X,P RETURN,P(0)/(1+(X/P(1))^2) END and then I try to run result=MPFITFUN('myfun',x,y,0.5,0.01) Where x,y are my x,y coordinates of the data that I am trying to fit, 0.5 is the first guess for P(0) and 0.01 is the first guess for P(1). As you guessed it is not working. What am I doing wrong? Thank you, Nolan
creator: nolan.smith1
date: 2005-06-14T15:20:58-00:00

Re: curvefit
type: item
description: nolan.smith1@gmail.com wrote: > I spoke too soon! > So I have set up my function: > (the model I am trying to fit is y=a/((1+(x/b))^2) ) > > FUNCTION myfun,X,P > RETURN,P(0)/(1+(X/P(1))^2) > END > > and then I try to run > > result=MPFITFUN('myfun',x,y,0.5,0.01) The 4th argument should be an array with the errors on y and the 5th argument an array with the estimates for the parameters, so try something like: err=replicate(1,n_elements(x));constant errors in y par=[0.5,0.01];parameter estimate result=MPFITFUN('myfun',x,y,err,par) > > Where x,y are my x,y coordinates of the data that I am trying to fit, > 0.5 is the first guess for P(0) and 0.01 is the first guess for P(1). > As you guessed it is not working. What am I doing wrong? > > Thank you, > Nolan >
creator: Paolo Grigis
date: 2005-06-14T16:16:38-00:00