Von Mises–Fisher distribution

In directional statistics, the von Mises–Fisher distribution (named after Richard von Mises and Ronald Fisher), is a probability distribution on the $$(p-1)$$-sphere in $$\mathbb{R}^{p}$$. If $$p=2$$ the distribution reduces to the von Mises distribution on the circle.

Definition
The probability density function of the von Mises–Fisher distribution for the random p-dimensional unit vector $$\mathbf{x}$$ is given by:


 * $$f_{p}(\mathbf{x}; \boldsymbol{\mu}, \kappa) = C_{p}(\kappa) \exp \left( {\kappa \boldsymbol{\mu}^\mathsf{T} \mathbf{x} } \right),$$

where $$ \kappa \ge 0, \left \Vert \boldsymbol{\mu} \right \Vert = 1 $$ and the normalization constant $$C_{p}(\kappa) $$ is equal to


 * $$C_{p}(\kappa)=\frac {\kappa^{p/2-1}} {(2\pi)^{p/2}I_{p/2-1}(\kappa)},$$

where $$ I_{v}$$ denotes the modified Bessel function of the first kind at order $$v$$. If $$p = 3$$, the normalization constant reduces to
 * $$C_{3}(\kappa) = \frac {\kappa} {4\pi\sinh \kappa} = \frac {\kappa} {2\pi(e^{\kappa}-e^{-\kappa})}.$$

The parameters $$\boldsymbol{\mu}$$ and $$\kappa$$ are called the mean direction and concentration parameter, respectively. The greater the value of $$\kappa$$, the higher the concentration of the distribution around the mean direction $$\boldsymbol{\mu}$$. The distribution is unimodal for $$\kappa > 0$$, and is uniform on the sphere for $$\kappa = 0$$.

The von Mises–Fisher distribution for $$p=3$$ is also called the Fisher distribution. It was first used to model the interaction of electric dipoles in an electric field. Other applications are found in geology, bioinformatics, and text mining.

Note on the normalization constant
In the textbook, Directional Statistics by Mardia and Jupp, the normalization constant given for the Von Mises Fisher probability density is apparently different from the one given here: $$C_{p}(\kappa)$$. In that book, the normalization constant is specified as:
 * $$C^*_{p}(\kappa)=\frac {(\frac{\kappa}2)^{p/2-1}} {\Gamma(p/2)I_{p/2-1}(\kappa)}$$

where $$\Gamma$$ is the gamma function. This is resolved by noting that Mardia and Jupp give the density "with respect to the uniform distribution", while the density here is specified in the usual way, with respect to Lebesgue measure. The density (w.r.t. Lebesgue measure) of the uniform distribution is the reciprocal of the surface area of the (p-1)-sphere, so that the uniform density function is given by the constant:
 * $$C_{p}(0)=\frac{\Gamma(p/2)}{2\pi^{p/2}}$$

It then follows that:
 * $$C^*_{p}(\kappa) = \frac{C_{p}(\kappa)}{C_{p}(0)}$$

While the value for $$C_{p}(0)$$ was derived above via the surface area, the same result may be obtained by setting $$\kappa=0$$ in the above formula for $$C_{p}(\kappa)$$. This can be done by noting that the series expansion for $I_{p/2-1}(\kappa)$ divided by $$\kappa^{p/2-1}$$ has but one non-zero term at $$\kappa=0$$. (To evaluate that term, one needs to use the definition $$0^0=1$$.)

Support
The support of the Von Mises–Fisher distribution is the hypersphere, or more specifically, the $(p-1)$-sphere, denoted as

S^{p-1} = \left\{ \mathbf{x} \in \mathbb{R}^p : \left\| \mathbf{x} \right\| = 1 \right\} $$ This is a $$(p-1)$$-dimensional manifold embedded in $$p$$-dimensional Euclidean space, $$\mathbb{R}^p$$.

Relation to normal distribution
Starting from a normal distribution with isotropic covariance $$\kappa^{-1}\mathbf{I}$$ and mean $$\boldsymbol{\mu}$$ of length $$r>0$$, whose density function is:
 * $$G_{p}(\mathbf{x}; \boldsymbol{\mu}, \kappa)

