Incorrect behavior of /NAN [message #30033] |
Thu, 04 April 2002 07:40  |
K. Bowman
Messages: 330 Registered: May 2000
|
Senior Member |
|
|
I tried to incite some interest in this last week, but had no takers,
so I'll try again. ;-)
I believe that the behavior of the TOTAL function is incorrect in
the case where all of the data are NaN and the /NAN keyword is set.
Here are several possible cases:
IDL> a = !values.f_nan
IDL> print, total([a, 1.0])
NaN
IDL> print, total([a, 1.0], /nan)
1.00000
IDL> print, total([a, a])
NaN
IDL> print, total([a, a], /nan)
0.00000
I believe that the last case is incorrect.
The documentation for /NAN says "Elements with the value NaN are treated
as missing data." In the last case there are no valid data, so how can
their sum be zero?
I think this is probably a simple error in the TOTAL algorithm.
Rather than computing the "sum of all the non-NaN values", it is
probably doing "set sum to zero and then add all non-Nan values".
For comparison, the MEAN function does not behave this way.
IDL> print, mean([a, 1.0])
NaN
IDL> print, mean([a, 1.0], /nan)
1.00000
IDL> print, mean([a, a])
NaN
IDL> print, mean([a, a], /nan)
NaN
Before I submit something (at least a question) to RSI, does anyone
have comments?
Ken Bowman
|
|
|
|
|
|
|
|
Re: Incorrect behavior of /NAN [message #30145 is a reply to message #30033] |
Fri, 05 April 2002 13:53   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Kenneth Bowman <k-bowman@null.tamu.edu> writes:
> In article <onofgz74jo.fsf@cow.physics.wisc.edu>,
> Craig Markwardt <craigmnet@cow.physics.wisc.edu> wrote:
>
>> If all the data are missing, how can the sum be NaN? Neither a return
>> value of 0, nor a return value of NaN, seems to be appropriate to
>> me. This appears to be an undefined case.
>
> If NaN represents missing data, and all of the data are missing, then the
> total is missing also, so it seems reasonable to me to return NaN.
:-)
I could easily argue the other way, in terms of reasonableness. The
sum of "no" numbers is zero.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
|
|
Re: Incorrect behavior of /NAN [message #30238 is a reply to message #30033] |
Mon, 15 April 2002 06:47  |
K. Bowman
Messages: 330 Registered: May 2000
|
Senior Member |
|
|
In article <yx6hvgatn3vp.fsf@socrates.Berkeley.EDU>,
noymer@socrates.Berkeley.EDU wrote:
> NaN is an IEEE standard, is it not?
>
> Does the IEEE define what to do in such cases?
>
> It seems to me that IDL should conform to such a standard, if it exists,
> even if it goes against our intuition.
As far as I know, IDL correctly does arithmetic involving NaNs
(i.e., it returns NaNs, etc.).
But IDL also uses NaNs as "missing values", which is not an IEEE issue,
and the behavior here is not clearly defined in some cases.
Ken
|
|
|
Re: Incorrect behavior of /NAN [message #30243 is a reply to message #30033] |
Sun, 14 April 2002 18:32  |
noymer
Messages: 65 Registered: June 1999
|
Member |
|
|
NaN is an IEEE standard, is it not?
Does the IEEE define what to do in such cases?
It seems to me that IDL should conform to such a standard, if it exists,
even if it goes against our intuition.
That said, doing a google on IEEE 754 and NaN and sum didn't turn up a
definitive answer (but I didn't look at all of the over 1,000 pages
google found).
Just my $0.02
Andrew
|
|
|