(Ross, p. 252)
Suppose we want to generate n
random points in the circle of radius r
centered at the origin, conditional on the event that no two points are within a distance d
of each other, where
is assumed to be a small positive number. (If were not small, then we could just continue to generate sets of
n
random points in the circle, stopping the first time that no two points in the set are within d
of each other.)
- Start with
n
points in the circle,, such that no two are within a distance
d
of each other. - Then generate a random number
U
and let.
- Generate a random point in the circle.
- If this point is not within
d
of any of the othern - 1
points excludingthen replace
by this generated point; otherwise, generate a new point and repeat the operation.
- After a large number of iterations, the set of
n
points will approximately have the desired distribution.
unif_circle.R
the function that implements the first step of the algorithm (initialization);gibbs_sampler.R
the function that does the rest of the algorithm steps;example.R
contains the code that implements the algorithm given some arbitrary parameters;gibbs_sampler_plot.png
illustrates the results of the algorithm (see the construction inexample.R
).