vMF Distribution

This page is machine-translated and may contain errors. Read the Chinese original

Read a paper on Zero-Shot (Zero-Shot Adaptation of Behavioral Foundation Models to Unseen Dynamics)
In it, different latent representations are used for RL tasks and RL dynamics
Using the dynamics latent h vector as a cluster center, and sampling task latent vectors z around it, one can obtain a clustered distribution of z vectors for different dynamics in task space
As shown in the figure below
The latent space here uses a normalized hypersphere, and a vMF distribution is used on the sphere as the sampling distribution for z
This note is a study note on the vMF distribution
alt text

From Gaussian Distribution to the vMF Distribution

Directional statistics studies data that lies on the unit sphere—compass readings, the direction of incident light, normalized word vectors, torsion angles of protein backbones, and so on. Such data cannot be modeled directly with an ordinary Gaussian, because the Gaussian is defined over the entire Rp . This article starts from the one-dimensional Gaussian and gradually transitions to the most central distribution in directional statistics: the von Mises–Fisher (vMF) distribution.


01 · One-Dimensional Gaussian Distribution

Let's start from the density function of a one-dimensional Gaussian distribution:

(1.1)f(x)=12πσexp(−(x−μ)22σ2)

Expand the square in the exponent:

(1.2)−(x−μ)22σ2=μσ2x−x22σ2−μ22σ2

The last term is independent of x and can be absorbed into the normalization constant. Thus, the "skeleton" of the Gaussian leaves only two parts: a linear term in x , and a quadratic term.

(1.3)f(x)∝exp(μσ2x−x22σ2)

The linear term μσ2x determines the location of the distribution; the quadratic term −x22σ2 determines its shape. But on the sphere there is no place for a quadratic term — this is exactly why the vMF is simpler than the Gaussian.

One-Dimensional Gaussian (density curve + real-time sampling)

一维高斯分布

Drag the slider to observe how μ shifts the curve and σ changes its width. The light-colored histogram is obtained by sampling from this distribution in real time, and it always matches the theoretical curve.


02 · Multivariate Isotropic Gaussian

Replace the scalar x with a p -dimensional vector x∈Rp , and take the covariance to be isotropic σ2I :

(2.1)N(x;μ,σ2I)=(2πσ2)−p/2exp(−∥x−μ∥22σ2)

Expand the squared Euclidean distance:

(2.2)∥x−μ∥2=∥x∥2−2μ⊤x+∥μ∥2

Substitute back into the exponential part:

(2.3)−∥x−μ∥22σ2=μ⊤xσ2⏟线性项−∥x∥22σ2⏟二次项−∥μ∥22σ2

Thus the density can be written compactly as:

(2.4)N(x)∝exp(μ⊤xσ2−∥x∥22σ2)

KeyPoint

μ⊤x measures the projection length of x along the mean direction. This term makes the density grow along the direction of μ ; while −∥x∥2/(2σ2) pulls the probability mass back toward the origin, preventing it from escaping to infinity.


03 · Normalizing the Distribution onto the Unit Sphere

Now impose the constraint: all data points lie on the unit sphere, i.e., x∈Sp−1 , satisfying ∥x∥=1 .

Substituting ∥x∥2=1 , that quadratic term immediately becomes a constant:

(3.1)−∥x∥22σ2=−12σ2=常数

The constant can be absorbed into the normalization factor. Thus only the linear term remains:

(3.2)f(x)∝exp(μ⊤xσ2)

Decompose the mean vector into direction and magnitude: μ=∥μ∥⋅μ^ , where ∥μ^∥=1 . Then:

(3.3)μ⊤xσ2=∥μ∥σ2μ^⊤x=κμ^⊤x

Physical meaning of the two parameters
κ=∥μ∥/σ2 is called the concentration parameter — the smaller the variance and the longer the mean, the more the distribution concentrates around μ^ .
μ^ is the mean direction, lying on the unit sphere.

At this point we have "guessed" the functional form of the vMF:

(3.4)f(x)∝exp(κμ⊤x)

Only one task remains: compute the normalization constant.


04 · The von Mises–Fisher Distribution

Let x∈Sp−1⊂Rp , mean direction μ∈Sp−1 , concentration κ≥0 :

(4.1)f(x;μ,κ)=Cp(κ)exp(κμ⊤x)

The normalization constant is given by the modified Bessel function Iν :

(4.2)Cp(κ)=κp/2−1(2π)p/2Ip/2−1(κ)

Why this form?

The core is computing this integral. Taking μ to point at the north pole, then μ⊤x=cos⁡θ :

(4.3)∫Sp−1eκμ⊤xdσ(x)=Ωp−1∫0πeκcos⁡θsinp−2⁡θdθ

where Ωp−1=2πp/2/Γ(p/2) is the total surface area of the unit sphere. This integral has a closed-form solution:

(4.4)∫Sp−1eκμ⊤xdσ(x)=(2π)p/2κ1−p/2Ip/2−1(κ)

Taking the reciprocal gives Cp(κ) . ◼

The most common special case: p=3

The 3-dimensional sphere S2 is the most common scenario in visualization and engineering. Using the elementary expressions for half-integer-order Bessel functions:

(4.5)I1/2(κ)=2πκsinh⁡κ

Substituting into p=3 :

(4.6)C3(κ)=κ1/2(2π)3/2I1/2(κ)=κ4πsinh⁡κ

Thus the vMF density on the 3-dimensional sphere is very clean:

(4.7)f(x;μ,κ)=κ4πsinh⁡κexp(κμ⊤x),x∈S2

Limiting behavior
As κ→0 , sinh⁡κ≈κ , so C3→1/(4π) — exactly the uniform distribution on the sphere.
As κ→∞ , the density collapses to a Dirac δ function located at μ .

