Lisp HUG Maillist Archive

Re: Random Numbers?

David,

(I've subscribed to the lisp-hug list, and I'm sending the reply there
in case this discussion is of interest to anyone)

why do you think you need a "very good" generator? In 1998-2000 I
worked on Monte Carlo simulation of physical systems and we actually
used a quit simple shift generator (R250) which was known to have
problems with some clustering algorithms, but was safe for our "local"
algorithm (we really needed something easy to implement, the whole
thing was running on FPGAs) [1]. Lately I've been doing Monte Carlo
again (in finance this time); standard references like Jaeckel [2]
 encourage the use of the Mersenne Twister to be on the safe side as
it seems to work well in most circumstances and it's not too demanding
computationally. Glasserman [3] suggest trying a nonlinear generator
(slower) to check everything is ok in case one is concerned about the
quality of the pseudo-random sequence (he refers to a chapter on
"quadratic and inversive congruential PRNG" in [4]). If your
simulation is not affected by the correlation in the sequence at long
distances you should be fine.

However, you mention "all the PRNG's in the simulator" and if you
actually want to use several streams of random numbers things get more
complicated. Using multiple independent generators might not be a good
idea (but depending on your algorithm it might be ok). There are also
solutions to this problem, for example SPRNG [5]. If I remember well,
the same generator (and the same seed) is reused but with different
starting points along the cycle, or leaping over the numbers that are
being generated by the other instances.

(I don't know anything about generators for cryptography, only that in
that case the point is to have a sequence that can't be "predicted";
for simulation you don't care as long as it behaves well in some
statistical sense)

Cheers,

Carlos

[1] I've just found a reference, but I've not read it:
http://www.fz-juelich.de/nic-series/volume10/janke1.pdf
[2] http://www.amazon.com/Monte-Carlo-Methods-Finance-Jaeckel/dp/047149741X
[3] http://www.amazon.com/Financial-Engineering-Stochastic-Modelling-Probability/dp/0387004513
[4] http://www.amazon.com/Monte-Carlo-Quasi-Monte-Methods-1996/dp/038798335X
[5] http://sprng.cs.fsu.edu


> Hi Carlos,
>
> Well, many thanks for your insistence!  I thought I had seen
> something about that in the last round of release notes... And
> this is very good news for the pure-Lisp portions of my code. But
> for obtaining variates of Gamma, Nakagami, Rayleigh, and Rice
> distributions, there needs to be a C-resident PRNG that can be
> called upon by the GSL routines doing the rejection-methods.
>
> And my question was actually three-fold, although I think I now
> have the answer to the second part: seeding the MT PRNG is done
> with just about any 32-bit integer value, and so I read the
> elapsed microseconds in the computer's clock, and logand that
> with #xFFFFFFFF. That gives me a random seeding so that not all
> the PRNG's in the simulator are running with the same values.
>
> But the final question relates to suitability of the MT PRNG for
> use in deriving accurate statistical estimates. I read that the
> suitability of various PRNG's varies between this kind of use,
> and usage in crypto applications. I haven't seen any good
> recommendations either way on any of the available PRNG's --
> though I suspect folks at the NSA know which ones to use for
> crypto...
>
> So thanks a bunch for pointing that out about LW !!
>
> Cheers,
>
> Dr. David McClain
>
> On Jul 3, 2008, at 13:36, Carlos Ungil wrote:
>
> > Hi David,
> >
> > I tried to reply via gmane but I have the impression the message didn't get through, so I'm contacting you directly.
> >
> > The Mersenne Twister generator is already available in lispworks, see
> > http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-349.htm
> >
> > Cheers,
> >
> > Carlos


Re: Random Numbers?

Hi Carlos, et al,

Wow! You are a wealth of information on this topic. I hope others on the list are benefiting from this discussion too.

You raise some good issues regarding the use of multiple noise generators in Monte Carlo simulations. What I can say, after examining one of our typical simulation setups, is that the use of multiple noise sources occurs in relatively orthogonal domains. What I mean by that is that one generator is used to derived the additive channel noise which leads to micro-fading at the receiver. Another is used to randomly select weather conditions such as temperature, pressure, and relative humidity.

I cannot give a solid objective answer about when a PRNG is "suitable". We are attempting to gain BER statistics for a variety of weather conditions, pass-band shapes, and modulation methods. It might actually happen that as long as we sample a reasonably complete representation of the problem space with our "noise" we could derive sufficient statistics. In that case even a fixed-pattern lattice sampling, as you find in some generators, might be sufficient.

In other situations that I have simulated, such as correcting atmospheric seeing (star images) with deformable mirrors, in the presence of high upper-atmosphere turbulence, we needed a noise generator that exhibited a higher order of fractal dimensionality than our problem which had a fractal dimension of about 4.5. The atmospheric turbulence produced phase fluctuations that were roughly Kolmogorov distributed. Feedback neural networks in the time domain are capable of modest predictions one or two sample times into the future on such problems.

But if some systems exhibit "memory" then statistical correlations induced by the PRNG might become problematic. However, even a truly random source will exhibit what appear to be correlations among finite duration sequences. And I know from prior work that any attempt to qualify a simulation result with estimates of the confidence intervals on variances of the results are almost hopeless because the number of samples and separate trials needed to estimate the uncertainty of the variance is huge and essentially unobtainable to any useful level of precision.

