Re: Minimization: Determine a constant across data sets [message #79806] |
Tue, 10 April 2012 11:24 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Tuesday, April 10, 2012 10:58:52 AM UTC-4, justinr...@gmail.com wrote:
> On Thursday, April 5, 2012 10:42:40 PM UTC-4, Justin wrote:
>> Hi all!
>>
>> I have several data sets that follow the form:
>>
>> data = A* e^(-t/t0)+ y
>>
>> I suspect EVERY data set to have the same t0, but different A & y values. (ie: (A1,y1),(A2,y2)...)
>> I can use MPFITFUN to fit A,t0 and y, but the routine determines a least chi-squared such that t0 is different for every data set.
>>
>> It would seem simple enough to fix t0 in MPFITFUN if I knew what the value was beforehand, but I don't :) Is there a way to minimize t0 across several data sets such that A & y are allowed to vary, but t0 is tied to every data set?
>>
>> I tried doing this in grids, but it was very computationally time consuming to search an unknown gridspace of t0 in an double for loop.
>>
>>
>> Thanks!
>> Justin
>
>
>
> On Thursday, April 5, 2012 10:42:40 PM UTC-4, Justin wrote:
>> Hi all!
>>
>> I have several data sets that follow the form:
>>
>> data = A* e^(-t/t0)+ y
>>
>> I suspect EVERY data set to have the same t0, but different A & y values. (ie: (A1,y1),(A2,y2)...)
>> I can use MPFITFUN to fit A,t0 and y, but the routine determines a least chi-squared such that t0 is different for every data set.
>>
>> It would seem simple enough to fix t0 in MPFITFUN if I knew what the value was beforehand, but I don't :) Is there a way to minimize t0 across several data sets such that A & y are allowed to vary, but t0 is tied to every data set?
>>
>> I tried doing this in grids, but it was very computationally time consuming to search an unknown gridspace of t0 in an double for loop.
>>
>>
>> Thanks!
>> Justin
>
> Awesome, I think I got it. Took a while to get the dimensions to agree.
>
> result=mpfitfun('myfun',x,y(*,*),1.,guess,bestnorm=chisq)
>
> FUNCTION myfun, X, P
> ;create the function from the inputs
> s=size(p)
> cols=(s(1)-1)/2
> model=dblarr(cols,n_elements(x))
> for i=0, cols-1 do begin
> model(i,*)=[P[i]* EXP(-x/P[cols])+P[i+cols+1] ]
> endfor
> RETURN, model
Now you are an advanced MPFIT user :-)
|
|
|
Re: Minimization: Determine a constant across data sets [message #79813 is a reply to message #79806] |
Tue, 10 April 2012 07:58  |
Justin Cantrell
Messages: 5 Registered: May 2010
|
Junior Member |
|
|
On Thursday, April 5, 2012 10:42:40 PM UTC-4, Justin wrote:
> Hi all!
>
> I have several data sets that follow the form:
>
> data = A* e^(-t/t0)+ y
>
> I suspect EVERY data set to have the same t0, but different A & y values. (ie: (A1,y1),(A2,y2)...)
> I can use MPFITFUN to fit A,t0 and y, but the routine determines a least chi-squared such that t0 is different for every data set.
>
> It would seem simple enough to fix t0 in MPFITFUN if I knew what the value was beforehand, but I don't :) Is there a way to minimize t0 across several data sets such that A & y are allowed to vary, but t0 is tied to every data set?
>
> I tried doing this in grids, but it was very computationally time consuming to search an unknown gridspace of t0 in an double for loop.
>
>
> Thanks!
> Justin
On Thursday, April 5, 2012 10:42:40 PM UTC-4, Justin wrote:
> Hi all!
>
> I have several data sets that follow the form:
>
> data = A* e^(-t/t0)+ y
>
> I suspect EVERY data set to have the same t0, but different A & y values. (ie: (A1,y1),(A2,y2)...)
> I can use MPFITFUN to fit A,t0 and y, but the routine determines a least chi-squared such that t0 is different for every data set.
>
> It would seem simple enough to fix t0 in MPFITFUN if I knew what the value was beforehand, but I don't :) Is there a way to minimize t0 across several data sets such that A & y are allowed to vary, but t0 is tied to every data set?
>
> I tried doing this in grids, but it was very computationally time consuming to search an unknown gridspace of t0 in an double for loop.
>
>
> Thanks!
> Justin
Awesome, I think I got it. Took a while to get the dimensions to agree.
result=mpfitfun('myfun',x,y(*,*),1.,guess,bestnorm=chisq)
FUNCTION myfun, X, P
;create the function from the inputs
s=size(p)
cols=(s(1)-1)/2
model=dblarr(cols,n_elements(x))
for i=0, cols-1 do begin
model(i,*)=[P[i]* EXP(-x/P[cols])+P[i+cols+1] ]
endfor
RETURN, model
END
|
|
|
Re: Minimization: Determine a constant across data sets [message #79829 is a reply to message #79813] |
Sat, 07 April 2012 20:05  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Friday, April 6, 2012 5:43:33 AM UTC-4, Mats Löfdahl wrote:
> Den fredagen den 6:e april 2012 kl. 04:42:40 UTC+2 skrev Justin:
>> Hi all!
>>
>> I have several data sets that follow the form:
>>
>> data = A* e^(-t/t0)+ y
>>
>> I suspect EVERY data set to have the same t0, but different A & y values. (ie: (A1,y1),(A2,y2)...)
>> I can use MPFITFUN to fit A,t0 and y, but the routine determines a least chi-squared such that t0 is different for every data set.
>>
>> It would seem simple enough to fix t0 in MPFITFUN if I knew what the value was beforehand, but I don't :) Is there a way to minimize t0 across several data sets such that A & y are allowed to vary, but t0 is tied to every data set?
>
> Sounds like you could describe your problem something like this:
>
> data = [data1, data2, data3, ...]
> model = [A1*e^(-t,t0)+y1, A2*e^(-t/t0)+y2, A3*e^(t/t0), ...]
>
> If you code the model MYFUNCT with the parameter array interpreted as
> p[0,1,2,3,...]=[t0,A1,y1,A2,y2,...]
> you should be able to keep using mpfitfun.
Yep, what Mats said.
MPFIT and MPFITFUN don't care how many data sets you are fitting. Just concatenate the two data sets and the two model functions. (and the hardest part is managing all of the parameters.)
Craig Markwardt
|
|
|
Re: Minimization: Determine a constant across data sets [message #79842 is a reply to message #79829] |
Fri, 06 April 2012 02:43  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den fredagen den 6:e april 2012 kl. 04:42:40 UTC+2 skrev Justin:
> Hi all!
>
> I have several data sets that follow the form:
>
> data = A* e^(-t/t0)+ y
>
> I suspect EVERY data set to have the same t0, but different A & y values. (ie: (A1,y1),(A2,y2)...)
> I can use MPFITFUN to fit A,t0 and y, but the routine determines a least chi-squared such that t0 is different for every data set.
>
> It would seem simple enough to fix t0 in MPFITFUN if I knew what the value was beforehand, but I don't :) Is there a way to minimize t0 across several data sets such that A & y are allowed to vary, but t0 is tied to every data set?
Sounds like you could describe your problem something like this:
data = [data1, data2, data3, ...]
model = [A1*e^(-t,t0)+y1, A2*e^(-t/t0)+y2, A3*e^(t/t0), ...]
If you code the model MYFUNCT with the parameter array interpreted as
p[0,1,2,3,...]=[t0,A1,y1,A2,y2,...]
you should be able to keep using mpfitfun.
/Mats
|
|
|