|Generates a random probability vector|
|Other toolboxes required||none|
|Function category||Random things|
RandomProbabilities is a function that generates a random probability vector (i.e., its entries are non-negative and sum to 1), uniformly distributed on the unit simplex.
- P = RandomProbabilities(N)
- N: The number of entries in the desired probability vector.
Uniform distribution of length-3 probability vectors
The following code randomly generates 10000 probability vectors of length 3, and then demonstrates that their distribution on the unit simplex really is approximately uniform:
>> for j = 1:10000 p(j,:) = RandomProbabilities(3); end >> scatter3(p(:,1),p(:,2),p(:,3),1) % plot the probability vectors in 3D-space
The scatter plot produced by the above code is displayed below:
Click here to view this function's source code on github.