Required: probability vector (PV) or the PMF along with a finite domain
Speed:
Set-up: slow (linear with the vector-length)
Sampling: very fast
DAU samples from distributions with arbitrary but finite probability vectors
(PV) of length N. The algorithm is based on an ingenious method by A.J.
Walker and requires a table of size (at least) N. It needs one random number
and only one comparison for each generated random variate. The setup time for
constructing the tables is O(N).
By default, the probability vector is indexed starting at 0. However, this
can be changed by passing a domain parameter. When domain is given
in combination with the PV, it has the effect of relocating the
distribution from (0,len(pv)) to (domain[0], domain[0]+len(pv)).
domain[1] is ignored in this case.
>>> rng=DiscreteAliasUrn(pv,domain=(10,13),random_state=urng)>>> rng.rvs()12 # may vary
The method also works when no probability vector but a PMF is given.
In that case, a bounded (finite) domain must also be given either by
passing the domain parameter explicitly or by providing a support
method in the distribution object: