Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

if the vector $\mathbf x$ is sampled randomly from a uniform distribution on $[0, 1]^d$, what is the probability density function for $|\mathbf x|$? Is it easy to scale for $[0, n]^d$?

share|cite|improve this question
The probability that |x| is in (a,b) is the measure of the hypershell from radius a to b intersected with the hypercube. This should be an iterated integral. – Mark May 17 '13 at 20:00
@Mark Sorry, but I don't understand. Can you dumb it down a bit :) ? – Matt Munson May 17 '13 at 20:09
See my answer below or yoBS's illustration below – Mark May 17 '13 at 22:03
up vote 2 down vote accepted

A partial answer. If $X$ is uniformly distributed in $[0,1]$ then $X^2$ has pdf $$f(t) = \frac{1}{2 \sqrt{t}}$$ for $t \in [0,1]$. Therefore the pdf of $| \mathbf{x}| = (\mathbf{x}_1^2 + \dotsc + \mathbf{x}_d^2)^{\frac{1}{2}}$ for $\mathbf{x} \in [0,1]^d$ is $$f_d(t) = 2t \, f^{\ast d}(t^2)$$ where $f^{\ast d}$ is the $d$-fold convolution of $f$. It looks like this pdf gets complicated quickly. For example already for $d=2$ using WA I get the following pdf:

$$ f_2(t) = \begin{cases} \frac{\pi t}{2} & \textrm{if } t\in[0,1]\\[1ex] t \left(\arcsin(t^{-1})-\arctan \sqrt{t^2-1}\right) & \textrm{if } t\in[1, \sqrt{2}] \end{cases} $$

share|cite|improve this answer
What is WAI? Is it a general trend that arbitrary pdf's are hard to solve? The question seemed so simple conceptually... I'm 2/2 now for getting unexpectedly difficult solutions to questions about conceptually simple pdf's. – Matt Munson May 17 '13 at 20:07
@MattMunson WolframAlpha – oldrinb May 17 '13 at 20:22
@oldrinb oh derp, its just WA... – Matt Munson May 17 '13 at 20:32

I'll try to explain and expand mark's comment.

Think for a momnet in two dimensions. The probability density that $|x|=r$ is the probability that a uniformly chosen point lies at a distance $r$ from the origin. This equals the length of an arc of a circle of radius $r$, intersected with the unit box. See the circles in the drawing:

enter image description here

It is therefore clear that for $r<1$ the PDF will be $\frac{\pi r}{2}$. For $r>1$ simple trigonometry shows that this arclength is $\frac{\pi}{2}-2\cos^{-1}\left(\frac{1}{r}\right)$. So we get that for 2D $$f(r)=\begin{cases} \frac{\pi }{2}r & r<1 \\ \frac{\pi }{2}-2\cos^{-1}\left(\frac{1}{r}\right) & r\geq 1 \\ \end{cases}$$ Which is the result that WimC gave, but simplified.

In a general dimension, finding the hyper-area of the intersection of the $d-1$ sphere with the hypercube is pretty complicated for $r>1$. However, it is quite simple for $r<1$ - the sphere is completely contained in the first hyper-quadrant, so its area is simply it's total area divided by $2^d$. We get that for a general dimension $d$ the PDF is

$$f(x)=\begin{cases} \frac{v_{d-1}}{2^d}r^{d-1} & r<1 \\[5mm] ??? & r\geq 1 \\ \end{cases}$$

Where $v_{d-1}$ is the area of the unit $d-1$ sphere.

share|cite|improve this answer

You want to think about how to calculate the measure of a hypersphere of radius $r$. If we have $n$ dimensions, we are asking for the set $\sum x_i^2 \le r^2$. This is because this set describes all the points with magnitude $r$ or less. If we imagine points distributed uniformly throughout this hypersphere, we will see that the probability of finding a point at radius $r$ is related to the size of the shell with radius $r$.

We can calculate the measure of this hypersphere by doing an iterated integral. For the four dimensional case we have:
$2^4\int_0^r \int ^{\sqrt{r^2-x_1^2}}_0 \int_0 ^\sqrt{r^2-x_1^2-x_2^2}\int_0^\sqrt{r^2-x_1^2-x_2^2-x_3^2} dx_4 dx_3 dx_2 dx_1$

