Sampling from distribution summing up to some value

Hello
I'm sampling 14 random numbers from a dirichlet distribution in the following way:
N = ones(14,1);
d = gamrnd(N , 1);
d = d./sum(d);
The values sum up to 1 but I want that they sum up to 14.
Is it valid to just multiply the values by 14, i.e. d = d * 14?
Second, do I have to initialize N with ones(14,1) or with ones(14,1) * (1/14)?

 Accepted Answer

The arguments of GAMRND are the shape parameters of the distribution. Change them and you will change the distribution from which you draw the random values. That is not what you generally want.
You should define carefully what you mean by valid.

5 Comments

Thanks a lot for the answer. I have 14 weight values which have to sum to 14. The weights are for features (one weight for one feature). Each value can be between 0 and 14. I have made an experiment. If I divide N by 14, I'm getting a few very high values and all others very small. If I don't divide by 14, it is more evenely distributed. Which approach is more suited?
You generally do not want to change the shape of the probability distribution, so fix these inputs.
The output of a single draw of a probability distribution is a value between 0 and 1.
You can normalise them as you suggest: d = 14 * d ./ (sum(d) This will indeed set the additional requirement that the values sum up to 14. However, you now cannot interpret a value of d as a probability! (which may not be a problem in itself)
Thanks for the answer. To what values would you set these inputs? The numbers should be weights, i.e. I have 14 weights which should sum uf to 14. These are weights for features. That means I have a dataset where the rows are data points and the columns are features. One weight belongs to one column. Natrually, the weights should be between 0 and 14 and they should sum up to 14.
I am not sure if I understand you question. The inputs to gamrnd specify the shape of the underlying distribution. Therefore, for specific inputs, some values are more likely than others. Try this:
a = 1 ; b = 2 ; % change these values and see that when we ...
V = gamrnd(a,b,1000,1) ; % draw a 1000 random values ...
histogram(V) % some values are becoming more/less likely than others
I see what you mean but in my case all 14 weights should be equal likely... so I think a == b == c etc., but I don't know what values to choose.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!