help-octave
[Top][All Lists]

## Re: handling NaN

 From: Paul Kienzle Subject: Re: handling NaN Date: Tue, 13 Aug 2002 14:55:09 -0400

```...

> > > The consequences are that NaN's should be omitted by default.
> >
> > The consequences are that MISSING VALUES should be omitted by default.
>
>
> Ok, you are right. Actually, I meant Missing Values. However, on explanation
> of
> this lapsus is that in statistitics and stochastic signal processing, there is
> no difference between NaNs and Missing values.
>
> > NaNs are
> > not missing values in many (most) computations, but instead are things
> > that inform you that your computation has gone awry.
>
> In my experience, NaN's can be omitted most of the time.
>
> Lets take the example of calculating the mean (or any other statistic) from a
> data series x:
> Lets further assume, x is a ratio of s over u; i.e. x=s./u.
> It could happen that for some elements s and u are zero, resulting in x=0/0.
> Clearly, 0/0 is not defined and results in NaN (an awry computation?). But we
> can still calculate the mean from that data series x.
> The bottomline is that it does not matter whether NaN's come from 0/0 or from
> somewhere else.

This is a bad example.  You do not want to compute a scale factor between
two signals using the mean of the ratio, especially if your measured value
of the signal is near zero.  It will be extremely sensitive to noise.  In
this case you are lucky to get the occasional NaN to let you know that
something is going wrong ;-)

Furthermore, in this case, nanmean won't protect you from NaNs.  Consider
s=[-1,0,1] and u=[0,0,0].  In this case nanmean(s./u) will give you
mean([-Inf,Inf]) which is NaN.  This data isn't unreasonable.
Consider trying to compute the gain on an amplifier with a digital scope
accurate to .1V.  If the input voltages is .01 and some point in the
signal and -.01 at some other point, and the amplifier has a gain of 10,
then you would be computing mean([..., Inf, ..., -Inf, ...]) which is NaN.

Paul Kienzle

-------------------------------------------------------------
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
-------------------------------------------------------------

```