User:Markuman: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== random == how to get equal matlab random numbers in octave - using twister(!) algorithm? * terminology: https://en.wikipedia.org/wiki/Mersenne_twister#Pseudocode * nice2k...") |
No edit summary |
||
Line 1: | Line 1: | ||
== random == | * Owner of http://mxeoctave.osuv.de | ||
* markuman@gmail.com (Mail, Gtalk) | |||
* markuman@jabber.ccc.de (XMPP) | |||
* markuman on irc.freenode.net | |||
* https://keybase.io/notagain | |||
* https://github.com/markuman/ | |||
=== random === | |||
how to get equal matlab random numbers in octave - using twister(!) algorithm? | how to get equal matlab random numbers in octave - using twister(!) algorithm? | ||
Line 6: | Line 13: | ||
* nice2know: http://stackoverflow.com/questions/13735096/python-vs-octave-random-generator | * nice2know: http://stackoverflow.com/questions/13735096/python-vs-octave-random-generator | ||
=== initial situation === | ==== initial situation ==== | ||
* ruby and python using twister algo as default | * ruby and python using twister algo as default | ||
Line 48: | Line 55: | ||
=== how to get the right seed states in octave? === | ==== how to get the right seed states in octave? ==== | ||
rand('twister',0) | rand('twister',0) | ||
Line 102: | Line 109: | ||
=== TODO === | ==== TODO ==== | ||
* Find the `seed` stuff in octave source | * Find the `seed` stuff in octave source |
Revision as of 19:34, 9 June 2014
- Owner of http://mxeoctave.osuv.de
- markuman@gmail.com (Mail, Gtalk)
- markuman@jabber.ccc.de (XMPP)
- markuman on irc.freenode.net
- https://keybase.io/notagain
- https://github.com/markuman/
random
how to get equal matlab random numbers in octave - using twister(!) algorithm?
- terminology: https://en.wikipedia.org/wiki/Mersenne_twister#Pseudocode
- nice2know: http://stackoverflow.com/questions/13735096/python-vs-octave-random-generator
initial situation
- ruby and python using twister algo as default
- force twister algo in matlab and octave
octave
octave:1> rand('twister',0) octave:2> rand ans = 0.844421851525048
python
>>> import random >>> random.seed(0) >>> random.random() 0.8444218515250481
numpy
>>> import numpy >>> numpy.random.seed(0) >>> numpy.random.random() 0.5488135039273248
ruby
irb(main):001:0> prng = Random.new(0) => #<Random:0x00000001d469e8> irb(main):002:0> prng.rand() => 0.5488135039273248
matlab
>> rand('twister',0) >> rand ans = 0.548813503927325
how to get the right seed states in octave?
rand('twister',0) states=rand('state');
seems to be the wrong ones. but they fit to them in python! ;)
function ret = twister_seed(SEED=0) ret = uint32(zeros(625,1)); ret(1) = SEED; for N = 1:623 ## initialize_generator # bit-xor (right shift by 30 bits) uint64(1812433253)*uint64(bitxor(ret(N),bitshift(ret(N),-30)))+N; # has to be uint64, otherwise in 4th iteration hit maximum of uint32! ret(N+1) = uint32(bitand(ans,uint64(intmax('uint32')))); # untempered numbers endfor ret(end) = 1; endfunction
octave:1> rand('twister',twister_seed) # notice: default seed is 0 in the function octave:2> rand ans = 0.548813503927325 octave:3> rand ans = 0.715189366372419 octave:4> rand ans = 0.602763376071644
compare to matlab...
>> rand('twister',0) >> rand ans = 0.548813503927325 >> rand ans = 0.715189366372419 >> rand ans = 0.602763376071644
TODO
- Find the `seed` stuff in octave source