4 ms·
I have to disagree with this. It would easier conceptually and faster computationally to use rejection sampling: do { x = uniform() y = uniform()
by mturmon 13y ago
I have to disagree with this. It would easier conceptually and faster computationally to use rejection sampling:
do {
x = uniform()
y = uniform()
r = x*x + y*y
} while (r > 1)
x = x/sqrt(r)
y = y/sqrt(r)
This does generalize to higher dimensions d, although as d gets large, you waste more samples. For spheres embedded in a handful of dimensions, it would still be fine, and it avoids all the transcendental functions associated with Normal variates. It's due to Marsaglia (1972).
- ColinWright 13y agoIt's simple, clean, clear, and works well in low dimensions. I regularly work in a few thousand dimensions, and it doesn't work at all because the volume of the sphere is too small. These are great discussions to have with a candidate. If they already know these things then you can see if they understand why, and if they don't already know these things, you can see how they react to learning new and rather esoteric stuff that turns out to be useful.
- RyanZAG 13y agoIntriguing, what do you use something like this random multi dimensional sphere for?
- ColinWright 13y agoChoosing a random direction uniformly for various varieties of hill-climbing optimization algorithms. The uniformity is necessary for the analysis of termination conditions.