The vMF distribution on S2

S² 上的 vMF 分布

Particles on the sphere below follow vMF(μ,κ) . Drag the sphere to rotate the view; increase κ to observe how the particles converge from a uniform spread into a spherical cap; change θμ,ϕμ to observe how the entire cap migrates.

05 · Projecting a Normal Distribution onto the Sphere

We now know the definitions of the Gaussian and vMF distributions. So how exactly are they connected?

The answer: normalize Gaussian samples to unit length. Let y∼N(μ,σ2I) be a Gaussian vector in Rp , and set

(5.1)x=y∥y∥∈Sp−1

Then the distribution followed by x is called the projected normal distribution, whose density is:

(5.2)f(x;μ,σ2)∝∫0∞rp−1exp(−∥rx−μ∥22σ2)dr

Expanding the norm, the dependence on r becomes clear:

(5.3)∥rx−μ∥2=r2−2r(μ⊤x)+∥μ∥2

In the isotropic case (covariance σ2I ), after integrating over r , all parts involving x reduce to just exp(∥μ∥μ^⊤x/σ2) . Thus:

(5.4)f(x;μ,σ2)=fvMF(x;μ^,κ),κ=∥μ∥σ2

Core conclusion
Radially normalizing an isotropic Gaussian yields exactly the vMF distribution. Conversely, vMF can also be viewed as "an isotropic Gaussian defined on the sphere." Two seemingly unrelated distributions differ only by a single normalization.

Geometric intuition

Imagine a Gaussian cloud in R3 centered at μ . Now slide each point along the ray from the origin onto the unit sphere — direction unchanged, only the radius changes. The cloud originally scattered in space gets "smeared" onto the sphere, forming a concentrated spot in the direction of μ .

The thinner the cloud (smaller σ ) and the farther the center is from the origin (larger ∥μ∥ ), the more compact the spot — this is exactly what κ=∥μ∥/σ2 means.

Continuous transition from Gaussian to vMF

高斯 → vMF 的连续过渡

The initial state ( t=0 ) is an isotropic Gaussian cloud in R3 , shown in amber; drag the transition slider or enable autoplay, and the particles slide radially onto the sphere ( t=1 ), with the color gradually turning cyan — that is the vMF distribution.

Drag the σ slider to change the Gaussian's spread, thereby changing the final vMF's κ . Observe: the smaller σ is, the more concentrated the final spot on the sphere.


06 · Sampling: Wood's Algorithm

To generate points on the sphere following a vMF distribution, the key is to exploit rotational invariance: first sample along the z axis, then rotate the result to μ .

Step 1: Sample the polar angle cosine ω=cos⁡θ

On S2 , the marginal density of ω is proportional to eκω (the sin⁡θ factor in the area element cancels out exactly when p=3 ). The cumulative distribution function is:

(6.1)F(ω)=eκω−e−κeκ−e−κ

Let F(ω)=u , u∼U(0,1) , and solve for the inverse:

(6.2)ω=1+1κln(u+(1−u)e−2κ)

Numerical stability
When κ is large, computing e2κ directly will overflow. The expression above rewrites the exponential as e−2κ , which automatically degenerates to ω≈1+ln⁡(u)/κ when κ→∞ , with no overflow throughout.

Step 2: Sample the azimuth and assemble

Take φ∼U(0,2π) , let s=1−ω2 :

(6.3)x0=(scos⁡φ,ssin⁡φ,ω)

Step 3: Rotate to μ

Construct an orthonormal basis (e1,e2,μ) with μ as the third axis, and output:

(6.4)x=x0,1e1+x0,2e2+x0,3μ

07 · Key Properties and Estimation

Mean Resultant Vector Length

The expectation of the vMF has a very concise form—the direction is simply μ , and the length depends only on κ :

(7.1)E[x]=Ap(κ)μ,Ap(κ)=Ip/2(κ)Ip/2−1(κ)

When p=3 , it reduces to the Langevin function form you may have seen before:

(7.2)A3(κ)=coth⁡κ−1κ

It grows monotonically from 0 to 1 : at κ=0 the direction is completely random, and at κ→∞ all points point toward μ .

Parameter Summary

Parameter Value Meaning
μ Sp−1 mean direction, unit vector
κ [0,∞) concentration; larger means more concentrated
κ=0 — uniform distribution on the sphere
κ→∞ — degenerates to the point μ
p=2 — circular vM distribution, C2=1/(2πI0(κ))
p=3 — C3=κ/(4πsinh⁡κ)

Maximum Likelihood Estimation

Given samples {x1,…,xn} , the log-likelihood is:

(7.3)ℓ(μ,κ)=nln⁡Cp(κ)+κμ⊤(∑i=1nxi)

Differentiating with respect to μ immediately yields: μ^ is the direction of the sample resultant vector, i.e.

(7.4)μ^=∑ixi‖∑ixi‖

And κ is implicitly determined by the equation Ap(κ^)=∥∑xi∥/n —there is no closed-form solution, so numerical solving is required (Newton's method typically converges within a few iterations).


08 · Summary

各向同性高斯N(x;μ,σ2I)→展开指数→施加约束∥x∥=1→二次项变成常数→只剩exp⁡(κμ⊤x)→补上球面归一化常数→vMF 分布

The isotropic Gaussian (projected normal) on the sphere and the vMF are equivalent. Because for points on the sphere, ∥x∥2=1 in the Gaussian density is a constant; the quadratic form x⊤Σ−1x of the projected normal also degenerates to a constant when Σ=σ2I . The two give exactly the same distribution family.

This also explains why the vMF is the undisputed "Gaussian" of directional statistics: it is simple, unimodal, has a conjugate prior, has efficient sampling algorithms, and at the two extremes of κ it covers the uniform distribution and a deterministic direction, respectively.