[scilab-Users] min/max with NaN values
Michaël Baudin
michael.baudin at scilab.org
Wed Nov 24 12:03:23 CET 2010
Noticed the small line at the end of the Matlab/min: "The min function
ignores NaNs.". This is not written in the help page Scilab/min, but I
guess that this is also true.
Now, Matlab is more consistent :
>> min([1 nan])
ans =
1
>> min(1,nan)
ans =
1
while Scilab is weird :
Scilab:
-->min([1 %nan])
ans =
1.
-->min(1,%nan)
ans =
Nan
I think that you have found a 2 more bugs (that is, added with the bug
#7608), i.e. :
1. nans are ignored by Scilab inside a matrix, but not across the input
arguments,
2. this is not explicitely written in the help page.
I guess that the particular processing of Nans in the loop over the
arguments has just been forgotten.
Would you mind to submit these bug report please ?
Best regards,
Michaël Baudin
Le 24/11/2010 11:54, Michaël Baudin a écrit :
> Ahah...
>
> In Scilab:
>
> -->min([1 2 3 %nan])
> ans =
> 1.
> -->min(1,2,3,%nan)
> ans =
> Nan
>
> This is fun...
>
> In Matlab:
>
> >> min([1 2 3 nan])
> ans =
> 1
> >> min(1,2,3,nan)
> ??? Error using ==> min
> Too many input arguments.
>
> So Matlab does not support the y=min(x1,x2,x3) calling sequence, but
> Scilab do. On the other hand, Scilab results are weird with nans, at
> least.
>
> Regards,
>
> Michaël
>
> Le 24/11/2010 11:47, Mathieu Dubois a écrit :
>> On 11/24/2010 11:40 AM, Michaël Baudin wrote:
>>> Hi,
>>>
>>> The expected result is actually the matrix of Nans. If you had found
>>> another result, that would have been a bug. Even more, we have
>>> similar automatic checks that this is so - see the following unit
>>> test :
>>>
>>> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/elementary_functions/tests/unit_tests/IEEEcompatibility.tst;h=778fc00d4833f54fce6324ac917bac725d6f9e19;hb=HEAD
>>>
>>>
>>> Notice that this test is mainly for +,-,*,/,sqrt, the operations
>>> which are specified by the IEEE754 standard. With respect to Nan,
>>> these tests says that "Nan on input, then Nan on output". In the
>>> IEEE754 standard, the authors use the term "Nan propagation". More
>>> informations on this topic are given by "Handbook of Floating Point
>>> Arithmetic", by Muller et al.. See the sections "2.3 - Exceptions"
>>> and "3.1.5 Exceptions specified by IEEE754-1985".
>> That sounds like a sane convention but then, just out of curiosity,
>> how do you explain that min([1 2 3 %nan]) returns 1?
>>>
>>> If you want to perform the computation without the nans, you may
>>> combine the "find" and "isnan" functions. For example, the statement:
>>>
>>> k = find(isnan(a))
>>>
>>> you get the indices where a is a nan. Now, the statement:
>>>
>>> a(isnan(a))=0
>>>
>>> sets to zero the entries where Nan is present.
>>>
>>> But be warned: Nans are *designed* to be propagated. That is, if
>>> your input data contains Nans, that means that some previous
>>> computations has already failed. The Nans should not be, in general,
>>> just ignored and thrown away.
>>>
>>> Best regards,
>>>
>>> Michaël Baudin
>>>
>>> Le 24/11/2010 10:11, Frederic Jourdin a écrit :
>>>> Hi all !
>>>> if I run this:
>>>>
>>>> a= [ 1, %nan; 4, 4];
>>>> b= [ %nan, 3; 3, 6];
>>>> c= [ 2, 2; %nan, %nan];
>>>> min( a, b, c)
>>>>
>>>> Scilab returns the following matrix:
>>>> NaN NaN
>>>> NaN NaN
>>>>
>>>> while the expected matrix should be:
>>>> 1 2
>>>> 3 4
>>>>
>>>> Why?
>>>>
>>>> thanks
>>>> Fred
>>>>
>>>> Scilab 5.3.0.beta3 on Linux
>>>>
>>>
>>>
>>
>
>
--
Michaël Baudin
Ingénieur de développement
michael.baudin at scilab.org
-------------------------
Consortium Scilab - Digiteo
Domaine de Voluceau - Rocquencourt
B.P. 105 - 78153 Le Chesnay Cedex
Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20101124/54fc99f3/attachment.htm>
More information about the users
mailing list