dau.new: UNU.RAN generator based on the Alias method (DAU)

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

UNU.RAN random variate generator for discrete distributions with given probability vector. It applies the Alias-Urn method (‘DAU’).

[Universal] – Patchwork Method.

Usage

1
2
dau.new(pv, from=1)
daud.new(distr)

Arguments

pv

vector of non-negative numbers (need not sum to 1). (numeric vector)

from

index of first entry in vector. (integer)

distr

distribution object. (S4 object of class "unuran.discr")

Details

This function creates a unuran object based on ‘DAU’ (Discrete Alias-Urn method). It can be used to draw samples of a discrete random variate with given probability vector using ur.

Vector pv must be postive but need not be normalized (i.e., it can be any multiple of a probability vector).

The method runs fast in constant time, i.e., marginal sampling times do not depend on the length of the given probability vector. Whereas their setup times grow linearly with this length.

Notice that the range of random variates is from:(from+length(pv)-1).

Alternatively, one can use function daud.new where the object distr of class "unuran.discr" must contain all required information about the distribution.

Value

An object of class "unuran".

Author(s)

Josef Leydold and Wolfgang H\"ormann [email protected].

References

W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 3.2 (The Alias Method).

A.J. Walker (1977): An efficient method for generating discrete random variables with general distributions. ACM Trans. Model. Comput. Simul. 3, pp.253–256.

See Also

ur, unuran.discr, unuran.new, unuran.

Examples

1
2
3
4
5
6
7
8
9
## Create a sample of size 100 for a 
## binomial distribution with size=115, prob=0.5
gen <- dau.new(pv=dbinom(0:115,115,0.5), from=0)
x <- ur(gen,100)

## Alternative approach
distr <- udbinom(size=100,prob=0.3)
gen <- daud.new(distr)
x <- ur(gen,100)

Runuran documentation built on Feb. 4, 2020, 9:09 a.m.