bugGNU Octave - Bugs: bug #57564, Implementation of rng

 
 

bug #57564: Implementation of rng

Submitter:  Guillaume <gyom>
Submitted:  Thu 09 Jan 2020 02:43:27 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 19 Feb 2020 04:12:54 PM UTC, comment #6: 

Guillaume, I checked in your rng.m file, added an entry for it in the manual and NEWS file, and made a few style fixes:

http://hg.savannah.gnu.org/hgweb/octave/rev/c08d7b53f1a2
http://hg.savannah.gnu.org/hgweb/octave/rev/d320728d5d06

John W. Eaton <jwe>
Group administrator
Wed 19 Feb 2020 12:43:43 PM UTC, comment #5: 

I would like to ask whether the priority of this report could be moved from "low" to "normal". In recent versions of Matlab, rng() is the only documented function to control random number generators so it gets used more and more and I would argue that random number generation is a very core feature of a language for numerical computations.
I understand more substantial work has to be done in Octave to switch to a single (Mersenne Twister) generator feeding both rand and randn but this can be hidden away from the higher level implementation of rng().

Guillaume <gyom>
Fri 10 Jan 2020 11:33:39 AM UTC, comment #4: 
Guillaume <gyom>
Thu 09 Jan 2020 04:33:21 PM UTC, comment #3: 

Setting group, priority, and severity to be consistent with other missing functions.

John W. Eaton <jwe>
Group administrator
Thu 09 Jan 2020 03:10:50 PM UTC, comment #2: 

The attached file had an UTF-8 encoding issue, re-attaching.

(file #48188)

Guillaume <gyom>
Thu 09 Jan 2020 03:03:33 PM UTC, comment #1: 


  • meaning of seed 0 in Matlab:

https://uk.mathworks.com/matlabcentral/answers/28216-how-to-duplicate-rand-twister-0-in-current-matlab#answer_36510

  • numpy can generate the same sequence of numbers for rand than Matlab:

https://stackoverflow.com/questions/3722138/is-it-possible-to-reproduce-randn-of-matlab-with-numpy?rq=1
https://github.com/numpy/numpy/blob/master/numpy/random/src/mt19937/mt19937.c
so the same could be achieved with Octave. For randn, Matlab seems to be using one or more rand values, which means that it is likely implementing the Ziggurat algorithm (and not the Marsaglia polar method or the Box–Muller transform).

Guillaume <gyom>
Thu 09 Jan 2020 02:43:27 PM UTC, original submission:  

Matlab has a "rng" function to set and query the state of the random number generator:
https://www.mathworks.com/help/matlab/ref/rng.html
This is the recommended syntax. The use of rand('state',...) is discouraged and not documented any more:
https://www.mathworks.com/help/matlab/math/updating-your-random-number-generator-syntax.html
https://www.mathworks.com/help/matlab/ref/rand.html

I attach a possible implementation for Octave. Currently, Octave has a separate generator for rand and randn so rng stores both states: if and when Octave evolves to use a single generator, the rng function can be updated internally without any visible change from the outside. This means that, in my eye, rng can be considered for inclusion in Octave now even if some work is still to take place in rand/randn.

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #48188:  rng.m added by gyom (9KiB - text/x-matlab)
file #48187:  rng.m added by gyom (9KiB - text/x-matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by gyom (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
    2020-02-21 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2020-02-19 jwe StatusNone Ready For Test
    2020-01-09 jwe Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility Feature Request
    2020-01-09 gyom Attached File- Added rng.m, #48188
    2020-01-09 gyom Attached File- Added rng.m, #48187

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code