Sampling on the sphere from $f(x) \propto x^TAx$
Richard Arnold

TL;DR
This paper introduces a sampling method for generating random unit vectors on a sphere according to a density proportional to quadratic forms, with an accompanying R implementation.
Contribution
It presents a novel sampling technique for vectors on the sphere based on quadratic form densities, including a practical R implementation.
Findings
Effective sampling from the specified distribution on the sphere.
Implementation in R facilitates practical application.
Potential use in statistical and machine learning models.
Abstract
A method for drawing random samples of unit vectors in with density proportional to where is a symmetric, positive definite matrix. Includes an R function which implements the method.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsMorphological variations and asymmetry · Point processes and geometric inequalities · Bayesian Methods and Mixture Models
Sampling on the sphere from
Richard Arnold
School of Mathematics and Statistics
Victoria University of Wellington
Wellington, New Zealand
1 Preliminaries
We wish to sample on the surface of the sphere from an axial distribution with density proportional to .
We assume that the matrix is symmetric, positive definite and can be diagonalised
[TABLE]
for orthogonal matrix and diagonal with for all .
Using the notation from (Arnold & Jupp, 2013) we can construct the density from an axial cardoid distribution
[TABLE]
where the last line follows from the requirement that which ensures that the desired proportionality holds.
In order to draw from this distribution we first take a draw from
[TABLE]
and then compute .
2 Construction
The dimensional vector has degrees of freedom which we parameterise as with for and (see, e.g. Mardia & Jupp, 2000, Ch. 9).
We then construct the vector as follows:
[TABLE]
Here we have defined the symbols
[TABLE]
and we further define
[TABLE]
Under this parameterisation the uniform distribution on the sphere has the form
[TABLE]
where is the Beta function and we define
[TABLE]
If the density is given by (2) then with respect to our chosen parameterisation of we have
[TABLE]
Integrating with respect to we obtain the marginal distribution over :
[TABLE]
Further integrations over lead to the general expression
[TABLE]
which holds for . When we ultimately have
[TABLE]
This latter distribution is a mixture of two Beta densities in . To simulate from it we proceed as follows:
Compute the mixture probabilities
[TABLE] 2. 2.
Draw 3. 3.
If draw
[TABLE]
otherwise if draw
[TABLE] 4. 4.
Draw D_{1}\sim\text{Categorical}((-1,+1);(\mbox{\frac{1}{2}},\mbox{\frac{1}{2}})) 5. 5.
Set .
To simulate we draw each conditional on by constructing the conditional distributions
[TABLE]
This is a mixture of three Beta densities in . The mixing proportions are
[TABLE]
corresponding to the three component densities \text{Beta}(\mbox{\frac{1}{2}},\mbox{\frac{p-j}{2}}), \text{Beta}(\mbox{\frac{3}{2}},\mbox{\frac{p-j}{2}}) and \text{Beta}(\mbox{\frac{1}{2}},\mbox{\frac{p-j+2}{2}}) respectively.
Thus to simulate
Compute the mixture probabilities , and using (17) 2. 2.
Draw 3. 3.
If draw
[TABLE]
otherwise if draw
[TABLE]
otherwise if draw
[TABLE] 4. 4.
Draw D_{j}\sim\text{Categorical}((-1,+1);(\mbox{\frac{1}{2}},\mbox{\frac{1}{2}})) 5. 5.
Set .
We carry out this procedure for . Note that the procedure is also defined for , in which case and we have the same two component mixture derived earlier.
The final step is to draw the angle . Its conditional distribution is given by
[TABLE]
This density has four-fold symmetry: and are all equivalent. To draw a value for we first draw and then solve the equation
[TABLE]
in the interval \phi^{\ast}\in[0,\mbox{\frac{\pi}{2}}]. We finally set to one of the four values with equal probability.
Once we have a full draw of the values we use (3) to construct the vector , and finally set as the random draw from .
3 R code
The following R function can be used to take draws from the density (1) where is a square, positive defnite matrix. The function returns an matrix, the rows of which are the random vectors.
rxax <- function(n,amat) { # Eigen decomposition ee <- eigen(amat) dvec <- eevectors csum <- rev(cumsum(rev(dvec))) p <- nrow(amat)
# Generate vectors in rotated frame where amat is diagonal
umat <- sapply(1:n,
function(i) {
avec <- rep(NA,p-1)
bvec <- rep(NA,p-1)
tvec <- rep(NA,p-2)
# generate t[1]...t[p-2]
avec[1] <- 0
bvec[1] <- 1
for(j in 1:(p-2)) {
pivec <- c( avec[j]*(p-j+1),
bvec[j]*dvec[j],
bvec[j]*csum[j+1] )
pivec <- pivec/sum(pivec)
i <- sample(1:3, size=1, prob=pivec)
b <- rbeta(1,
(c(1,3,1)/2)[i],
(c(p-j,p-j,p-j+2)/2)[i])
d <- sample(c(-1,1), size=1)
tvec[j] <- d*b
bvec[j+1] <- bvec[j]*(1-tvec[j]^2)
avec[j+1] <- avec[j] + dvec[j]*bvec[j]*tvec[j]^2
}
# generate phi[p-1]
ustar <- runif(1)
ffunc <- function(phi, uval, a, b, d1, d2) {
c1 <- (b/4)*(d1-d2)
c2 <- a + 0.5*b*(d1+d2)
(1/(2*pi)*( phi + c1*sin(2*phi)/c2 ) - uval/4)
}
# generate angle in (0,pi/2)
phistar <- uniroot(ffunc, c(0,pi/2),
uval=ustar, a=avec[p-1], b=bvec[p-1],
d1=dvec[p-1], d2=dvec[p])$root
# randomise over fourfold symmetry
phistar <- (sample(c(0,1),size=1)*pi
+sample(c(-1,+1),size=1)*phistar)
# construct uvec
uvec <- c( sqrt(bvec)[1:(p-2)]*tvec,
sqrt(bvec[p-1])*c(cos(phistar), sin(phistar)) )
})
# rotate back to natural frame
xmat <- t(rmat%*%umat)
return(xmat)
}
An example use of the function is as follows: we construct a suitable symmetric matrix at random and then take 10 draws from it.
amat <- array(rnorm(9),dim=c(3,3)) amat <- t(amat)%*%amat xmat <- rxax(10, amat) xmat
[,1] [,2] [,3]
[1,] 0.98674959 0.01738693 -0.1613163 [2,] -0.38065170 0.23323003 0.8948229 [3,] 0.24385388 -0.60136593 0.7608510 [4,] -0.44503351 -0.66007152 0.6051865 [5,] -0.85847885 -0.04198661 -0.5111274 [6,] 0.33440170 0.04373660 0.9414152 [7,] -0.09637544 -0.11457369 -0.9887288 [8,] 0.27959151 -0.70197708 0.6550242 [9,] 0.61130650 -0.18851719 0.7686128 [10,] -0.38150181 -0.76106892 0.5246241
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1(1)
- 2Arnold & Jupp (2013) Arnold, R. & Jupp, P. E. (2013), ‘Statistics of orthogonal axial frames’, Biometrika 100 , 571–586.
- 3Mardia & Jupp (2000) Mardia, K. V. & Jupp, P. E. (2000), Directional Statistics , Wiley, Chichester.
