# PDF of uniform distribution over the hypersphere and the hyperball

There are some good questions and answers about picking random multivariate points over the surface of the hypersphere and the volume of the hyperball, just like this and this.

However none of the answers provide probability density function (PDF) for these distributions.

The related Wolfram Mathworld articles (this and this) also lack the PDFs.

The missing PDFs should be in the form $P(x; x_0, r)$.

where the parameters are

• $x_0$ is the location (center) of the hypersphere/hyperball
• $r$ is the radius of the hypersphere/hyperball

More specifically, the methods in question are the following:

Picking a random multivariate over the hypersphere:

If $X = (X_1, \ldots, X_n)$ are independent (iid) standard normal variates, then $x_0 + r \frac{X}{||X||_2}$ is uniformly distributed over the surface of the n-sphere (in the geometer's sense) with location $x_0$ and radius $r$.

Picking a random multivariate over the hyperball:

If $X = (X_1, \ldots, X_n)$ are independent (iid) standard normal variates, and $Y$ is a standard exponential ($\lambda = 1$) variate, then $x_0 + r \frac{X}{\sqrt{Y + ||X||_2^2}}$ is uniformly distributed over the volume of the n-ball with location $x_0$ and radius $r$.

Alternatively, using a variate $U$ uniformly distributed over $[0,1]$, the expression $x_0 + r U^{1/n} \frac{X}{||X||_2}$ is also uniformly distributed over the hyperball.

Maybe I'm missing something, but I'm not sure why it would be any more complicated than $$\mathcal{P}(\vec{x};\vec{x_0},r) = \frac{1}{V_n} \Theta(r - ||\vec{x} - \vec{x_0}||)$$ for the interior of a hyperball, and $$\mathcal{P}(\vec{x};\vec{x_0},r) = \frac{1}{S_n} \delta(||\vec{x} - \vec{x_0}|| - r)$$ for the surface of a hypersphere.

The notation here is that

• $\Theta(x)$ is the Heaviside step function,
• $\delta(x)$ is the Dirac delta function,
• $S_n = 2 \pi^{n/2} r^{n-1} / \Gamma(n/2)$ is the surface area of an $n$-sphere, and
• $V_n = S_n r/n$ is the volume of an $n$-ball.

EDIT: to show that these have the correct normalization, we use polar coordinates centered at $\vec{x}_0$; in other words, we define $\rho = \| \vec{x} - \vec{x}_0 \|$ and let the other $n-1$ coordinates be angular coordinates $\theta_1, \theta_2, \dots$ on the $n$-sphere. For the surface of a hypersphere, we then have $$\int_{\mathbb{R}^n} \mathcal{P}(\vec{x};\vec{x}_0,r) d^n x = \frac{1}{S_n} \int_0^\infty \delta(\rho - r) (\rho^{n-1} \, d\rho \, d\Omega)$$ where $d^{n-1} \Omega$ stands for the solid angle element in $\mathbb{R}^n$. This is then equal to $$\frac{1}{S_n} \left[ \int_0^\infty \delta(\rho - r) \rho^{n-1} d\rho \right] \left[ \int d \Omega \right]$$ The integral of the solid angle in $n$ dimensions is a [well-known result], while the "picking property" of the delta function means that the radial integral is equal to $r^{n-1}$; so the integral becomes $$\frac{1}{S_n} \left[ r^{n-1} \right] \left[ \frac{2 \pi^{n/2}}{\Gamma(n/2)} \right] = 1.$$

The proof for the interior of the hyperball proceeds similarly, except this time the integral over $\rho$ is $$\int_0^{\infty} \Theta(r - \rho) \rho^{n-1} \, d \rho = \int_0^r \rho^{n-1} \, d\rho = \frac{r^n}{n}.$$ This factor and the angular factor then cancel out with the factor of $1/V_n$. (In the first equality above, we use the fact that $\Theta(r - \rho) = 0$ for $r > \rho$ and 1 for $r < \rho$.)

• Great answer. I plotted the densities in Mathematica, and they seem right. – plasmacel May 10 '17 at 23:13
• I guess the Dirac delta can be exchanged with any piecewise function which has a nonzero value only at $0$. – plasmacel May 10 '17 at 23:30
• @plasmacel: The Dirac delta "function" is not really well-defined as a function; it has the property that the integral $$\int_a^b \delta(x) \, dx$$ is 1 if $a < 0 < b$ and zero otherwise. Informally, it's equal to 0 everywhere except at $x = 0$, while $\delta(0)$ is infinite. You can read more about it on the Wikipedia page linked above. – Michael Seifert May 11 '17 at 1:40
• I meant that $\delta(x)$ in the formula can be changed to the piecewise function $f(x) = \begin{cases}1 & x = 0 \\ 0 & otherwise\end{cases}$. So this way the probability density is $1$ instead of $\infty$ on the surface of the sphere, and of course $0$ otherwise. – plasmacel May 11 '17 at 2:45
• @plasmacel: If you do that, then the integral of the probability distribution over $\mathbb{R}^n$ will be zero; but by the usual probability normalization condition it should be 1. This will also be the case if $f(x)$ has any finite value at $x = 0$. Intuitively, the probability density needs to be infinite at $x = 0$, since there is a non-zero probability in any arbitrarily thin spherical shell containing the hypersphere $\| \vec{x} - \vec{x}_0 \| = r$. – Michael Seifert May 11 '17 at 13:23