# Sampling from the surface of a sphere in n dimensions with specific centre

I have a point $$p$$ on the surface of a unit sphere. I want to sample points from the surface of the sphere, such that the probability density of a point $$q$$ on the surface is given by $$$$f(q) \propto \exp(p^T q)$$$$

For simplicity, we can think of $$p = (1,0,0,0,...)$$. Is it possible to do it analytically? Can someone suggest how to do it?

On the unit sphere $$S^{n-1}=\{x\in \mathbb{R}^n \colon x^T x=1\}$$, $$q^T p$$ varies only between $$-1$$ and 1, so the densitiy $$f$$ does not vary too much. So it would be simple to implement rejection sampling. Then we must start with samling a point uniformly on the sphere, that is easy. Just draw $$X$$ from a spherical multivariate normal distribution (that is with mean zero and unit covariance matrix), and scale to norm 1. See How to generate uniformly distributed points on the surface of the 3-d unit sphere?

Then the rejection phase: Rescale the density $$f$$ so that its maximum value is 1, that is: $$f(q)= \exp(p^T q-1)$$ and use that for the rejection phase, resulting in the algorithm:

1. Draw $$X \sim \mathcal{N}_n(0,I)$$.

2. Draw $$P \sim \mathcal{U}(0,1)$$.

3. Accept $$X$$ if $$P \le \exp(p^T X-1)$$ else reject.

This is simple and maybe fast enough? If not fast enough, tell us.

• Thanks. I did something similar since I need to compute the expectation of a gradient only: 1) Sample n points $x_1, ..., x_n$ from standard normal. 2) Project on the sphere. Let them be $q_1,...q_n$. 3) Compute $\exp(p^T q)$ for these points and normalise to get a total probability of $1$. 4) Use these normalised probabilities to compute the expectation – user2808118 Feb 6 at 5:32