bugGNU Octave - Bugs: bug #42557, rand seed for twister algorithm...

 
 

bug #42557: rand seed for twister algorithm differs from Matlab

Submitted by:  Markus Bergholz <markuman>
Submitted on:  Sun 15 Jun 2014 08:28:31 AM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: 3.8.1Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Thu 19 Nov 2015 05:34:58 PM UTC, comment #7:

Actually, scrap that last comment, 0 is seed 5489 in Matlab's latest RNG: http://www.mathworks.com/matlabcentral/answers/28216-how-to-duplicate-rand-twister-0-in-current-matlab#answer_36524

So only the normal distribution discrepancy remains.

Anonymous
Thu 19 Nov 2015 03:48:12 PM UTC, comment #6:

The flipping of the last element of the state vector reference was supposed to link to bug #44046

Anonymous
Thu 19 Nov 2015 02:04:17 PM UTC, comment #5:

This doesn't seem to hold for randn, tried with

Octave 4.0.0:

>> randn('twister', twister_seed(5489));
>> randn(1,5)

ans =

1.362259 0.071959 0.203598 -0.096973 1.324298

Matlab R2015a:

>> rng(5489, 'twister');
>> randn(1,5)


ans =

0.5377 1.8339 -2.2588 0.8622 0.3188

Also tried flipping the last state vector value as decribed (in both Matlab and Octave), randn still produces different streams.

Matlab also seems to use the Ziggurat method, so can't figure out where the difference is.

>> RandStream.getGlobalStream


ans =

mt19937ar random stream (current global stream)
Seed: 5489
NormalTransform: Ziggurat

Oddly enough, Matlab always seems to produce the same randn sequence no matter what the seed number is, i.e. rng(0, 'twister') and rng(5489, 'twister') generate the same 625 state vector when queried with s = rng

Anonymous
Sat 28 Jun 2014 05:15:20 AM UTC, comment #4:
Markus Bergholz <markuman>
Thu 26 Jun 2014 03:41:21 PM UTC, comment #3:

What does Matlab do if the seed is a vector, rather than a scalar?

Rik <rik5>
Project Administrator
Fri 20 Jun 2014 05:37:20 PM UTC, comment #2:

and finaly

seems to be the default seed from matlab...

Markus Bergholz <markuman>
Mon 16 Jun 2014 12:25:10 AM UTC, comment #1:

I've marked the bug as confirmed and changed the category to "Matlab Compatibility".

Rik <rik5>
Project Administrator
Sun 15 Jun 2014 08:28:31 AM UTC, original submission:

Initial situation:

Ruby, Python and Numpy using twister algorithm as default.
We can force this algorithm in Octave and Matlab too.
So, if you seed each software with the value 0, it should return the same random numbers.

So Octave is handling the seed input wrong. Afaiu the seed is processed in http://hg.octave.org/octave/file/03c2671493f9/liboctave/cruft/ranlib/getsd.f due use_old_generators. But maybe I'm wrong. However, This behavior can be fixed with another function.

This function needs to be translated into c++ (that's past my c++ skills!) and need to be called in line 276 of libinterp/corefcn/rand.cc and returned to ColumnVector s (afaiu).
http://hg.octave.org/octave/file/03c2671493f9/libinterp/corefcn/rand.cc#l276

Markus Bergholz <markuman>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #31549:  twister_seed.m added by markuman (456B - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by markuman (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 16 Jun 2014 12:25:10 AM UTCrik5Item GroupIncorrect Result=>Matlab Compatibility
      StatusNone=>Confirmed
      Summaryrand seed for twister algorithm=>rand seed for twister algorithm differs from Matlab
    Sun 15 Jun 2014 08:28:31 AM UTCmarkumanAttached File-=>Added twister_seed.m, #31549

    Back to the top


    Powered by Savane 3.1-cleanup1