[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: handling NaN
From: |
John W. Eaton |
Subject: |
Re: handling NaN |
Date: |
Thu, 8 Aug 2002 11:39:38 -0500 |
On 8-Aug-2002, Paul Kienzle <address@hidden> wrote:
| The consequences are that MISSING VALUES should be omitted by
| default. NaNs are not missing values in many (most) computations,
| but instead are things that inform you that your computation has
| gone awry. If your code does not explicitly deal with these
| problems itself (e.g., by using nanfun) then the invalid value
| should be propogated back to somewhere that the user can see it.
I agree with this, which is why I'm reluctant to make Octave's
functions ignore NaN by default.
| One suggestion is to define a constant NA to represent missing values. These
| could then be ignored in all the stats functions. I believe this would work
| well enough, except for the people coming from matlab who want to use NaN to
| represent missing values.
In R, they have NA as a special NaN value. For some time, I thought
it might be better to have a special NA data type that would not rely
on tricks like this. But I'm not sure that it is worth the effort.
Now, I think that having a special type means adding a lot of bloat.
So, how about adding an R-compatible NA value to Octave? I have a
patch that does this for doubles, but that's probably all that is
needed since most things in Octave are done on doubles anyway, right?
I know that R has an NA_INTEGER value (at least internally) that is
currently represented by INT_MIN, but to me, that seems like a less
reliable thing to do, so I'd rather not if we don't need it.
In any case, with my current patch, Octave does this:
octave:1> x = [Inf, NaN, 13, NA]
x =
Inf NaN 13.000 NA
octave:2> isnan (x)
ans =
0 1 0 0
octave:3> isinf (x)
ans =
1 0 0 0
octave:4> is_NA (x)
ans =
0 0 0 1
octave:5> is_NaN_or_NA (x)
ans =
0 1 0 1
octave:6> finite (x)
ans =
0 0 1 0
octave:7> x = rand (3); x(2,2) = NA; is_NA (x)
ans =
0 0 0
0 1 0
0 0 0
etc.
If you'd like to see the patch before I check it in, let me know (it's
about 400 lines of context diffs, so I decided it would probably be
best to omit it from this post).
Now all that's left is to fix various functions to be NA-aware. This
will take some time, and it would help if someone (or some group)
could volunteer to help out with that.
Thanks,
jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Re: handling NaN, Schloegl Alois, 2002/08/05
- Re: handling NaN, Schloegl Alois, 2002/08/07
- Re: handling NaN, John W. Eaton, 2002/08/08
- Re: handling NaN, Schloegl Alois, 2002/08/13
- Re: handling NaN, Paul Kienzle, 2002/08/13
- Re: handling NaN, Schloegl Alois, 2002/08/13
- windows installation question, Helen Tang, 2002/08/13
Re: handling NaN, Dirk Eddelbuettel, 2002/08/08