rstream.mrg32k3a-class: Class "rstream.mrg32k3a" - Multiple streams with MRG32k3a...

Description Objects from the Class Extends Methods Warning Note Author(s) References See Also Examples

Description

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 from the Class

Objects can be created by calls of the form new("rstream.mrg32k3a", name, seed, force.seed, antithetic, incprecision).

name:

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.

seed:

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.

force.see:

A boolean. If the RngStreams package should be reseeded (which is not recommended) it must be TRUE. Default is FALSE.

antithetic:

A boolean. Whether or not antithetic random numbers should be produced. Default is FALSE.

incprecision:

A boolean. Whether or not random numbers with increased precision should be produced. Default is FALSE.

Extends

Class "rstream", directly.

Methods

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:

rstream.sample

signature(object = "rstream.mrg32k3a"): Get a random sample from the stream object.

r

signature(object = "rstream.mrg32k3a"): Same as rstream.sample.

rstream.reset

signature(object = "rstream.mrg32k3a"): Reset stream into initial state.

rstream.nextsubstream

signature(object = "rstream.mrg32k3a"): Set state of stream to next substream.

rstream.resetsubstream

signature(object = "rstream.mrg32k3a"): Reset current substream into starting state.

Antithetic random streams and increased precision:

rstream.antithetic

signature(object = "rstream.mrg32k3a"): Whether or not the stream object returns antithetic random numbers.

rstream.antithetic<-

signature(object = "rstream.mrg32k3a"): Change antithetic flag (TRUE or FALSE).

rstream.incprecision

signature(object = "rstream.mrg32k3a"): Whether or not the stream object returns random numbers with increased precision.

rstream.incprecision<-

signature(object = "rstream.mrg32k3a"): Change flag for increased precision (TRUE or FALSE).

Handling "rstream.mrg32k3a" objects:

print

signature(x = "rstream.mrg32k3a"): Print state of the stream object.

rstream.name

signature(object = "rstream.mrg32k3a"): The name of the stream object.

rstream.name<-

signature(object = "rstream.mrg32k3a"): Change the name of the stream object.

rstream.clone

signature(object = "rstream.mrg32k3a"): Make a copy (clone) of stream object.

initialize

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.

rstream.packed

signature(object = "rstream.mrg32k3a"): Whether or not the stream object is packed.

rstream.packed<-

signature(object = "rstream.mrg32k3a"): Pack or unpack object: set packed to TRUE or FALSE.

Warning

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.

Note

The slots of this class must not be accessed directly. Use the above methods instead.

"rstream" objects cannot simply be copied by <-. The new variable does not hold a copy of an "rstream" object but just points to the old object which might not be the wanted result (similar to R environments). Use rstream.clone instead.

One may miss a method for reseeding a random stream. However, there is no need for such a method as there is a method for resetting the stream to its initial state. I one needs a stream with a different stream, then a new rstream object should be created at all.

Packed objects must be unpacked before any other method can be applied.

Author(s)

Josef Leydold [email protected]

underlying generator: Pierre L'Ecyuer and Richard Simard

References

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.

See Also

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## 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

rstream documentation built on June 21, 2017, 5:02 p.m.