Re: Missing data and MPFITFUN [message #50920 is a reply to message #50919] |
Mon, 23 October 2006 07:44   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
David Fanning <news@dfanning.com> writes:
> Allan Whiteford writes:
>
>> Set the weight of the missing data values to zero when doing the fit.
>
> Humm. There must be more to it than that. -(
> Consider this test program:
David, the data values should still be finite. Multiplying (VALUE*0)
= (NaN*0) is still NaN. Remove the NaNs, include zero-weights, and
you should be fine.
You might ask, why not ignore points with NaNs? The answer is, there
are two many people who were blithely allowing their data or model to
go infinite and then complaining to me when MPFIT didn't work. I
prefer to force the user to explicitly set the weight to zero for
points they want to ignore, rather than silently ignoring them. Then
if non-finite values show up, MPFIT knows it's a problem.
Perhaps I should add a /NAN keyword though.
Craig
>
> PRO TEST
> npts = 101
> time = Findgen(npts)
> signal = 4.3 * Findgen(npts)^2.52
> noisySignal = (Randomu(-3L, N_Elements(signal)) - 0.5) * 50000L + $
> signal
> noisySignal[ [ 3, 5, 22, 54, 66, 87] ] = !VALUES.F_NAN
> Plot, time, noisySignal, PSym=2
> model = 'p[0] * x^p[1]'
> error = Replicate(100, npts)
> params = [1.0,2.0]
> weights = Replicate(1.0, npts)
> weights[ [ 3, 5, 22, 54, 66, 87] ] = 0.0
> fit = MPFITEXPR(model, time, noisySignal, error, params, $
> WEIGHTS=weights)
> OPlot, time, fit[0] * Findgen(npts)^fit[1]
> END
>
> If you comment out the line where I set certain values
> to !VALUES.F_NAN the program works great. If I leave
> the line uncommented, it doesn't work so well, even
> though the WEIGHTS have been set to 0. :-(
>
> 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.")
--
------------------------------------
Craig Markwardt, Ph.D.
EMAIL: craigm@lheamail.gsfc.nasa.gov
------------------------------------
|
|
|