How to normalize a vector such that the sum of its squared elements is some arbitrary c

normed-spacesrandomvectors

I am trying to generate points (vectors) from the $L^2$ unit norm hypersphere uniformly at random.

This post says to:

  1. Generate a random Gaussian $d$-dimensional vector $v$.
  2. Generate a random uniform number $u$ in $[0, 1]$.
  3. "Normalize the vector to norm $u^{1/d}$."

Unfortunately, I don't understand how to do step (3). I believe that to normalize a vector to 1, one would compute $\frac{v}{norm(v)}$. I have considered computing $\frac{v}{u^{1/d}}$, but this doesn't make sense to me, since in the first case our divisor was $norm(v)$ despite the fact that the desired norm of 1 was not equal to $norm(v)$.

In another post referenced by the above, someone has commented a Matlab implementation of the solution, which suggests that I should compute: $\frac{v u^{1/d}}{norm(v)}$… but I don't understand the rationale for this.

Could someone confirm that the latter method is correct, and perhaps explain how so? Is there a general way to normalize a $d$-dimensional vector so that its $L^p$ norm is $c$?

Best Answer

Note that this is the strategy for random points in a unit ball, not for random points on a unit sphere.

Let us assume you have generated $v$ as a Gaussian $d$-dimensional vector. Normalizing this to length $1$ is done by using $\frac{v}{\|v\|}$ as you correctly stated. This results in a uniform distribution on the surface of the unit sphere, as described in the article about hypersphere point picking.

In order to get points inside of the ball, you have to use another random variable to specify the distance from the origin. If you simply used a uniform distribution for this, you would get too many points near the origin and not enough points near the surface.

But if you take a variable $u$ with a uniform distribution and raise it to the $\frac{1}{d}$-th power, the resulting distribution ensures that the distribution of points inside the ball is uniform. In a manner of speaking, applying the $\frac{1}{d}$-th power moves the points outwards by just the correct amount to get a uniform distrubution in the ball.