I'd like to sample from "zipf" distribution from a bounded domain.
That is, assume that the domain is {1,...,N}, I'd like each element in the domain, i, to be chosen with probability proportional to i ** -a
, where a
is a parameter of the distribution.
numpy
provides a zipf sampler (numpy.random.zipf), but it does not allow me to restrict the domain.
How can I easily sample from such distribution?
If the distribution parameter, a
, is larger than 1, I can use the numpy
sampler by rejecting (and re-sampling) all samples larger than N
. However, since it does not restrict the sample range, trying to use any smaller values of a
does not work.
When the domain is finite, there shouldn't be a problem to use such a
s, and that is what I need for my application.