Artificial intelligent assistant

Sampling from the diamond: $|x_1|+\ldots+|x_n| \le 1$? Let $\left(x_1, \ldots, x_n \right)$ be a point in $\mathbb R^n$. Sample uniformly at random from the diamond $$ |x_1|+\ldots+|x_n| \le 1. $$ In $\mathbb R^2$, one way is to sample the square, then translate/reflect any point that fall outside the diamond, back into the diamond. But in $\mathbb R^n$, this doesn't work. I considered rejection sampling. But, as my target dimension is $n=500$. The rejection rate will be too high.

You can constrain your problem to finding a point in a simplex where each $x_i \ge 0$ and $\sum x_i \le 1$, then generate 500 random bits and negate the corresponding $x_i$.

The simplex is the n-dimensional version of a triangle or tetrahedron. I googled over my head and found this. Don't ask me to explain it, though. :)

Uniform distribution on a simplex via i.i.d. random variables

<

Sampling uniformly in the Unit Simplex

Sampling frmo the simplex

After looking at these I've seen this algorithm crop up:

1. Generate 500 $y_i$ on the interval (0,1)
2. $z_i = - \log y_i$
3. $S = \sum z_i$.
4. $x_i = \frac{z_i}{S}$



I don't really understand it and can't vouch for it being correct though.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy c27d8002c8def7a30142a473d1420a29