0
votes

point K must be selected out of possible points, K is a random variable with known probability distribution. I want to choose one of the points due to this distribution... how can I do that?

For example: the points: 3 5 6 8 probability: 0.2 0.4 0.1 0.3

I want to select one of the points due to their probabilities.

2

2 Answers

3
votes

Using rand generate a random number in the range [0.0, 1.0). If it is in [0.0,0.2) select 3, if the random number is in [0.2,0.6) select 5, etc, etc.

3
votes

I'll not provide you with an exact function, however, with the code provided below it should be extremely easy to wrap it into a function.

The solution is based on Marks original comment, but uses cumsum() to make the implementation a bit easier.

%# Set up point labels and probabilities (input parameters to function)
labels = [3 5 6 8];
probabilities = [0.2 0.4 0.1 0.3];

%#Find cumulative distribution
cp = [0 cumsum(probabilities)];

%#Draw point at random according to probability density
draw = rand();
higher = find(cp >= draw==1,1);
drawnPoint = labels(higher-1); %# Output result from function