Uniformly distributed n-dimensional probability vectors over a simplex
#/Total[#,{2}]&@Log@RandomReal[{0,1},{m,n}]
will give you a sample of m
points from a uniform distribution over an n-1
-dimensional regular simplex. (An equilateral triangle is a 2-dimensional regular simplex.) Here's what m = 2000, n = 3
should look like, where {x,y} = {p[[2]]-p[[1]], Sqrt@3*p[[3]]}
are the barycentric coordinates of the 3-element probability vector p
:
Here's what you get if you omit the Log@
and normalize Uniform(0,1) variables, which is what both of the OP's examples do:
Old question, but I didn't see this method. Generates $n$ points uniformly randomly distributed on a simplex embedded in $d$ dimensions.
genSimplex[n_, d_] :=
Table[Differences[Sort[Flatten[{0, RandomReal[1, d – 1], 1}]]], {n}];
The algorithm generates points that are randomly distributed on an outer face of a simplex. The way to generate them is, for a d-dimensional problem…
- Generate d-1 uniformly distributed random values in the range [0,1]
- Add a 0 and a 1 to the list
- Sort the list
- Extract a list of the differences between the elements
You now have a list of random values that sum to 1 (so they are on a plane that is defined by points that sum to one) and that are otherwise independent of each other, so their dispersion is uniform.
Updating the answer with a picture of example data with 1,000 points.
This topic is well-covered here... https://stackoverflow.com/questions/3010837/sample-uniformly-at-random-from-an-n-dimensional-unit-simplex
Starting in M10.2, you can just use RandomPoint
:
pts=RandomPoint[Simplex[{{0,0,1},{0,1,0},{1,0,0}}], 1000];
Graphics3D[Point[pts]]