RandomProbabilities

From QETLAB
Jump to navigation Jump to search
RandomProbabilities
Generates a random probability vector

Other toolboxes required none
Related functions RandomStateVector
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.

Syntax

  • P = RandomProbabilities(N)

Argument descriptions

  • N: The number of entries in the desired probability vector.

Examples

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:

RandomProbabilities uniform.png

Source code

Click here to view this function's source code on github.