bugGNU Octave - Bugs: bug #42062, normrnd returns NaN for sigma=0

 
 

bug #42062: normrnd returns NaN for sigma=0

Submitter:  None
Submitted:  Sun 06 Apr 2014 11:09:25 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Matt Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.4
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 09 Apr 2014 03:16:50 AM UTC, comment #4: 

I fixed this on the development branch in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/ac75140f2c97).  It will be a part of the 4.2 release.  If you want to see the change earlier you can grab the m-file from the online Mercurial repository and replace your local copy of normrnd.m with the newer one.

Rik <rik5>
Group administrator
Tue 08 Apr 2014 03:57:38 AM UTC, comment #3: 

Sorry for the missing info.
Compatibility testing was done on both R2010b and R2011, and both return:

+Verbatim+

>> normrnd(1,0)


ans =

     1
-Verbatim-

Matlab R2010b and R2011 return

+Verbatim+

>> normpdf(1,1,0)


ans =

   NaN
-Verbatim-

I agree that normpdf should behave this way, but still think normrnd should not. I could be persuaded it is only a compatibility issue (and I have sanitized inputs to work around compatibility issues for the moment).

Matt <oconnmat>
Mon 07 Apr 2014 03:54:50 PM UTC, comment #2: 

Matlab r2009b returns NaN
but I think they have changed that in
more recent versions...

Michael Godfrey <godfrey>
Group Member
Mon 07 Apr 2014 03:00:25 PM UTC, comment #1: 

Which version of Matlab are you using for compatibility testing?

Also, what does the following return under your version of Matlab?


normpdf (1,1,0)


I had compatibility testing done for a lot of corner cases during the overhaul of the statistical functions between 3.4.X and 3.6.X.  But, Matlab is a moving target and they may have changed things once again for certain boundary cases.

Rik <rik5>
Group administrator
Sun 06 Apr 2014 11:09:25 PM UTC, original submission:  

Can reproduce by using command:


octave:1> normrnd(1,0)
ans = NaN


normrnd should return mu when sigma=0, not NaN

Output expected:

ans = 1


This is inconsistent with the definition of the normal distribution, and also inconsistent with Matlab's results.

I think the problem is in the normrnd.m file when testing whether sigma has a valid value. It does not include 0, only >0.

Specifically the parts of the code below

if (!isnan (mu) && !isinf (mu) && (sigma > 0) && (sigma < Inf))
should be
if (!isnan (mu) && !isinf (mu) && !(sigma < 0) && (sigma < Inf))


and


k = isnan (mu) | isinf (mu) | !(sigma > 0) | !(sigma < Inf);
 should be
k = isnan (mu) | isinf (mu) | (sigma < 0) | !(sigma < Inf);


Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by oconnmat (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-04-09 rik5 Item GroupIncorrect Result Matlab Compatibility
        StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2014-04-07 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code