The virtual class "rstream" provides a unified interface to uniform random number generators. Objects of its subclasses act as a source of streams for random numbers that can be handled by a set of methods and which can be used as arguments of functions that require sources of randomness, e.g. discrete event models, Monte Carlo integration or other stochastic simulations.
The instances of objects of this class and its subclasses are independent, i.e., sampling random numbers from one instance or reseting and changing its state does not effect any other instance. (However, different streams may not be stochastically independent if they are not carefully seeded!)
Additionally there is a mechanismus interface to save and restore such streams, e.g. for the next R session, for a reruning some stochastic calculations with identical input, or for sending the stream object to a slave node in parallel computing via MPI.
The interface to these classes is inspired by Pierre L'Ecuyers RngStreams package.
A virtual Class: No objects may be created from it.
The virtual class "rstream" prepares the following methods for
handling random stream objects. Some methods that return parameters of
the stream object have a variant that uses <-
to change the
respective parameters. See the man pages for the respective methods
for details.
Notice: Some subclasses only implement a subset of these interfaces. The methods that do not work produce an error message.
Methods to use the stream (available for all subclasses):
signature(object = "rstream")
:
Get a random sample from the stream object.
signature(object = "rstream")
:
Same as rstream.sample
.
signature(object = "rstream")
:
Reset stream into initial state.
Some subclasses have implemented the concept of substreams. This is especially usefull if two or more streams should be synchronized:
signature(object = "rstream")
:
Set state of stream to next substream.
signature(object = "rstream")
:
Reset current substream into starting state.
Antithetic random streams return numbers which have smallest possible correlation (i.e. \(-1\)) to their respective counterparts:
signature(object = "rstream")
:
Whether or not the stream object returns antithetic random
numbers.
signature(object = "rstream")
:
Change antithetic flag (TRUE
or FALSE
).
Most sources of pseudo random numbers generate random numbers of precision \(2^{-32}\approx 2\times 10^{-10}\). For some streams this can be increased to machine epsilon (i.e. \(\approx 10^{-16}\)) by combining two random numbers of lower precision:
signature(object = "rstream")
:
Whether or not the stream object returns random numbers with
increased precision.
signature(object = "rstream")
:
Change flag for increased precision (TRUE
or FALSE
).
Handling "rstream" objects:
signature(x = "rstream")
:
Print state of the stream object.
signature(x = "rstream")
:
Same as print
.
signature(object = "rstream")
:
The name of the stream object.
signature(object = "rstream")
:
Change the name of the stream object.
signature(object = "rstream")
:
Make a copy (clone) of stream object.
When a "rstream" object should be used in another R session or saved for some kind of later reuse all information about the object must be packed. Notice no method other than unpacking can be applied to a packed object. It must be unpacked before.
signature(object = "rstream")
:
Whether or not the stream object is packed.
signature(object = "rstream")
:
Pack or unpack object: set packed to TRUE
or FALSE
.
Josef Leydold josef.leydold@wu.ac.at
When "rstream" objects should be used in later R sessions they must be packed before the current R session is stopped and unpacked after the new R session has been started and the workspace image has been reloaded.
L'Ecuyer, P., Simard, R., Chen, E. J., and Kelton, W. D. (2002) An object-oriented random-number package with many long streams and substreams. Operations Research 50(6), 1073-1075.
rstream.mrg32k3a
,
rstream.runif
.
rstream.antithetic-methods
,
rstream.clone-methods
,
rstream.incprecision-methods
,
rstream.name-methods
,
rstream.packed-methods
,
rstream.reset-methods
,
rstream.sample-methods
,
rstream.nextsubstream-methods
,
rstream.RNG
.