
12

Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under
Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the
data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave
version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Off top of my head I think you will not be able to get the same numbers
that way (the implementations are different).
I would create a large sequence of your random numbers in on of your
systems and save it to a file then read that as input into the other system.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


On Sun, Jun 3, 2012 at 10:03 AM, Mathieu Dubois <[hidden email]> wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave
I believe that the only way to do this is to generate a sequence of random numbers with one system (octave) and then store these to a file. Then use this file of numbers for both systems, this will give you exactly the same numbers for your test.
 DAS
https://linuxcounter.net/user/206392.html
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Another option is to write some code to generate your own pseudo random sequence then use the same code on both. There are plenty of algorithms out there if you look around. Adam Doug Stewart < [hidden email]> wrote: On Sun, Jun 3, 2012 at 10:03 AM, Mathieu Dubois <[hidden email]> wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave
I believe that the only way to do this is to generate a sequence of random numbers with one system (octave) and then store these to a file. Then use this file of numbers for both systems, this will give you exactly the same numbers for your test.
 DAS
https://linuxcounter.net/user/206392.html
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


I'm not sure if it will work, but your best best (if the randoms are reals) is to try setting the state to a certain value in both applications (rand('state',42) or randn('state',42)). I'm not familiar with the seed algorithm the apps use, but even with the same starting state, and with both running on the same machine, the results could be different. If, however, they are running on different machines, I'm sure they will not be identical.
If, however, the randoms are integers, perhaps you can generate a very large sequence in both and have the results be sufficiently similar.
Andrew


On 3 June 2012 10:03, Mathieu Dubois < [hidden email]> wrote:
> In order to compare as precisely as possible the Matlab and Octave version
> it seems necessary to have the same sequence of random numbers.
This is impossible.
The exact algorithm for generating random numbers that Matlab uses is
hidden, as is their seed. We can't replicate their sequence.
 Jordi G. H.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


 Original Message 
> From: Mathieu Dubois < [hidden email]>
> To: [hidden email]
> Cc:
> Sent: Sunday, June 3, 2012 5:03 PM
> Subject: Same sequence of random number generators than under Matlab?
>
> Hello,
>
> I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab
> and Octave.
>
> The algorithm is stochastic because, as in most training algorithm, the data are
> presented inrandom order.
> In order to compare as precisely as possible the Matlab and Octave version it
> seems necessary to have the same sequence of random numbers.
>
> Is there a way to do that?
>
> I have tried the following:
> rand('twister', 10);
> s = rand(10, 1);
> disp(s);
> disp(mean(s));
> disp(var(s));
>
> The sequences are different (but the statistics are close).
>
> Mathieu
>
>
As others have already suggested, generate the sequence in one tool (either Matlab or Octave), store it in a file, and use it in the other tool.
Regards,
Sergei.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


 Original Message 
