This class is obsolete and should be replaced by class
"rstream.mrg32k3a"
!
This is the old class that 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.lecuyer", name, seed, force.seed, antithetic,
incprecision)
.
An arbitrary string to name the stream object.
If omitted a string that consists of lecuyer
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.lecuyer 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.lecuyer" provides the following methods for
handling "rstream.lecuyer" 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.lecuyer")
:
Get a random sample from the stream object.
signature(object = "rstream.lecuyer")
:
Same as rstream.sample
.
signature(object = "rstream.lecuyer")
:
Reset stream into initial state.
signature(object = "rstream.lecuyer")
:
Set state of stream to next substream.
signature(object = "rstream.lecuyer")
:
Reset current substream into starting state.
Antithetic random streams and increased precision:
signature(object = "rstream.lecuyer")
:
Whether or not the stream object returns antithetic random
numbers.
signature(object = "rstream.lecuyer")
:
Change antithetic flag (TRUE
or FALSE
).
signature(object = "rstream.lecuyer")
:
Whether or not the stream object returns random numbers with
increased precision.
signature(object = "rstream.lecuyer")
:
Change flag for increased precision (TRUE
or FALSE
).
Handling "rstream.lecuyer" objects:
signature(x = "rstream.lecuyer")
:
Print state of the stream object.
signature(object = "rstream.lecuyer")
:
The name of the stream object.
signature(object = "rstream.lecuyer")
:
Change the name of the stream object.
signature(object = "rstream.lecuyer")
:
Make a copy (clone) of stream object.
signature(.Object = "rstream.lecuyer")
:
Initialize rstream object. (For Internal usage only).
When a "rstream.lecuyer" 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.lecuyer")
:
Whether or not the stream object is packed.
signature(object = "rstream.lecuyer")
:
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.lecuyer" 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.lecuyer" 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.mrg32k3a
,
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.lecuyer object
s <- new("rstream.lecuyer")
## 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