powered by
Generate random variates from the Kolmogorov-Smirnov distribution.
This is not directly related to the Polya-Gamma technique, but it is a nice example of using an alternating sum to generate a random variate.
rks(N=1)
The number of random variates to generate.
The density function of the KS distribution is
$$ f(x) = 8 \sum_{i=1}^\infty (-1)^{n+1} n^2 x e^{-2 n^2 x^2}. $$
We follow Devroye (1986) p. 161 to generate random draws from KS.
L. Devroye. Non-Uniform Random Variate Generation, 1986.
# NOT RUN { X = rks(1000) # }
Run the code above in your browser using DataLab