> From: Sergei Steshenko < [hidden email]>
> To: Mathieu Dubois < [hidden email]>; " [hidden email]" < [hidden email]>
> Cc:
> Sent: Sunday, June 3, 2012 8:45 PM
> Subject: Re: Same sequence of random number generators than under Matlab?
>
>
>
>
>
>  Original Message 
>> From: Mathieu Dubois < [hidden email]>
>> To: [hidden email]
>> Cc:
>> Sent: Sunday, June 3, 2012 5:03 PM
>> Subject: Same sequence of random number generators than under Matlab?
>>
>> Hello,
>>
>> I want to comapre the output of the SelfOrganinzin Map algorithm under
> Matlab
>> and Octave.
>>
>> The algorithm is stochastic because, as in most training algorithm, the
> data are
>> presented inrandom order.
>> In order to compare as precisely as possible the Matlab and Octave version
> it
>> seems necessary to have the same sequence of random numbers.
>>
>> Is there a way to do that?
>>
>> I have tried the following:
>> rand('twister', 10);
>> s = rand(10, 1);
>> disp(s);
>> disp(mean(s));
>> disp(var(s));
>>
>> The sequences are different (but the statistics are close).
>>
>> Mathieu
>>
>>
>
> As others have already suggested, generate the sequence in one tool (either
> Matlab or Octave), store it in a file, and use it in the other tool.
>
> Regards,
> Sergei.
In general, regardless of tools, using truly random numbers directly, without first storing them is a persistent storage, is methodologically wrong.
Suppose certain random numbers sequence exposes an anomaly.
If the sequence is not stored in some kind of persistent storage, it can't be replayed in order to investigate the anomaly.
Regards,
Sergei.
>
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Le 03/06/2012 16:19, Martin Helm a écrit :
> Off top of my head I think you will not be able to get the same numbers
> that way (the implementations are different).
> I would create a large sequence of your random numbers in on of your
> systems and save it to a file then read that as input into the other system.
Thanks to every one who replied so quickly. I will try this solution.
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
x_{k+1} = ax_k (mod m)
with a,m = 16807, 2^311
which was in fact Matlab's internal random number generator until replaced by the Mersenne Twister. You'll find some good links here; there are some PRNGs developed by the late George Marsaglia which are both far simpler, and have a far longer period, than the Mersenne Twister.
For a Matlab implementation of the WichmannHill PRNG (which works basically by adding up three floating point values and taking the fractional part as output), seehere. This is a simple program which should work equally well in Matlab and Octave.
Alasdair
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois <[hidden email]> wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Here's a simple function which generates n pseudorandom numbers according to the 2006 WichmannHill method, which is much stronger than the one linked to above, and which passes the "Big Crush" test, as well as having a period of 2^121:
whrandom.m 
# Implements the 2006 WichmannHill PRNG # Computes n pseudorandom numbers starting with a seed of 4 userchosen # values.
function out = whrandom(ix,iy,iz,iw,n) p1 = 2147483579; p2 = 2147483543; p3 = 2147483423; p4 = 2147483123; out = zeros(n,1); for i=1:n
ix = mod(11600*ix,p1); iy = mod(47003*iy,p2); iz = mod(23000*iz,p3); iw = mod(30000*iw,p4); out(i) = mod(ix/p1+iy/p2+iz/p3+iw/p4,1); end 
Alasdair On Mon, Jun 4, 2012 at 10:26 PM, Alasdair McAndrew <[hidden email]> wrote:
Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
x_{k+1} = ax_k (mod m)
with a,m = 16807, 2^311
which was in fact Matlab's internal random number generator until replaced by the Mersenne Twister. You'll find some good links here; there are some PRNGs developed by the late George Marsaglia which are both far simpler, and have a far longer period, than the Mersenne Twister.
For a Matlab implementation of the WichmannHill PRNG (which works basically by adding up three floating point values and taking the fractional part as output), seehere. This is a simple program which should work equally well in Matlab and Octave.
Alasdair
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois <[hidden email]> wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


.. and here's a simple implementation of Marsaglia's "Complementary Multiply with Carry" generator. It has a period of 2^131104  far greater than that of the Mersenne Twister.

function out = CMWC32(s1,s2,n) # 32 bit CMWC a = 18782; c = s1; x = s2; b = 2^321; # initialize state vector s = zeros(4097,1);
for i=1:4096 x = bbitand(uint64(a*x+c),b); c = bitshift(uint64(a*x+c),32); s(i) = x; endfor # Now compute new values for use for i = 1:n
x = s(1); s(4097) = bbitand(uint64(a*x+c),b); c = bitshift(uint64(a*x+c),32); disp(double(s(4097))/2^32) s = s(2:4097); endfor 
No doubt this could be streamlined and optimized considerably. For the very simple C code which describes this PRNG, see here.
Alasdair On Tue, Jun 5, 2012 at 12:25 AM, Alasdair McAndrew <[hidden email]> wrote:
Here's a simple function which generates n pseudorandom numbers according to the 2006 WichmannHill method, which is much stronger than the one linked to above, and which passes the "Big Crush" test, as well as having a period of 2^121:
whrandom.m 
# Implements the 2006 WichmannHill PRNG # Computes n pseudorandom numbers starting with a seed of 4 userchosen # values.
function out = whrandom(ix,iy,iz,iw,n) p1 = <a href="tel:2147483579" value="+12147483579" target="_blank">2147483579; p2 = <a href="tel:2147483543" value="+12147483543" target="_blank">2147483543;
p3 = <a href="tel:2147483423" value="+12147483423" target="_blank">2147483423; p4 = <a href="tel:2147483123" value="+12147483123" target="_blank">2147483123; out = zeros(n,1);
for i=1:n
ix = mod(11600*ix,p1); iy = mod(47003*iy,p2); iz = mod(23000*iz,p3); iw = mod(30000*iw,p4); out(i) = mod(ix/p1+iy/p2+iz/p3+iw/p4,1); end 
Alasdair On Mon, Jun 4, 2012 at 10:26 PM, Alasdair McAndrew <[hidden email]> wrote:
Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
x_{k+1} = ax_k (mod m)
with a,m = 16807, 2^311
which was in fact Matlab's internal random number generator until replaced by the Mersenne Twister. You'll find some good links here; there are some PRNGs developed by the late George Marsaglia which are both far simpler, and have a far longer period, than the Mersenne Twister.
For a Matlab implementation of the WichmannHill PRNG (which works basically by adding up three floating point values and taking the fractional part as output), seehere. This is a simple program which should work equally well in Matlab and Octave.
Alasdair
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois <[hidden email]> wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


 Mail original 
