Re: IDL - EXP fitting function [message #65886] |
Fri, 27 March 2009 09:13 |
glen_andy
Messages: 4 Registered: March 2009
|
Junior Member |
|
|
On Mar 27, 9:03 am, Vince Hradil <vincehra...@gmail.com> wrote:
> On Mar 27, 8:50 am, Paolo <pgri...@gmail.com> wrote:
>
>
>
>
>
>> Vince Hradil wrote:
>>> On Mar 27, 8:27 am, Paolo <pgri...@gmail.com> wrote:
>>>> Vince Hradil wrote:
>>>> > On Mar 26, 5:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
>>>> > wrote:
>>>> > > Quoth glen_a...@hotmail.com:
>
>>>> > > > On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>>>> > > > > glen_a...@hotmail.com writes:
>>>> > > > > > Greetings everyone! My first post! I have some data x, y, that i would
>>>> > > > > > like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>>> > > > > > where a and b are constants which i would like found. Any ideas on how
>>>> > > > > > to do this?
>
>>>> > > > > ab = LinFit(x, y)
>>>> > > > > a = ab[0]
>>>> > > > > b = ab[1]
>
>>>> > > > > Cheers,
>
>>>> > > > > David
>>>> > > > > --
>>>> > > > > David Fanning, Ph.D.
>>>> > > > > Fanning Software Consulting, Inc.
>>>> > > > > Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> > > > > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>>>> > > > Thanks for getting back to me David,
>
>>>> > > > Does the linfit function work when i would like my data to be fitted to
>>>> > > > an EXP(a + bx) function? I didn't think that a linear function would be
>>>> > > > correct when considering the EXP? Or am i getting confused going from
>>>> > > > real space to log space!
>
>>>> > > No, linfit() fits a linear model of the form y = A + B*x, so it will not
>>>> > > "just work". why don't you just fit a linear model in logspace?
>
>>>> > > res = linfit(x, alog(yfit))
>>>> > > a = res[0]
>>>> > > b = res[1]
>
>>>> > > cheers
>>>> > > chris
>
>>>> > I'll second that. This is really a linear problem, so no need to
>>>> > solve the non-linear equation.
>
>>>> I disagree. If you have negative measurements, or positive
>>>> but very small measurements, you will get bad results.
>>>> Also the result will not be the least-squares best fit.
>
>>>> Ciao,
>>>> Paolo
>
>>> It can still be fit as a linear system - just weight the residuals by
>>> the measured values, like this:http://mathworld.wolfram.com/LeastSquaresFittingExponen tial.html
>
>> Interesting... but I still do not see how they handle negative
>> values...
>
>> Ciao,
>> Paolo
>
> How about using yiprime = yi - min(yi) + eps ? Or does that change
> the whole thing. It's too early - and I still have to get a cuppa.
> I'll be back 8^]- Hide quoted text -
>
> - Show quoted text -
Thanks guys for the suggestions. I dont need to worry about negative
values. Al;though i am considering small numbers. Typically in the
range between 1E-5 and 1. I am trying to fit to this function to match
a current method which has been applied to the same type of data sets
for modelling purposes. I am trying to compare experimental results to
that model and see how different the a abd b parameters have changed.
|
|
|
Re: IDL - EXP fitting function [message #65895 is a reply to message #65886] |
Fri, 27 March 2009 07:03  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Mar 27, 8:50 am, Paolo <pgri...@gmail.com> wrote:
> Vince Hradil wrote:
>> On Mar 27, 8:27 am, Paolo <pgri...@gmail.com> wrote:
>>> Vince Hradil wrote:
>>>> On Mar 26, 5:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
>>>> wrote:
>>>> > Quoth glen_a...@hotmail.com:
>
>>>> > > On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>>>> > > > glen_a...@hotmail.com writes:
>>>> > > > > Greetings everyone! My first post! I have some data x, y, that i would
>>>> > > > > like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>>> > > > > where a and b are constants which i would like found. Any ideas on how
>>>> > > > > to do this?
>
>>>> > > > ab = LinFit(x, y)
>>>> > > > a = ab[0]
>>>> > > > b = ab[1]
>
>>>> > > > Cheers,
>
>>>> > > > David
>>>> > > > --
>>>> > > > David Fanning, Ph.D.
>>>> > > > Fanning Software Consulting, Inc.
>>>> > > > Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> > > > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>>>> > > Thanks for getting back to me David,
>
>>>> > > Does the linfit function work when i would like my data to be fitted to
>>>> > > an EXP(a + bx) function? I didn't think that a linear function would be
>>>> > > correct when considering the EXP? Or am i getting confused going from
>>>> > > real space to log space!
>
>>>> > No, linfit() fits a linear model of the form y = A + B*x, so it will not
>>>> > "just work". why don't you just fit a linear model in logspace?
>
>>>> > res = linfit(x, alog(yfit))
>>>> > a = res[0]
>>>> > b = res[1]
>
>>>> > cheers
>>>> > chris
>
>>>> I'll second that. This is really a linear problem, so no need to
>>>> solve the non-linear equation.
>
>>> I disagree. If you have negative measurements, or positive
>>> but very small measurements, you will get bad results.
>>> Also the result will not be the least-squares best fit.
>
>>> Ciao,
>>> Paolo
>
>> It can still be fit as a linear system - just weight the residuals by
>> the measured values, like this:http://mathworld.wolfram.com/LeastSquaresFittingExponen tial.html
>
> Interesting... but I still do not see how they handle negative
> values...
>
> Ciao,
> Paolo
How about using yiprime = yi - min(yi) + eps ? Or does that change
the whole thing. It's too early - and I still have to get a cuppa.
I'll be back 8^]
|
|
|
Re: IDL - EXP fitting function [message #65896 is a reply to message #65895] |
Fri, 27 March 2009 06:50  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
Vince Hradil wrote:
> On Mar 27, 8:27 am, Paolo <pgri...@gmail.com> wrote:
>> Vince Hradil wrote:
>>> On Mar 26, 5:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
>>> wrote:
>>>> Quoth glen_a...@hotmail.com:
>>
>>>> > On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>>>> > > glen_a...@hotmail.com writes:
>>>> > > > Greetings everyone! My first post! I have some data x, y, that i would
>>>> > > > like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>>> > > > where a and b are constants which i would like found. Any ideas on how
>>>> > > > to do this?
>>
>>>> > > ab = LinFit(x, y)
>>>> > > a = ab[0]
>>>> > > b = ab[1]
>>
>>>> > > Cheers,
>>
>>>> > > David
>>>> > > --
>>>> > > David Fanning, Ph.D.
>>>> > > Fanning Software Consulting, Inc.
>>>> > > Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> > > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>>
>>>> > Thanks for getting back to me David,
>>
>>>> > Does the linfit function work when i would like my data to be fitted to
>>>> > an EXP(a + bx) function? I didn't think that a linear function would be
>>>> > correct when considering the EXP? Or am i getting confused going from
>>>> > real space to log space!
>>
>>>> No, linfit() fits a linear model of the form y = A + B*x, so it will not
>>>> "just work". why don't you just fit a linear model in logspace?
>>
>>>> res = linfit(x, alog(yfit))
>>>> a = res[0]
>>>> b = res[1]
>>
>>>> cheers
>>>> chris
>>
>>> I'll second that. This is really a linear problem, so no need to
>>> solve the non-linear equation.
>>
>> I disagree. If you have negative measurements, or positive
>> but very small measurements, you will get bad results.
>> Also the result will not be the least-squares best fit.
>>
>> Ciao,
>> Paolo
>
> It can still be fit as a linear system - just weight the residuals by
> the measured values, like this: http://mathworld.wolfram.com/LeastSquaresFittingExponential. html
Interesting... but I still do not see how they handle negative
values...
Ciao,
Paolo
|
|
|
Re: IDL - EXP fitting function [message #65897 is a reply to message #65896] |
Fri, 27 March 2009 06:38  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Mar 27, 8:27 am, Paolo <pgri...@gmail.com> wrote:
> Vince Hradil wrote:
>> On Mar 26, 5:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
>> wrote:
>>> Quoth glen_a...@hotmail.com:
>
>>>> On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>>>> > glen_a...@hotmail.com writes:
>>>> > > Greetings everyone! My first post! I have some data x, y, that i would
>>>> > > like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>>> > > where a and b are constants which i would like found. Any ideas on how
>>>> > > to do this?
>
>>>> > ab = LinFit(x, y)
>>>> > a = ab[0]
>>>> > b = ab[1]
>
>>>> > Cheers,
>
>>>> > David
>>>> > --
>>>> > David Fanning, Ph.D.
>>>> > Fanning Software Consulting, Inc.
>>>> > Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>>>> Thanks for getting back to me David,
>
>>>> Does the linfit function work when i would like my data to be fitted to
>>>> an EXP(a + bx) function? I didn't think that a linear function would be
>>>> correct when considering the EXP? Or am i getting confused going from
>>>> real space to log space!
>
>>> No, linfit() fits a linear model of the form y = A + B*x, so it will not
>>> "just work". why don't you just fit a linear model in logspace?
>
>>> res = linfit(x, alog(yfit))
>>> a = res[0]
>>> b = res[1]
>
>>> cheers
>>> chris
>
>> I'll second that. This is really a linear problem, so no need to
>> solve the non-linear equation.
>
> I disagree. If you have negative measurements, or positive
> but very small measurements, you will get bad results.
> Also the result will not be the least-squares best fit.
>
> Ciao,
> Paolo
It can still be fit as a linear system - just weight the residuals by
the measured values, like this: http://mathworld.wolfram.com/LeastSquaresFittingExponential. html
|
|
|
Re: IDL - EXP fitting function [message #65898 is a reply to message #65897] |
Fri, 27 March 2009 06:27  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
Vince Hradil wrote:
> On Mar 26, 5:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
> wrote:
>> Quoth glen_a...@hotmail.com:
>>
>>
>>
>>> On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>>>> glen_a...@hotmail.com writes:
>>>> > Greetings everyone! My first post! I have some data x, y, that i would
>>>> > like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>>> > where a and b are constants which i would like found. Any ideas on how
>>>> > to do this?
>>
>>>> ab = LinFit(x, y)
>>>> a = ab[0]
>>>> b = ab[1]
>>
>>>> Cheers,
>>
>>>> David
>>>> --
>>>> David Fanning, Ph.D.
>>>> Fanning Software Consulting, Inc.
>>>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>>
>>> Thanks for getting back to me David,
>>
>>> Does the linfit function work when i would like my data to be fitted to
>>> an EXP(a + bx) function? I didn't think that a linear function would be
>>> correct when considering the EXP? Or am i getting confused going from
>>> real space to log space!
>>
>> No, linfit() fits a linear model of the form y = A + B*x, so it will not
>> "just work". why don't you just fit a linear model in logspace?
>>
>> res = linfit(x, alog(yfit))
>> a = res[0]
>> b = res[1]
>>
>> cheers
>> chris
>
> I'll second that. This is really a linear problem, so no need to
> solve the non-linear equation.
I disagree. If you have negative measurements, or positive
but very small measurements, you will get bad results.
Also the result will not be the least-squares best fit.
Ciao,
Paolo
|
|
|
Re: IDL - EXP fitting function [message #65901 is a reply to message #65898] |
Fri, 27 March 2009 03:13  |
Maarten[1]
Messages: 176 Registered: November 2005
|
Senior Member |
|
|
On Mar 26, 11:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
wrote:
>> Does the linfit function work when i would like my data to be fitted to
>> an EXP(a + bx) function? I didn't think that a linear function would be
>> correct when considering the EXP? Or am i getting confused going from
>> real space to log space!
>
> No, linfit() fits a linear model of the form y = A + B*x, so it will not
> "just work". why don't you just fit a linear model in logspace?
>
> res = linfit(x, alog(yfit))
> a = res[0]
> b = res[1]
Be very careful with that. Small offsets (on measured data, usually
way below the noise level) will throw this fit way off. A non-linear
fit will probably give better results, especially if you have a
realistic error model (Poisson noise on a decay signal for instance).
At the very least plot the fit over the data, and plot the residuals
for visual inspection.
Maarten
|
|
|
Re: IDL - EXP fitting function [message #65905 is a reply to message #65901] |
Thu, 26 March 2009 19:11  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Mar 26, 5:55 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
wrote:
> Quoth glen_a...@hotmail.com:
>
>
>
>> On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>>> glen_a...@hotmail.com writes:
>>>> Greetings everyone! My first post! I have some data x, y, that i would
>>>> like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>>> where a and b are constants which i would like found. Any ideas on how
>>>> to do this?
>
>>> ab = LinFit(x, y)
>>> a = ab[0]
>>> b = ab[1]
>
>>> Cheers,
>
>>> David
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>> Thanks for getting back to me David,
>
>> Does the linfit function work when i would like my data to be fitted to
>> an EXP(a + bx) function? I didn't think that a linear function would be
>> correct when considering the EXP? Or am i getting confused going from
>> real space to log space!
>
> No, linfit() fits a linear model of the form y = A + B*x, so it will not
> "just work". why don't you just fit a linear model in logspace?
>
> res = linfit(x, alog(yfit))
> a = res[0]
> b = res[1]
>
> cheers
> chris
I'll second that. This is really a linear problem, so no need to
solve the non-linear equation.
|
|
|
Re: IDL - EXP fitting function [message #65914 is a reply to message #65905] |
Thu, 26 March 2009 15:55  |
Christopher Thom
Messages: 66 Registered: October 2006
|
Member |
|
|
Quoth glen_andy@hotmail.com:
> On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
>> glen_a...@hotmail.com writes:
>>> Greetings everyone! My first post! I have some data x, y, that i would
>>> like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>> where a and b are constants which i would like found. Any ideas on how
>>> to do this?
>>
>> ab = LinFit(x, y)
>> a = ab[0]
>> b = ab[1]
>>
>> Cheers,
>>
>> David
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Thanks for getting back to me David,
>
> Does the linfit function work when i would like my data to be fitted to
> an EXP(a + bx) function? I didn't think that a linear function would be
> correct when considering the EXP? Or am i getting confused going from
> real space to log space!
No, linfit() fits a linear model of the form y = A + B*x, so it will not
"just work". why don't you just fit a linear model in logspace?
res = linfit(x, alog(yfit))
a = res[0]
b = res[1]
cheers
chris
|
|
|
Re: IDL - EXP fitting function [message #65916 is a reply to message #65914] |
Thu, 26 March 2009 15:33  |
glen_andy
Messages: 4 Registered: March 2009
|
Junior Member |
|
|
On Mar 26, 5:15 pm, David Fanning <n...@dfanning.com> wrote:
> David Fanning writes:
>> glen_a...@hotmail.com writes:
>
>>> Greetings everyone! My first post! I have some data x, y, that i would
>>> like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>>> where a and b are constants which i would like found. Any ideas on how
>>> to do this?
>
>> ab = LinFit(x, y)
>> a = ab[0]
>> b = ab[1]
>
> Whoops! Hang on. Trying to do too many things at
> once. :-)
>
> Give me a couple of minutes and I'll see if I can
> find the right answer here. Didn't notice that
> EXPONENT thing there. :-(
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Its ok :-) and thank you.
|
|
|
Re: IDL - EXP fitting function [message #65917 is a reply to message #65916] |
Thu, 26 March 2009 15:25  |
glen_andy
Messages: 4 Registered: March 2009
|
Junior Member |
|
|
On Mar 26, 5:12 pm, David Fanning <n...@dfanning.com> wrote:
> glen_a...@hotmail.com writes:
>> Greetings everyone! My first post! I have some data x, y, that i would
>> like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>> where a and b are constants which i would like found. Any ideas on how
>> to do this?
>
> ab = LinFit(x, y)
> a = ab[0]
> b = ab[1]
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Thanks for getting back to me David,
Does the linfit function work when i would like my data to be fitted
to an EXP(a + bx) function? I didn't think that a linear function
would be correct when considering the EXP? Or am i getting confused
going from real space to log space!
Cheers
Andy
|
|
|
Re: IDL - EXP fitting function [message #65918 is a reply to message #65917] |
Thu, 26 March 2009 15:15  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> glen_andy@hotmail.com writes:
>
>> Greetings everyone! My first post! I have some data x, y, that i would
>> like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
>> where a and b are constants which i would like found. Any ideas on how
>> to do this?
>
> ab = LinFit(x, y)
> a = ab[0]
> b = ab[1]
Whoops! Hang on. Trying to do too many things at
once. :-)
Give me a couple of minutes and I'll see if I can
find the right answer here. Didn't notice that
EXPONENT thing there. :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: IDL - EXP fitting function [message #65919 is a reply to message #65918] |
Thu, 26 March 2009 15:12  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
glen_andy@hotmail.com writes:
> Greetings everyone! My first post! I have some data x, y, that i would
> like to fit to a fitting function of the kind yfit = EXP(a+ b*x).
> where a and b are constants which i would like found. Any ideas on how
> to do this?
ab = LinFit(x, y)
a = ab[0]
b = ab[1]
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|