MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Multiple independent random number streams cannot be implemented.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130165] Re: Multiple independent random number streams cannot be implemented.
  • From: Roger Wilson <rogerhw999 at gmail.com>
  • Date: Sat, 16 Mar 2013 03:15:00 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <khsbbv$36f$1@smc.vnet.net>

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



  • Prev by Date: Re: Issues with Rendering of Graphics[]
  • Next by Date: Re: Dynamic application of several polynomials
  • Previous by thread: Re: Multiple independent random number streams cannot be implemented.
  • Next by thread: Dynamic application of several polynomials