top | item 44998948

(no title)

mkaic | 6 months ago

My favorite way to generate random points on a n-dimensional sphere is to just sample n times from a Gaussian distribution to get a n-dimensional vector, and then normalizing that vector to the radius of the desired sphere.

discuss

order

ravin_gees|6 months ago

Wonder if you get any numerical instability here in high dimensions by doing a sum of exponentials? Probably not because they’re Gaussian (no long tails) but after looking at scipy.special.logsumexp [1] I’m a bit wary of sums of exponentials with float32. Would be curious to see if there’s any characterization of this (the cited paper in the article only considers the low dimensional case)

[1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.s...

Sharlin|6 months ago

Mentioned in the article. Surely you read it, didn't you?

dragonwriter|6 months ago

This is exactly the method the article describes as the most common method (though the article uses the more specific “standard normal” rather than the more general “gaussian” when describing the distribution), and notes generalizes efficiently to higher dimensions unlike accept/reject, but, as the article notes, the accept/reject method is more efficient for n=3.

_alternator_|6 months ago

The only reason I can think of that you’re getting downvoted because this is mentioned in the article. This is a strictly better method than the accept/reject method for this application. The runtime of the accept reject algorithm is exponential in the dimension because the ratio between the volume of the sphere is exponentially smaller than the volume of the hypercube.

I’d also point out that the usual way Gaussians are generated (sample uniformly from the unit interval and remap via the Gaussian percentile) can be expressed as sampling from a d-dimensional cube and then post-processing as well, with the advantage that it works in one shot. (Edit: typo)