We can easily generalize this to any dimension. Then we note that the actual problem asks for the density inside a hypercube, so we only take the portion of the hypersphere which intersects our hypercube.

Let $M(x) = \text{min}(x,1)$. Then we drop our $2^n$ factor because we are only worried about positive components. Then our CDF$(r)$ is

$\int_0^{M(r)} \int ^{M(\sqrt{r^2-x_1^2})}_0 \int_0 ^{M(\sqrt{r^2-x_1^2-x_2^2})}\int_0^{M(\sqrt{r^2-x_1^2-x_2^2-x_3^2})} dx_4 dx_3 dx_2 dx_1$

For $r \le 1$ we have an easy solution because the $M$s disappear and we end up with the volume of the n-dimensional hypersphere of radius $r$ divided by $2^n$. I will update the solution if I find a simpler form where $r \gt 1$.

Here is a different formulation / generalization to arbitrary dimension:
Let a particle appear with equal likelihood in any part of the unit n-hypercube. For $r \ge 0$ Let $F_n(r)$ be the probability that the particle will appear within $r$ distance of the origin.
Obviously $F_1(r) =\text{min}(1,r)$ because the one-dimensional case is a line segment of length 1. (this is just a silly way of writing the uniform CDF because I don't know how to format latex)

Now let's try to compute $F_n(r)$ in terms of $F_{n-1}$ by imagining that the particle is restricted to a hyperplane where one of the coordinates is fixed to $k$. That is, it must appear in the plane $\{k\} \times [0,1]^{n-1}$. Since we are only allowed to go $r$ distance away from the origin and we used up $k$ distance already, we can only use $\sqrt{r^2 - k^2}$ distance in traveling away from the origin of the sub-cube $[0,1]^{n-1}$.

$F_n(r) = P(\sum{x_i^2} \le r^2)$
$ = \int_0^1P(\sum x_i^2 \le r^2 | x_1 = k)f_{x_1}(k)dk $
$ = \int_0^1P(\sum_{i\ne1} x_i^2 \le r^2 - k^2 | x_1 = k)dk $
$ = \int_0^1P(\sum_{i\ne1} x_i^2 \le r^2 - k^2 | x_1 = k)\mathbb{I}\{k \le r\le 1\}dk $
$ = \int_0^rP(\sum_{i\ne1} x_i^2 \le r^2 - k^2 | x_1 = k)\mathbb{I}\{r\le 1\}dk $
$ = \int_0^rF_{n-1}(\sqrt{r^2-k^2})\mathbb{I}\{r\le 1\}dk $
$ = \int_0^{\text{min}(r,1)}F_{n-1}(\sqrt{r^2-k^2})dk $

So we end up with:
$F_n(r) = \int_0^{\text{min}(r,1)}F_{n-1}(\sqrt{r^2-k^2})dk$
$F_1(r) =\text{min}(1,r)$

Of course if you expand this formula for $F_4$ you will get the same four dimensional case mentioned above.

share|cite|improve this answer

There are many different probability densities of continuous distributions on $[0,1]^d$. There are also many probability distributions on that set that do not have densities, including, but not limited to, discrete distributions and mixtures of discrete and continuous distributions. A point could be randomly sampled from any of those distributions.

There is a somewhat uninformed usage that is commonplace among mathematicians who are not probabilists, according to which "randomly" means "uniformly distributed". It that is what is meant, then the density is equal to $1$ everywhere within that cube. On $[0,n]^d$ the density of the uniform distribution is $n^{-d}$ at every point.

Later edit: As noted in the comments, my answer ends before getting to the hard part. Maybe I'll add more later if no one beats me to it.

The conditional density given the order in which the coordinates appear when sorted, does not depend on which order it is. Therefore, we can condition on the event that $x_1<x_2<x_3<\cdots<x_n$ and we get the same distribution.

share|cite|improve this answer
I think the OP asked for the density of $|x|$. – Narut Sereewattanawoot May 17 '13 at 18:17
Oh. OK, my answer is incomplete. Maybe I'll add more later. – Michael Hardy May 17 '13 at 18:28
Edited my question to clarify that I am asking about the case where $x$ is sampled from the uniform distribution on $[0,1]^d$. And, yes, I am asking about the density of $|x|$. – Matt Munson May 17 '13 at 19:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.