Learn R Programming

rstream (version 1.0)

rstream.lecuyer-class: Class "rstream.lecuyer" -- Multiple streams from Pierre L'Ecuyers RngStreams package

Description

This class implements the "rstream" interface for Pierre L'Ecuyer's RngStreams package. 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).

Arguments

Objects from the Class

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

  • name:
{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.} 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.lecuyer 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.

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.lecuyer" object is created the value of global variable is set to the value of the Robject. Thus there is no problem when such "rstream.lecuyer" objects are packed for using in later Rsessions. However, if such packed objects are not stored in the workspace image, then the Rvariable gets lost and there is a (extremely small) chance that newly created objects are not stochastically independent from restored objects.

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-class, 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

Run this code
## 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