De: "Alasdair McAndrew" < [hidden email]>
À: "Mathieu Dubois" < [hidden email]>, [hidden email]
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?
> Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
> x_{k+1} = ax_k (mod m)
> with a,m = 16807, 2^311
Following your advice, I was trying to implement the LCG but I can't find the document. Could you repost it?
Also thanks for the other algorithm but I want to use a simple one.
Mathieu
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois < [hidden email] > wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
______________________________ _________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/ listinfo/helpoctave

Blog: http://amca01.wordpress.com
Web: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


>Another option is to write some code to generate your own pseudo random sequence then use the same code on both.
>There are plenty of algorithms out there if you look around.
I think this is the best option.

Francesco Potortì (ricercatore) Voice: +39.050.315.3058 (op.2111)
ISTI  Area della ricerca CNR Mobile: +39.348.8283.107
via G. Moruzzi 1, I56124 Pisa Fax: +39.050.315.2040
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


 Mail original 
De: "Alasdair McAndrew" < [hidden email]>
À: "Mathieu Dubois" < [hidden email]>, [hidden email]
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?
> Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
> x_{k+1} = ax_k (mod m)
> with a,m = 16807, 2^311
I tried to implement the algorithm (see attached file) but it doesn't seem to work (I get sequences containing 0). Can somebody help?
Just a note: I'm trying to mimck the behaviour of Matlab rand function. My plan is to put the file in the test directory (under the name 'rand.m') so that the rand function will be replaced by my implementation. This is because I don't want to touch the code of the toolbox I'm using. As this toolbox uses rand('state', seed) my code tries to mimick that (this is also why I don't want ti implement more complicated algorithm that use a vector of seeds). The code uses a global variable for the seed and for xn which is the next random number to return. I print the state of the genrator at the begining and end of the function.
Thanks in advance for any help,
Mathieu _______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


The article you want is at http://www.mathworks.com.au/moler/random.pdf
and the LCG (very simple) is
x(n+1) = 16807*x(n) mod 2^311 with x(1)=1.
You can see Moler's mfile here:
Alasdair On Tue, Jun 5, 2012 at 7:21 PM, Mathieu Dubois <[hidden email]> wrote:
 Mail original 
De: "Alasdair McAndrew" <[hidden email]>
À: "Mathieu Dubois" <[hidden email]>, [hidden email]
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?
> Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
> x_{k+1} = ax_k (mod m)
> with a,m = 16807, 2^311
Following your advice, I was trying to implement the LCG but I can't find the document. Could you repost it?
Also thanks for the other algorithm but I want to use a simple one.
Mathieu
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois < [hidden email] > wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
______________________________ _________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/ listinfo/helpoctave

Blog: http://amca01.wordpress.com
Web: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


You won't have much luck mimicking Matlab's rand function, as Matlab uses the Mersenne twister PRNG, which is very good, but quite complicated. And because you don't have access to the source code, you can't be sure of how it's been set up to work.
Assuming you don't want too many random numbers, the simple LCG should suffice.
Alasdair On Tue, Jun 5, 2012 at 10:01 PM, Alasdair McAndrew <[hidden email]> wrote:
The article you want is at http://www.mathworks.com.au/moler/random.pdf
and the LCG (very simple) is
x(n+1) = 16807*x(n) mod 2^311 with x(1)=1.
You can see Moler's mfile here:
AlasdairOn Tue, Jun 5, 2012 at 7:21 PM, Mathieu Dubois <[hidden email]> wrote:
 Mail original 
De: "Alasdair McAndrew" <[hidden email]>
À: "Mathieu Dubois" <[hidden email]>, [hidden email]
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?
> Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
> x_{k+1} = ax_k (mod m)
> with a,m = 16807, 2^311
Following your advice, I was trying to implement the LCG but I can't find the document. Could you repost it?
Also thanks for the other algorithm but I want to use a simple one.
Mathieu
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois < [hidden email] > wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
______________________________ _________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/ listinfo/helpoctave

Blog: http://amca01.wordpress.com
Web: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
 Blog: http://amca01.wordpress.comWeb: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


On Tue, Jun 5, 2012 at 8:08 AM, Alasdair McAndrew <[hidden email]> wrote:
You won't have much luck mimicking Matlab's rand function, as Matlab uses the Mersenne twister PRNG, which is very good, but quite complicated. And because you don't have access to the source code, you can't be sure of how it's been set up to work.
Assuming you don't want too many random numbers, the simple LCG should suffice.
Alasdair
On Tue, Jun 5, 2012 at 10:01 PM, Alasdair McAndrew <[hidden email]> wrote:
The article you want is at http://www.mathworks.com.au/moler/random.pdf
and the LCG (very simple) is
x(n+1) = 16807*x(n) mod 2^311 with x(1)=1.
You can see Moler's mfile here:
AlasdairOn Tue, Jun 5, 2012 at 7:21 PM, Mathieu Dubois <[hidden email]> wrote:
 Mail original 
