This class implements the "rstream" interface for Pierre L'Ecuyer's RngStreams package with the MRG32K3a multiple recursive generator as its backbone generator. This package is well suited for multiple independent streams of uniform random numbers. In particular it provides antithetic variates and substreams. A very important feature is that different streams are stochastically independent (in opposition to many other random number generators where the uses has to choose seeds carefully). For that reason there only exists a package seed for all streams and indiviual seeds should be avoided (and requires expertise).
Objects can be created by calls of the form
new("rstream.mrg32k3a", name, seed, force.seed, antithetic,
incprecision)
.
An arbitrary string to name the stream object.
If omitted a string that consists of mrg32k3a
and some
number (which is increased every time when a new rstream
object is created.
An array of six numbers. The seed for the RngStreams package. If omitted a random seed is used. It should only be set at the first creation of an instance of an rstream.mrg32k3a object.
A boolean. If the RngStreams package should be reseeded
(which is not recommended) it must be TRUE
.
Default is FALSE
.
A boolean. Whether or not antithetic random
numbers should be produced.
Default is FALSE
.
A boolean. Whether or not random numbers with
increased precision should be produced.
Default is FALSE
.
Class "rstream"
, directly.
The class "rstream.mrg32k3a" provides the following methods for
handling "rstream.mrg32k3a" 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.
Methods to use the stream:
signature(object = "rstream.mrg32k3a")
:
Get a random sample from the stream object.
signature(object = "rstream.mrg32k3a")
:
Same as rstream.sample
.
signature(object = "rstream.mrg32k3a")
:
Reset stream into initial state.
signature(object = "rstream.mrg32k3a")
:
Set state of stream to next substream.
signature(object = "rstream.mrg32k3a")
:
Reset current substream into starting state.
Antithetic random streams and increased precision:
signature(object = "rstream.mrg32k3a")
:
Whether or not the stream object returns antithetic random
numbers.
signature(object = "rstream.mrg32k3a")
:
Change antithetic flag (TRUE
or FALSE
).
signature(object = "rstream.mrg32k3a")
:
Whether or not the stream object returns random numbers with
increased precision.
signature(object = "rstream.mrg32k3a")
:
Change flag for increased precision (TRUE
or FALSE
).
Handling "rstream.mrg32k3a" objects:
signature(x = "rstream.mrg32k3a")
:
Print state of the stream object.
signature(object = "rstream.mrg32k3a")
:
The name of the stream object.
signature(object = "rstream.mrg32k3a")
:
Change the name of the stream object.
signature(object = "rstream.mrg32k3a")
:
Make a copy (clone) of stream object.
signature(.Object = "rstream.mrg32k3a")
:
Initialize rstream object. (For Internal usage only).
When a "rstream.mrg32k3a" 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.mrg32k3a")
:
Whether or not the stream object is packed.
signature(object = "rstream.mrg32k3a")
:
Pack or unpack object: set packed to TRUE
or FALSE
.
Josef Leydold josef.leydold@wu.ac.at
underlying generator: Pierre L'Ecyuer and Richard Simard
The underlying RngStreams library uses a global variable to store the package seed. This variable is also stored inside R. Whenever a new instance of a "rstream.mrg32k3a" object is created the value of global variable is set to the value of the R object. Thus there is no problem when such "rstream.mrg32k3a" objects are packed for using in later R sessions. However, if such packed objects are not stored in the workspace image, then the R variable gets lost and there is a (extremely small) chance that newly created objects are not stochastically independent from restored objects.
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
,
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
.
## create a new rstream.mrg32k3a object
s <- new("rstream.mrg32k3a")
## show state of this object
print(s)
## show and change name of stream object
rstream.name(s)
rstream.name(s) <- "mystream"
## get a random number
x <- rstream.sample(s)
## get a random sample of size 100
x <- rstream.sample(s,100)
## reset random stream
rstream.reset(s)
## show and set antithetic flag
rstream.antithetic(s)
rstream.antithetic(s) <- TRUE
## jump to next substream
rstream.nextsubstream(s)
## make a clone of the rstream object
sc <- rstream.clone(s)
## pack and unpack the rstream object
rstream.packed(s) <- TRUE
rstream.packed(s) <- FALSE
Run the code above in your browser using DataLab