bugGNU Octave - Bugs: bug #59410, [octave forge] (statistics)...

 
 

bug #59410: [octave forge] (statistics) geomean with NaN

Submitter:  Armin Müller <arm_in>
Submitted:  Tue 03 Nov 2020 07:45:07 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 21 Jun 2022 10:49:27 AM UTC, comment #11: 

Latest fix concerning 'includenan' option has been pushed in commit 4110f8f at https://github.com/gnu-octave/statistics/commit/11a690d008e13790365fc0778bab2b7a47657693
This bug can be closed.

Andreas Bertsatos <pr0m1th3as>
Sun 12 Jun 2022 09:25:33 AM UTC, comment #10: 

I have made a new implementation of geomean, which does not rely on existing mean implementation from core Octave. It is fully compatible with Matlab and it also handles properly page indexing in n-dimensional arrays.
Moreover, it can handle negative values in input argument X by returning complex numbers. Proper texinfo help and a number of tests have been included. Commit 166bec6 pushed at
https://github.com/gnu-octave/statistics/commit/166bec62b5b486fb6b2c655aad39058c8c96fbf7

Andreas Bertsatos <pr0m1th3as>
Tue 23 Nov 2021 08:51:37 PM UTC, comment #9: 

as we will soon be releasing octave 7.1, will the comment #8 change  to core allow us to close this?

Nicholas Jankowski <nrjank>
Group Member
Sat 28 Nov 2020 05:48:02 PM UTC, comment #8: 

I pushed a patch to allow NaN input for geometric mean in Octave core here:
https://hg.savannah.gnu.org/hgweb/octave/rev/54509b7fddd3

I'm not sure if we should leave this open in case the statistics package doesn't want to wait for that change in Octave core to be released.

I'm also not sure if this bug should be about the 'omitnan' and 'includenan' flags that have been introduced in Matlab. That is not what this report was originally about.

There are already bug #50571 for the same feature in `sum` and bug #50007 for `min` and `max`. Maybe we should have a separate report for `mean`, too. Or one single report for adding those switches to all of those functions.

Markus Mützel <mmuetzel>
Group administrator
Fri 13 Nov 2020 09:04:20 PM UTC, comment #7: 

Matlab r2020b:

>> format compact
>> geomean([+Inf 1 2 3])
ans =
   Inf
>> geomean([-Inf 1 2 3])
Error using geomean (line 27)
X may not contain negative values or complex values.
>> geomean([NaN 1 2 3])
ans =
   NaN
>> geomean([NaN 1 2 3], 'omitnan')
ans =
    1.8171
>>


Philip Nienhuis <philipnienhuis>
Group Member
Fri 13 Nov 2020 04:47:55 PM UTC, comment #6: 

It looks like matlab mean function that has a omitnan flag [1]


[1] https://www.mathworks.com/help/matlab/ref/mean.html#buql3m_



John Donoghue <lostbard>
Group Member
Fri 13 Nov 2020 01:56:33 PM UTC, comment #5: 

Thanks for testing.
I understand that this is a change in behavior. But reading their documentation, it looks like this is compatible behavior (at least for `geomean`).
I don't have access to the statistics toolbox in Matlab. So it would be nice if someone could verify that this is the case.

The 'g' switch is an Octave extension to the `mean` function. There are arguments in favor of and against failing on NaN input. But I'd argue that if mean without the 'g' switch doesn't fail for NaN input, it shouldn't fail with the 'g' switch either...

Markus Mützel <mmuetzel>
Group administrator
Fri 13 Nov 2020 01:48:48 PM UTC, comment #4: 

With the patch:

mean([NaN 1 2 3], 'g')
ans = NaN

geomean([NaN 1 2 3])
ans = NaN

John Donoghue <lostbard>
Group Member
Thu 12 Nov 2020 01:49:33 PM UTC, comment #3: 

Or maybe simpler like this.

(file #50258)

Markus Mützel <mmuetzel>
Group administrator
Thu 12 Nov 2020 01:45:23 PM UTC, comment #2: 

If I correctly understand the MathWork's documentation for `geomean`, it doesn't fail on NaN values.
If `mean (x, "g")` should behave the same way as `geomean (x)`, we could use the attached change.

(file #50257)

Markus Mützel <mmuetzel>
Group administrator
Thu 12 Nov 2020 01:05:30 PM UTC, comment #1: 

The geomean function is just calling octave mean function in its geomean mode and displaying its message, which is what the docs say it does.


octave:1> mean([NaN 1 2 3], 'g')
error: mean: X must not contain any negative values
error: called from
    mean at line 158 column 9


The documentation could perhaps update to say that, or the octave mean documentation?

John Donoghue <lostbard>
Group Member
Tue 03 Nov 2020 07:45:07 PM UTC, original submission:  

Octave 5.2.0
statistics 1.4.1


>> geomean([0 1 2 3])
ans = 0


=> looks OK


>> geomean([+Inf 1 2 3])
ans =  Inf


=> looks OK


>> geomean([-Inf 1 2 3])
error: mean: X must not contain any negative values
error: called from
    mean at line 158 column 9
    geomean at line 28 column 7


=> correct error message


>> geomean([NaN 1 2 3])
error: mean: X must not contain any negative values
error: called from
    mean at line 158 column 9
    geomean at line 28 column 7


=> Misleading. There is no negative value.

Armin Müller <arm_in>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #50257:  bug59410_geomean.patch added by mmuetzel (741B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pr0m1th3as (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by lostbard (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by arm_in (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-21 siko1056 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2021-11-23 nrjank StatusNone Need Info
    2020-11-28 mmuetzel Release5.2.0 other
    2020-11-12 mmuetzel Attached File- Added bug59410_geomean_v2.patch, #50258
    2020-11-12 mmuetzel Attached File- Added bug59410_geomean.patch, #50257
    2020-11-12 lostbard Operating SystemMicrosoft Windows Any
    2020-11-04 siko1056 Summarygeomean with NaN [octave forge] (statistics) geomean with NaN

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code