De: "Alasdair McAndrew" <[hidden email]>
À: "Mathieu Dubois" <[hidden email]>, [hidden email]
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?
> Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
> x_{k+1} = ax_k (mod m)
> with a,m = 16807, 2^311
Following your advice, I was trying to implement the LCG but I can't find the document. Could you repost it?
Also thanks for the other algorithm but I want to use a simple one.
Mathieu
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois < [hidden email] > wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
Alasdair, you are correct in what you said, but my understanding of what he is going to do is this.
Make his own rand.m and use it in Matlab and Octave without changing any other code. I think this is a good plan.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


 Mail original 
De: "Alasdair McAndrew" < [hidden email]>
À: "Mathieu Dubois" < [hidden email]>, [hidden email]
Envoyé: Mardi 5 Juin 2012 14:08:20
Objet: Re: Same sequence of random number generators than under Matlab?
> You won't have much luck mimicking Matlab's rand function, as Matlab uses the Mersenne twister PRNG, which is very good, but quite complicated. And because you don't have access to the source code, you can't be sure of how it's been set up to work.
I mean to mimick the interface of the function (i.e. the response to calls such as rand('state', 10)), not the result.
> Assuming you don't want too many random numbers, the simple LCG should suffice.
Thanks for the code it really helps! I thinks it's working now.
Alasdair
On Tue, Jun 5, 2012 at 10:01 PM, Alasdair McAndrew < [hidden email] > wrote:
The article you want is at http://www.mathworks.com.au/moler/random.pdf
and the LCG (very simple) is
x(n+1) = 16807*x(n) mod 2^311 with x(1)=1.
You can see Moler's mfile here:
http://www.mathworks.com/matlabcentral/fileexchange/4822usingnumericalcomputingwithmatlabintheclassroom/content/randmcg.m
Alasdair
On Tue, Jun 5, 2012 at 7:21 PM, Mathieu Dubois < [hidden email] > wrote:
 Mail original 
De: "Alasdair McAndrew" < [hidden email] >
À: "Mathieu Dubois" < [hidden email] >, [hidden email]
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?
> Writing your own is a good idea. Cleve Moler, here, speaks of the linear congruential generator
> x_{k+1} = ax_k (mod m)
> with a,m = 16807, 2^311
Following your advice, I was trying to implement the LCG but I can't find the document. Could you repost it?
Also thanks for the other algorithm but I want to use a simple one.
Mathieu
On Mon, Jun 4, 2012 at 12:03 AM, Mathieu Dubois < [hidden email] > wrote:
Hello,
I want to comapre the output of the SelfOrganinzin Map algorithm under Matlab and Octave.
The algorithm is stochastic because, as in most training algorithm, the data are presented inrandom order.
In order to compare as precisely as possible the Matlab and Octave version it seems necessary to have the same sequence of random numbers.
Is there a way to do that?
I have tried the following:
rand('twister', 10);
s = rand(10, 1);
disp(s);
disp(mean(s));
disp(var(s));
The sequences are different (but the statistics are close).
Mathieu
______________________________ _________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/ listinfo/helpoctave

Blog: http://amca01.wordpress.com
Web: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew

Blog: http://amca01.wordpress.com
Web: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew

Blog: http://amca01.wordpress.com
Web: http://sites.google.com/site/amca01/
Facebook: http://www.facebook.com/alasdair.mcandrew
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Why no just make Octave's rand/randn work in Matlab. This is the third
or fourth time I've suggested this over the year with code I posted on
the octaveforge list in 2005 as a mexfile.
http://sourceforge.net/mailarchive/forum.php?thread_name=425A617A.3010004%40motorola.com&forum_name=octavedevI've updated this for newer versions of Octave and attach it here.
Compile this file taking the randmtzig.{c,h} files from the Octave
sources. Copy the resulting file to rand.MEXEXT and randn.MEXEXT (where
MEXEXT is returned by the mexext function in matlab) and try something like
rand("state",1:3); rand(1,3)
randn("state",1:3);randn(1,3)
in Matlab and Octave and you should get the same results.
D.

David Bateman [hidden email]
35 rue Gambetta +33 1 46 04 02 18 (Home)
92100 BoulogneBillancourt FRANCE +33 6 72 01 06 33 (Mob)
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave

12
