comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » MPfit question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: MPFIT question [message #64747 is a reply to message #62623] Wed, 14 January 2009 23:52 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Jan 14, 4:37 pm, "j.coe...@gmail.com" <j.coe...@gmail.com> wrote:
> The user function has help statements at its beginning and end now,
> and I tried the other suggestions, but I'm still stumped.  I'm doing
> something foolish.
>
> Below is the problem code.  Most of it is just the 353-element data
> array.  Without the data, it's only two short functions, 20 lines of
> code or so total.  I hope it's not bad netiquette to post so many
> lines.  I can't figure out why these data crash the program.  I can
> fit most other data acquired in this manner -- I have fit hundreds of
> thousands of these curves with this method, but the error crops up
> once every 50 cases or so (usually for data that don't fit the model
> very well, but it still shouldn't crash?).
>
> The data are being fit to a gamma variate function.  Two things I'm
> not sure about: (1) I'm passing t0 as a fitting parameter, and I'm not
> sure if this is acceptable.  (2)  Worse, I don't have a good idea of
> how to estimate error, so I'm just using the standard deviation of the
> baseline (pre-arrival) curve, which is probably wrong.  Suggestions?
>
> The code crashes after just two MPFIT iterations.  Just type
> 'MPFIT_problem' to run.
>
> Thanks for any help.
>
> ------------------------------------
>
> function gamma_variate, x, p
>
> print, 'p start...'
> help, p
>
> baseline = p[0]
> t0 = p[1]
> tmax = p[2]             ; time of peak signal
> smax = p[3]             ; signal max in mVolts
> alpha = p[4]
>
>         ; shift time, apply gamma variate only to data after t0
>
> wh = Where(x GE t0, ct)
> t = (x - t0)[wh]
> tmax = tmax - t0
>
>         ; gamma variate function
>
> s = baseline + (smax) * (tmax^(-alpha)) * exp(alpha) * (t^alpha) *  exp
> ((-alpha)  * t / tmax)
>
>         ; add the pre-t0 data (baseline)
>
> n = n_elements(x)
> pre = make_array(n - ct, Value = baseline)
> s = [pre, s]

Thanks for your complete example, very useful!

Your function is crashing at the MAKE_ARRAY stage. This is because N
EQ CT, so you are asking for an empty array.

After the error occurs, MPFITFUN() returns !NaN, in addition to error
status keywords. Since you don't trap the error codes, execution
proceeds to the next statement which attempts to evaluate GAMMA_VARIATE
(T, !NaN).

So the lessons learned are:
* validity checking before MAKE_ARRAY
* error checking after MPFITFUN returns

Good luck!
Craig
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Trouble writing very large files
Next Topic: Recording batch commands

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:05:48 PDT 2025

Total time taken to generate the page: 0.00477 seconds