Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Multiple independent random number streams cannot be implemented.
Replies: 3   Last Post: Mar 16, 2013 3:13 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Wilson

Posts: 16
Registered: 10/23/10
Re: Multiple independent random number streams cannot be implemented.
Posted: Mar 16, 2013 3:13 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Thursday, 14 March 2013 11:13:03 UTC, Roger Wilson wrote:
> Hopefully the title is enough of a red flag for someone to try to prove me wrong.
>
>
>
> I want to implement two functions; lets call them f and g so that they both return random numbers. For example...
>
>
>
> f[]:=RandomReal[];
>
> g[]:=RandomReal[];
>
>
>
> However I want f and g to return the same number when they're called for the nth time. So the first call to f is always the same number and the first call to g is always the same number.
>
>
>
> In the above case (on my machine)...
>
> SeedRandom[1]; {f[], g[]} gives {0.168697, 0.113119}
>
>
>
> and of course..
>
> SeedRandom[1]; {g[], f[]} gives the same {0.817389, 0.11142}
>
>
>
> Essentially I want f and g to to be independent random sources.
>
>
>
> It is possible to localize the random number generators using BlockRandom but I do not see how that helps me in this case. BlockRandom localizes the state of the random number generators within the block where as I want to localize them into the symbol names.
>
>
>
> Roger



I'm replying to myself as several people have been kind enough to post replies here and to me directly. I'll try to describe the problem in more detail. I should point out that I've worked around the issue using BlockRandom so its not longer a problem, just academic interest now.

The problem is a monte-carlo simulation involving Brownian Bridges. I have a paths which are sequences of random numbers. I start of with one number , sub-divide it into two with the Brownian bridge, sub-divide that into 4 etc. Each sub-division pulls more random numbers from the RNG. One set of paths stating with the coarsest path to the finest path (say divided into 64 steps) is one monte-carlo sample.

If I need 1000 samples I generate each the first set of sub-divided paths, then the second then third etc generating paths of lengths 1,2,4,8,16,32&64. A problem arises if I change the depth of the sub-division. Say I only sub-divided the paths into 1,2,4,8,16&32 sections not but not 64. With the same random seed, the first sample (with paths lengths 1,2,4,8,16&32) will be the same (except missing the finest layer) but the next sample will be completely different because its now consuming random variates from the RNG which would have been used to refine the finest layer of the sample before.

A solution to this would have been to use a separate RNG for each sub-division layer, saving and restoring $RandomState indexed on the layers depth. That way the random numbers used for say, layer three would be independent of the simulation having a layer 7 or not.

However $RandomState is a legacy feature and in v.9 does not change at all as the random numbers are generate (except in Legacy mode). BlockRandom is the replacement but requires a change of paradigm.

My solution has been to generate each sample of sub-divided path inside a BlockRandom with its own seed (randomly generated outside the BlockRandom). This then means that each sample will generate the same coarser paths independently of the finer paths being generated. The sequence of seeds for each sample generation can be seeded itself using SeedRandom (its outside the BlockRandom used to isolate the sample generation).

Many thanks for everyone's replies but there are too many to respond to individually.

Roger




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.