Such "memory" systems might also pose problems for the issue you raised about using multiple noise generators in the same parametric domain. Certainly, it seems as if financial systems have both memory and nontrivial fractal dimensionality. And in that domain, you even have the problem that all the models depend on distributions with fast decaying tails (though some are leptokurtic), but the "black swan" events can only happen on a realistic frequency scale using entirely different statistics that scale with a power law. Otherwise you get the absurd statements that "such and such market event was a 20-sigma event" -- not even enough time in the life of the universe for one such event to have happened using conventional statistics.

Your questions raise another parallel that has been touched on by Prof. William Kahan of UCB regarding the quality of intermediate results in a numerical calculation. Such things are a spider's web where only the boundary of attachment has any quality concern for us, and in the interior, near poles of the complex domain, the intermediate results could be wildly incorrect. In reading that first paper you referenced below (Janke), this appears to have been the case for the Ferrenberg simulations mentioned on page 45 of that paper.

So I guess in summary, for conventional statistics, I would have to say that the quality of an PRNG can be estimated as "good" so long as its fractal dimensionality is significantly higher than that of the problem domain. 

For financial modeling, the situation is even worse because the black swan events don't happen frequently enough to allow estimates of their distributions, but too frequently to be considered in the tail of anything conventional (exponential roll-off). 

Thanks again for the wealth of references and the stimulating thoughts!

Dr. David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ  85750

email: dbm@refined-audiometrics.com
phone: 1.520.390.3995
web: http://www.refined-audiometrics.com



On Jul 4, 2008, at 14:33, Carlos Ungil wrote:


David,

(I've subscribed to the lisp-hug list, and I'm sending the reply there
in case this discussion is of interest to anyone)

why do you think you need a "very good" generator? In 1998-2000 I
worked on Monte Carlo simulation of physical systems and we actually
used a quit simple shift generator (R250) which was known to have
problems with some clustering algorithms, but was safe for our "local"
algorithm (we really needed something easy to implement, the whole
thing was running on FPGAs) [1]. Lately I've been doing Monte Carlo
again (in finance this time); standard references like Jaeckel [2]
 encourage the use of the Mersenne Twister to be on the safe side as
it seems to work well in most circumstances and it's not too demanding
computationally. Glasserman [3] suggest trying a nonlinear generator
(slower) to check everything is ok in case one is concerned about the
quality of the pseudo-random sequence (he refers to a chapter on
"quadratic and inversive congruential PRNG" in [4]). If your
simulation is not affected by the correlation in the sequence at long
distances you should be fine.

However, you mention "all the PRNG's in the simulator" and if you
actually want to use several streams of random numbers things get more
complicated. Using multiple independent generators might not be a good
idea (but depending on your algorithm it might be ok). There are also
solutions to this problem, for example SPRNG [5]. If I remember well,
the same generator (and the same seed) is reused but with different
starting points along the cycle, or leaping over the numbers that are
being generated by the other instances.

(I don't know anything about generators for cryptography, only that in
that case the point is to have a sequence that can't be "predicted";
for simulation you don't care as long as it behaves well in some
statistical sense)

Cheers,

Carlos

[1] I've just found a reference, but I've not read it:
http://www.fz-juelich.de/nic-series/volume10/janke1.pdf
[2] http://www.amazon.com/Monte-Carlo-Methods-Finance-Jaeckel/dp/047149741X
[3] http://www.amazon.com/Financial-Engineering-Stochastic-Modelling-Probability/dp/0387004513
[4] http://www.amazon.com/Monte-Carlo-Quasi-Monte-Methods-1996/dp/038798335X
[5] http://sprng.cs.fsu.edu


Hi Carlos,

Well, many thanks for your insistence!  I thought I had seen
something about that in the last round of release notes... And
this is very good news for the pure-Lisp portions of my code. But
for obtaining variates of Gamma, Nakagami, Rayleigh, and Rice
distributions, there needs to be a C-resident PRNG that can be
called upon by the GSL routines doing the rejection-methods.

And my question was actually three-fold, although I think I now
have the answer to the second part: seeding the MT PRNG is done
with just about any 32-bit integer value, and so I read the
elapsed microseconds in the computer's clock, and logand that
with #xFFFFFFFF. That gives me a random seeding so that not all
the PRNG's in the simulator are running with the same values.

But the final question relates to suitability of the MT PRNG for
use in deriving accurate statistical estimates. I read that the
suitability of various PRNG's varies between this kind of use,
and usage in crypto applications. I haven't seen any good
recommendations either way on any of the available PRNG's --
though I suspect folks at the NSA know which ones to use for
crypto...

So thanks a bunch for pointing that out about LW !!

Cheers,

Dr. David McClain

On Jul 3, 2008, at 13:36, Carlos Ungil wrote:

Hi David,

I tried to reply via gmane but I have the impression the message didn't get through, so I'm contacting you directly.

The Mersenne Twister generator is already available in lispworks, see
http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-349.htm

Cheers,

Carlos



Updated at: 2020-12-10 08:42 UTC