# Uniform sampling from general simplex with a twist

This is part of a question I had asked elsewhere, and then some of the links redirected me to CS stack exchange.

Given $0\leq a_1\leq\dots\leq a_D\leq1$ (all strictly positive), I want to draw points uniformly from

$\qquad X =\{(x_1, x_2, ..., x_D) \mid 0 \leq x_D \leq x_{D-1} \leq \dots \leq x_1\ , \sum_{i=1}^D a_i x_i = 1 \}$

How do I achieve this? I would also like to understand how $x_1$ might be distributed over $[\frac {1} {\sum_i a_i}, \frac {1} {a_1}$] (a theoretical query).

This question solves it for $a_i=1$ and without the $x_i$'s having a prior order, but I do not see any obvious way to generalize from that answer.

There is a similar question on MO, but without the weights $a_1,\dots,a_D$.

Edit for possible solution clue:

I think this page from Devroy[1] page 568 is really helpful. To the best of my understanding, it solves my problem except for the part of $x_1 \geq x_2 \geq \dots \geq x_D$.

I think I might have an idea of how to solve it all the way, and I will try to write it out in the next couple of days.

Edit 2: To complete the answer for $x_1 \geq x_2 \geq \dots \geq x_D$ part, one needs to note that for any $(x_1,x_2,x_3)$, $$(x_1,x_2,x_3)=(\frac {1} {a_1},0,0)*(x_1-x_2)a_1+(\frac {1} {a_1+a_2},\frac {1} {a_1+a_2},0)*(x_2-x_3)(a_1+a_2)+(\frac {1} {a_1+a_2+a_3},\frac {1} {a_1+a_2+a_3},\frac {1} {a_1+a_2+a_3})*x_3*(a_1+a_2+a_3)$$

In fact this representation is an if and only if, as in, any convex combination of the said points will be in the aforementioned plain $X$ and would have $x_1 \geq x_2 \geq \dots \geq x_D$.

And this can be extended to a general number of dimensions.

So to draw points uniformly from $X$ with $0 \leq x_1 \leq x_2 \leq \dots \leq x_D$, one needs to start by drawing numbers uniformly on the unit simplex, and then use that draw as weights to find a convex combination of the points $(\frac {1} {a_1},0,0), (\frac {1} {a_1+a_2},\frac {1} {a_1+a_2},0), (\frac {1} {a_1+a_2+a_3},\frac {1} {a_1+a_2+a_3},\frac {1} {a_1+a_2+a_3})$. Similarly for higher dimensions.

• Simultaneously corssposted to cs.se - please don't do this. cs.stackexchange.com/questions/60311/… – usul Jul 5 '16 at 3:17
• Your solution in Edit 2 is the right algorithm to use: you have identified the vertices of the simplex, now just generate a uniform point on the probability simplex (using one of the various known methods for this), and use the sampled point to assign coefficients to the vertices and output the resulting convex combination. I suggest you post the solution yourself and accept it. – Sasho Nikolov Jul 14 '16 at 0:28
• Oh, yes, that is exactly what I meant. I did not post on the algorithm on drawing from the prob simplex as that is already solved in one of the links I posted. – Juanito Jul 14 '16 at 0:55

I believe there is something called the Metropolis Algorithm The volume of your simplex (without the linear constraint) is $\frac{1}{n!}$ and so rejection sampling is terrible.
• These algorithms are quite the overkill for the problem. Sampling from any simplex $\Delta$ reduces to sampling from the probability simplex as long as you can identify the vertices of $\Delta$. Identifying the vertices in this case is an exercise. There are a number of (simple) classical algorithms for sampling from the probability simplex. – Sasho Nikolov Jul 14 '16 at 0:32
• @SashoNikolov Is it ok if multiple $a_i$ are zero? In that case, the transformation from the standard simplex to non-standard simplex is linear and singular. Projection of a uniform distribution of points over an equilateral triangle to the base would give a non-uniform distribution of points on the base. The center of the base will have more points. – R zu Nov 9 '18 at 13:56