= \left(\sqrt{\frac{\kappa}{2\pi}}\right)^p \exp\left( -\kappa \frac{(\mathbf{x}-\boldsymbol{\mu})'(\mathbf{x}-\boldsymbol{\mu})}{2} \right),$$ the Von Mises–Fisher distribution is obtained by conditioning on $$\left\|\mathbf{x}\right\|=1$$. By expanding
 * $$(\mathbf{x}-\boldsymbol{\mu})'(\mathbf{x}-\boldsymbol{\mu}) = \mathbf{x}'\mathbf{x} + \boldsymbol{\mu}'\boldsymbol{\mu} - 2\boldsymbol{\mu}' \mathbf{x},$$

and using the fact that the first two right-hand-side terms are fixed, the Von Mises-Fisher density, $$f_{p}(\mathbf{x}; r^{-1}\boldsymbol{\mu}, r\kappa)$$ is recovered by recomputing the normalization constant by integrating $$\mathbf{x}$$ over the unit sphere. If $$r=0$$, we get the uniform distribution, with density $$f_{p}(\mathbf{x}; \boldsymbol{0}, 0)$$.

More succinctly, the restriction of any isotropic multivariate normal density to the unit hypersphere, gives a Von Mises-Fisher density, up to normalization.

This construction can be generalized by starting with a normal distribution with a general covariance matrix, in which case conditioning on $$\left\|\mathbf{x}\right\|=1$$ gives the Fisher-Bingham distribution.

Mean direction
A series of N independent unit vectors $$x_i$$ are drawn from a von Mises–Fisher distribution. The maximum likelihood estimates of the mean direction $$\mu$$ is simply the normalized arithmetic mean, a sufficient statistic:
 * $$\mu = \bar{x}/\bar{R},

\text{where } \bar{x} = \frac{1}{N}\sum_i^N x_i, \text{and } \bar{R} = \|\bar{x}\|,$$

Concentration parameter
Use the modified Bessel function of the first kind to define


 * $$A_{p}(\kappa) = \frac {I_{p/2}(\kappa)} {I_{p/2-1}(\kappa)} . $$

Then:
 * $$\kappa = A_p^{-1}(\bar{R}) .$$

Thus $$\kappa$$ is the solution to
 * $$A_p(\kappa) = \frac{\left\| \sum_i^N x_i \right\|}{N} = \bar{R} .$$

A simple approximation to $$\kappa$$ is (Sra, 2011)
 * $$\hat{\kappa} = \frac{\bar{R}(p-\bar{R}^2)}{1-\bar{R}^2} ,$$

A more accurate inversion can be obtained by iterating the Newton method a few times
 * $$\hat{\kappa}_1 = \hat{\kappa} - \frac{A_p(\hat{\kappa}) - \bar{R}}{1-A_p(\hat{\kappa})^2 - \frac{p - 1}{\hat{\kappa}} A_p(\hat{\kappa})} ,$$
 * $$\hat{\kappa}_2 = \hat{\kappa}_1 - \frac{A_p(\hat{\kappa}_1)-\bar{R}}{1-A_p(\hat{\kappa}_1)^2-\frac{p - 1}{\hat{\kappa}_1} A_p(\hat{\kappa}_1)} .$$

Standard error
For N ≥ 25, the estimated spherical standard error of the sample mean direction can be computed as:
 * $$\hat{\sigma} = \left(\frac{d}{N\bar{R}^2}\right)^{1/2}$$

where
 * $$d = 1 - \frac{1}{N} \sum_i^N \left(\mu^Tx_i\right)^2$$

It is then possible to approximate a $$100(1-\alpha)\%$$ a spherical confidence interval (a confidence cone) about $$\mu$$ with semi-vertical angle:
 * $$q = \arcsin\left(e_\alpha^{1/2}\hat{\sigma}\right),$$ where $$e_\alpha = -\ln(\alpha).$$

For example, for a 95% confidence cone, $$\alpha = 0.05, e_\alpha = -\ln(0.05) = 2.996,$$ and thus $$q = \arcsin(1.731\hat{\sigma}).$$

Expected value
The expected value of the Von Mises–Fisher distribution is not on the unit hypersphere, but instead has a length of less than one. This length is given by $$A_p(\kappa)$$ as defined above. For a Von Mises–Fisher distribution with mean direction $$\boldsymbol{\mu}$$ and concentration $$\kappa>0$$, the expected value is:
 * $$A_p(\kappa)\boldsymbol{\mu}$$.

For $$\kappa=0$$, the expected value is at the origin. For finite $$\kappa>0$$, the length of the expected value is strictly between zero and one and is a monotonic rising function of $$\kappa$$.

The empirical mean (arithmetic average) of a collection of points on the unit hypersphere behaves in a similar manner, being close to the origin for widely spread data and close to the sphere for concentrated data. Indeed, for the Von Mises–Fisher distribution, the expected value of the maximum-likelihood estimate based on a collection of points is equal to the empirical mean of those points.

Entropy and KL divergence
The expected value can be used to compute differential entropy and KL divergence.

The differential entropy of $$\text{VMF}(\boldsymbol{\mu}, \kappa)$$ is:

\bigl\langle -\log f_{p}(\mathbf{x}; \boldsymbol{\mu}, \kappa)\bigr\rangle_{\mathbf{x}\sim\text{VMF}(\boldsymbol{\mu}, \kappa)} =-\log f_{p}(A_p(\kappa)\boldsymbol{\mu}; \boldsymbol{\mu}, \kappa) = -\log C_p(\kappa) -\kappa A_p(\kappa) $$ where the angle brackets denote expectation. Notice that the entropy is a function of $$\kappa$$ only.

The KL divergence between $$\text{VMF}(\boldsymbol{\mu_0}, \kappa_0)$$ and $$\text{VMF}(\boldsymbol{\mu_1}, \kappa_1)$$ is:

\Bigl\langle \log \frac{f_{p}(\mathbf{x}; \boldsymbol{\mu_0}, \kappa_0)} {f_{p}(\mathbf{x}; \boldsymbol{\mu_1}, \kappa_1)} \Bigr\rangle_{\mathbf{x}\sim\text{VMF}(\boldsymbol{\mu_0}, \kappa_0)} =\log \frac{f_{p}(A_p(\kappa_0)\boldsymbol{\mu_0}; \boldsymbol{\mu_0}, \kappa_0)} {f_{p}(A_p(\kappa_0)\boldsymbol{\mu_0}; \boldsymbol{\mu_1}, \kappa_1)} $$

Transformation
Von Mises-Fisher (VMF) distributions are closed under orthogonal linear transforms. Let $$\mathbf{U}$$ be a $$p$$-by-$$p$$ orthogonal matrix. Let $$\mathbf{x}\sim\text{VMF}(\boldsymbol\mu,\kappa)$$ and apply the invertible linear transform: $$\mathbf{y}=\mathbf{Ux}$$. The inverse transform is $$\mathbf{x}=\mathbf{U'y}$$, because the inverse of an orthogonal matrix is its transpose: $$\mathbf{U}^{-1}=\mathbf{U}'$$. The Jacobian of the transform is $$\mathbf{U}$$, for which the absolute value of its determinant is 1, also because of the orthogonality. Using these facts and the form of the VMF density, it follows that:
 * $$\mathbf{y}\sim\text{VMF}(\mathbf{U}\boldsymbol{\mu},\kappa).

$$ One may verify that since $$\boldsymbol{\mu}$$ and $$\mathbf{x}$$ are unit vectors, then by the orthogonality, so are $$\mathbf{U}\boldsymbol{\mu}$$ and $$\mathbf{y}$$.

General case
An algorithm for drawing pseudo-random samples from the Von Mises Fisher (VMF) distribution was given by Ulrich and later corrected by Wood. An implementation in R is given by Hornik and Grün; and a fast Python implementation is described by Pinzón and Jung.

To simulate from a VMF distribution on the $$(p-1)$$-dimensional unitsphere, $$S^{p-1}$$, with mean direction $$\boldsymbol{\mu}\in S^{p-1}$$, these algorithms use the following radial-tangential decomposition for a point $$\mathbf{x}\in S^{p-1}\subset\mathbb{R}^p$$ :

\mathbf{x} = t\boldsymbol{\mu}+\sqrt{1-t^2}\mathbf{v} $$ where $$\mathbf{v}\in\mathbb{R}^p$$ lives in the tangential $$(p-2)$$-dimensional unit-subsphere that is centered at and perpendicular to $$\boldsymbol{\mu}$$; while $$t\in[-1,1]$$. To draw a sample $$\mathbf{x}$$ from a VMF with parameters $$\boldsymbol{\mu}$$ and $$\kappa$$, $$\mathbf{v}$$ must be drawn from the uniform distribution on the tangential subsphere; and the radial component, $$t$$, must be drawn independently from the distribution with density:

f_\text{radial}(t;\kappa,p)=\frac{(\kappa/2)^\nu} {\Gamma(\frac12)\Gamma(\nu+\frac12)I_\nu(\kappa)} e^{t\kappa}(1-t^2)^{\nu-\frac12} $$ where $$\nu=\frac{p}2-1$$. The normalization constant for this density may be verified by using:

I_\nu(\kappa) = \frac{(\kappa/2)^\nu}{\Gamma(\frac12)\Gamma(\nu+\frac12)} \int_{-1}^{1}e^{t\kappa}(1-t^2)^{\nu-\frac12}\,dt $$ as given in Appendix 1 (A.3) in Directional Statistics. Drawing the $$t$$ samples from this density by using a rejection sampling algorithm is explained in the above references. To draw the uniform $$\mathbf{v}$$ samples perpendicular to $$\boldsymbol{\mu}$$, see the algorithm in, or otherwise a Householder transform can be used as explained in Algorithm 1 in.

3-D sphere
To generate a Von Mises–Fisher distributed pseudo-random spherical 3-D unit vector $\mathbf X_{s}$  on the $S^{2}$ sphere for a given $\mu$  and $\kappa$, define

$$\mathbf X_{s} = [r, \theta, \phi]$$

where $\theta$ is the polar angle, $\phi$  the azimuthal angle, and $r=1$  the distance to the center of the sphere

for $\mathbf \mu = [0,(.),1]$ the pseudo-random triplet is then given by

$$\mathbf X_{s} = [1, \arccos W, V]$$

where $V$ is sampled from the continuous uniform distribution $U(a,b)$  with lower bound $a$  and upper bound $b$

$$V \sim U(0, 2\pi)$$

and

$$W = \cos \theta = 1+ \frac {1} {\kappa} (\ln\xi+\ln(1- \frac {\xi-1} {\xi}e^{-2\kappa}))$$

where $\xi$ is sampled from the standard continuous uniform distribution $U(0,1)$

$$\xi \sim U(0, 1)$$

here, $W$ should be set to $W = 1$ when $\mathbf \xi=0$  and $\mathbf X_{s}$  rotated to match any other desired $\mu$.

Distribution of polar angle
For $$p = 3$$, the angle &theta; between $$\mathbf{x}$$ and $$\boldsymbol{\mu}$$ satisfies $$\cos\theta=\boldsymbol{\mu}^\mathsf{T} \mathbf{x}$$. It has the distribution
 * $$p(\theta)=\int d^2x f(x; \boldsymbol{\mu}, \kappa)\, \delta\left(\theta-\text{arc cos}(\boldsymbol{\mu}^\mathsf{T} \mathbf{x})\right)$$,

which can be easily evaluated as
 * $$p(\theta)=2\pi C_3(\kappa)\,\sin\theta\, e^{\kappa\cos\theta}$$.

For the general case, $$p\ge2$$, the distribution for the cosine of this angle:

\cos\theta = t = \boldsymbol{\mu}^\mathsf{T} \mathbf{x} $$ is given by $$f_\text{radial}(t;\kappa,p)$$, as explained above.

The uniform hypersphere distribution
When $$\kappa=0$$, the Von Mises–Fisher distribution, $$\text{VMF}(\boldsymbol{\mu},\kappa)$$ on $$S^{p-1}$$ simplifies to the uniform distribution on $$S^{p-1}\subset\mathbb{R}^p$$. The density is constant with value $$C_p(0)$$. Pseudo-random samples can be generated by generating samples in $$\mathbb{R}^p$$ from the standard multivariate normal distribution, followed by normalization to unit norm.

Component marginal of uniform distribution
For $$1\le i\le p$$, let $$x_i$$ be any component of $$\mathbf{x}\in S^{p-1}$$. The marginal distribution for $$x_i$$ has the density:

f_i(x_i;p) = f_\text{radial}(x_i;\kappa=0,p)=\frac{(1-x_i^2)^{\frac{p-1}2-1}}{B\bigl(\frac12,\frac{p-1}2\bigr)} $$ where $$B(\alpha,\beta)$$ is the beta function. This distribution may be better understood by highlighting its relation to the beta distribution:

\begin{align} x_i^2&\sim\text{Beta}\bigl(\frac12,\frac{p-1}2\bigr) &&\text{and}& \frac{x_i+1}{2}&\sim\text{Beta}\bigl(\frac{p-1}2,\frac{p-1}2\bigr) \end{align} $$ where the Legendre duplication formula is useful to understand the relationships between the normalization constants of the various densities above.

Note that the components of $$\mathbf{x}\in S^{p-1}$$ are not independent, so that the uniform density is not the product of the marginal densities; and $$\mathbf{x}$$ cannot be assembled by independent sampling of the components.

Distribution of dot-products
In machine learning, especially in image classification, to-be-classified inputs (e.g. images) are often compared using cosine similarity, which is the dot product between intermediate representations in the form of unitvectors (termed embeddings). The dimensionality is typically high, with $$p$$ at least several hundreds. The deep neural networks that extract embeddings for classification should learn to spread the classes as far apart as possible and ideally this should give classes that are uniformly distributed on $$S^{p-1}$$. For a better statistical understanding of across-class cosine similarity, the distribution of dot-products between unitvectors independently sampled from the uniform distribution may be helpful.

Let $$\mathbf{x},\mathbf{y}\in S^{p-1}$$ be unitvectors in $$\mathbb{R}^p$$, independently sampled from the uniform distribution. Define:

\begin{align} t&=\mathbf{x}'\mathbf{y}\in[-1,1], & r&=\frac{t+1}{2}\in[0,1], & s&=\text{logit}(r) =\log\frac{1+t}{1-t} \in\mathbb{R} \end{align} $$ where $$t$$ is the dot-product and $$r,s$$ are transformed versions of it. Then the distribution for $$t$$ is the same as the marginal component distribution given above; the distribution for $$r$$ is symmetric beta and the distribution for $$s$$ is symmetric logistic-beta:

\begin{align} r&\sim \text{Beta}\bigl(\frac{p-1}2,\frac{p-1}2\bigr), & s&\sim B_\sigma\bigl(\frac{p-1}2,\frac{p-1}2\bigr) \end{align} $$ The means and variances are:

\begin{align} E[t]&=0, & E[r]&=\frac12, & E[s]&=0, \end{align} $$ and

\begin{align} \text{var}[t]&=\frac1p, & \text{var}[r]&=\frac1{4p}, & \text{var}[s]&=2\psi'\bigl(\frac{p-1}2\bigr)\approx\frac4{p-1} \end{align} $$ where $$\psi'=\psi^{(1)}$$ is the first polygamma function. The variances decrease, the distributions of all three variables become more Gaussian, and the final approximation gets better as the dimensionality, $$p$$, is increased.

Matrix Von Mises-Fisher
The matrix von Mises-Fisher distribution (also known as matrix Langevin distribution ) has the density
 * $$f_{n, p}(\mathbf{X}; \mathbf{F}) \propto \exp(\operatorname{tr}(\mathbf{F}^\mathsf{T}\mathbf{X}))$$

supported on the Stiefel manifold of $$n \times p$$ orthonormal p-frames $$\mathbf{X}$$, where $$\mathbf{F}$$ is an arbitrary $$n \times p$$ real matrix.

Saw distributions
Ulrich, in designing an algorithm for sampling from the VMF distribution, makes use of a family of distributions named after and explored by John G. Saw. A Saw distribution is a distribution on the $$(p-1)$$-sphere, $$S^{p-1}$$, with modal vector $$\boldsymbol{\mu}\in S^{p-1}$$ and concentration $$\kappa\ge0$$, and of which the density function has the form:

f_\text{Saw}(\mathbf{x};\boldsymbol\mu,\kappa) = \frac{g(\kappa\mathbf x'\boldsymbol\mu)}{K_p(\kappa)} $$ where $$g$$ is a non-negative, increasing function; and where $$K_P(\kappa)$$ is the normalization constant. The above-mentioned radial-tangential decomposition generalizes to the Saw family and the radial compoment, $$t=\mathbf x'\boldsymbol\mu$$ has the density:

f_\text{Saw-radial}(t;\kappa)=\frac{2\pi^{p/2}}{\Gamma(p/2)}\frac{g(\kappa t)(1-t^2)^{(p-3)/2}}{B\bigl(\frac12,\frac{p-1}2\bigr)K_p(\kappa)}. $$ where $$B$$ is the beta function. Also notice that the left-hand factor of the radial density is the surface area of $$S^{p-1}$$.

By setting $$g(\kappa\mathbf x'\boldsymbol\mu)=e^{\kappa\mathbf x'\boldsymbol\mu}$$, one recovers the VMF distribution.

Weighted Rademacher Distribution
The definition of the Von Mises-Fisher distribution can be extended to include also the case where $$p=1$$, so that the support is the 0-dimensional hypersphere, which when embedded into 1-dimensional Euclidean space is the discrete set, $$\{-1,1\}$$. The mean direction is $$\mu\in\{-1,1\}$$ and the concentration is $$\kappa\ge0$$. The probability mass function, for $$x\in\{-1,1\}$$ is:

f_1(x\mid\mu,\kappa) = \frac{e^{\kappa\mu x}}{e^{-\kappa}+e^{\kappa}} = \sigma(2\kappa\mu x) $$ where $$\sigma(z)=1/(1+e^{-z})$$ is the logistic sigmoid. In the uniform case, at $$\kappa=0$$, this simplifies to the Rademacher distribution.