How to test if vectors are equidistributed on the unit sphere

583 Views Asked by At

I can create a large collection of normalized real valued $n$-dimensional vectors from some random process which I hypothesis should be equidistributed on the unit sphere. I would like to test this hypothesis.

  • What is a good way numerically to test if vectors are equidistributed on the unit sphere? I am writing computer code so I will be testing that way
  • Is there some way to visualise the distribution given that my vectors are in $n$ dimensions?
3

There are 3 best solutions below

2
On

In the whole vector space defined by your normalised vectors in $\mathbb{R}^n$, you can try to find the inner product of the vectors (in $\mathcal{L}_2$ space) and with the output, you can decide whether it is equidistributed on the unit sphere (n-dimension).

This is one of the numerically reliable method.

0
On

I would proceed on the basis that a (hollow) sphere with $N$ mass = $1$ points uniformly distributed shall have mass-centre (1st moment) =$0$, moment of inertia (2nd moment) = $\rho (n)N$, around any ax. Where $\rho (n) = 2/3$ in the case $n=3$, while for the n-dimensional sphere in general it shall be calculated .

Therefore the $n$-vector of the mass-centre and that of the inertia could be a start to statistically evaluate the hypothesis of uniform distribution.

1
On

From this paper by Cai, Fan, Jiang: you can calculate angles $\theta_{ij}$ between pairs of vectors $\vec{v}_i$, $\vec{v}_j$ from your collection, $1 \leq i < j \leq N$ (where $N$ is the total number of vectors). If the vectors have a uniform distribution on the $(n-1)$-sphere, then these angles should be distributed according to $$ h(\theta) = \frac{1}{\sqrt{\pi}} \frac{\Gamma\left(\frac{n}{2}\right)}{\Gamma\left(\frac{n-1}{2}\right)} \cdot \left(\sin \theta\right)^{n-2}, \quad \theta\in[0,\pi], $$ where $\Gamma(n)$ is the gamma function. This is a necessary condition for the uniform distribution on a sphere. And if I understand correctly, it is also sufficient (correct me if I am wrong - I am not an expert on this topic).

Here is a code in python that illustrates this.

import numpy as np
from numpy import sqrt, sin, arccos, pi
from numpy.linalg import norm
from scipy.special import gamma
import matplotlib.pyplot as plt

n = 15      # space dimension
N = 10000   # number of vectors

# Generate vectors (columns of v) uniformly distributed on the (n-1)-sphere
v = np.random.normal(0, 1, (n, N))
v_norms = norm(v, axis=0)
v = v / v_norms

# Calculate the angles between pairs of vectors
thetas = v.T @ v
thetas = thetas[np.triu_indices_from(thetas, 1)]
thetas = arccos(thetas)

# Plotting
fig, ax = plt.subplots(figsize=(14, 8), tight_layout=True)
ax.set_ylabel('pdf', fontsize=20)
ax.set_xlabel(r'$\theta_{ij}$', fontsize=20)
ax.hist(thetas, bins='auto', density=True, label='observed distribution')
x = np.linspace(0, pi, num=1000)
ax.plot(x, 1/sqrt(pi) * gamma(n/2)/gamma((n-1)/2) * (sin(x))**(n-2), color='red', linestyle='--', label=r'$\frac{1}{\sqrt{\pi}} \frac{\Gamma(n/2)}{\Gamma\left(\frac{n-1}{2}\right)} \left(\sin(\theta)\right)^{n-2}$')
plt.legend(loc='upper right', prop={'size': 18}, markerscale=4)
ax.set_xlim(0, pi)

plt.show()

picture

P.S. Book "Symmetric Multivariate and Related Distributions" by Fang, Kotz, Ng (1990) is another relevant reading on this topic.