A generator for random sources Bradley Lucier (27 Jun 2020 21:53 UTC)
Re: A generator for random sources John Cowan (27 Jun 2020 22:45 UTC)
Re: A generator for random sources Bradley Lucier (27 Jun 2020 23:50 UTC)
Re: A generator for random sources Linas Vepstas (27 Jun 2020 23:52 UTC)
Re: A generator for random sources Arvydas Silanskas (28 Jun 2020 08:11 UTC)

A generator for random sources Bradley Lucier 27 Jun 2020 21:53 UTC

I don't understand as much as I'd like about generators and parameters,
but I think there could be something suitable for SRFI 194 that would
really help semi-serious simulations.

SRFI 27 specifies

(make-random-source) -> s
(random-source-pseudo-randomize! s i j)

The second procedure was motivated by Section 1.2 and 1.3 of the paper
"An Object-Oriented Random-Number Package with Many Long Streams and
Substreams" by Pierre L'Ecuyer, Richard Simard, E. Jack Chen, and W.
David Kelton:

http://www.iro.umontreal.ca/~lecuyer/myftp/papers/streams00.pdf

I can't speak for all implementations of SRFI 27, but the reference
implementation and Gambit implement the ideas of this paper, which are:

Let's say you want to simulate a process and gather statistics of how
that process will proceed from beginning to end over multiple runs.

You'd do the simulation N times.

Each of those simulations requires *many* streams of random numbers.

For example, if you were trying to model the mean and variance of wait
times at a four-way intersection given different traffic light timings,
you'd want four exponential streams with different arrival spacings for
each of the four directions.  For each direction you'd want a random
stream to specify whether a car coming from that direction will go
straight, turn left or right (maybe a categorical generator).  You might
have an entire network of streets with traffic lights through downtown,
so soon you get to scores or hundreds of independent streams of random
variables.

And when you repeat this simulation N times you'd like all the streams
in simulation I to be independent of the streams in simulation I'.

That's what random-source-pseudo-randomize! is supposed to do (although
it's not spelled out explicitly in SRFI 27, it's clear that the
implementation does this).

You'd like to have something like

(define (random-source-generator i)
   (let ((j 0))
     (lambda ()
       (let ((new-source (make-random-source))) ;; deterministic
         (random-source-pseudo-randomize! new-source i j)
         (set! j (+ j 1))
         new-source))))

and in your code you'd have for the I'th simulation

(define random-sources (random-source-generator I))

Then each time you'd call random-sources you'd get the next random
source in the sequence.

And you might like a form with-next-random-source used something like

(define southbound-arrival-increment
   (with-next-random-source
   ... ;; set up a random generator using the next random source
))

and to get the next arrival time difference you'd call
(southbound-arrival-increment).

I'm not being very precise here because I don't have clear in my mind
how you would set up and use the generators of this SRFI in a simulation.

Discussion/criticism/... invited.

Brad

The definitions from SRFI 27:

(make-random-source) -> s
     Creates a new random source s. Implementations may accept
additional, optional arguments in order to create different types of
random sources. A random source created with make-random-source
represents a deterministic stream of random bits generated by some form
of pseudo random number generator. Each random source obtained as
(make-random-source) generates the same stream of values, unless the
state is modified with one of the procedures below.

(random-source-pseudo-randomize! s i j)
     Changes the state of the random source s into the initial state of
the (i, j)-th independent random source, where i and j are non-negative
integers. This procedure provides a mechanism to obtain a large number
of independent random sources (usually all derived from the same
backbone generator), indexed by two integers. In contrast to
random-source-randomize!, this procedure is entirely deterministic.