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)?

 채택된 답변

Jos (10584)
Jos (10584) 2016년 5월 12일

1 개 추천

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

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)
Moritz Bleibtreu
Moritz Bleibtreu 2016년 5월 15일
편집: Moritz Bleibtreu 2016년 5월 15일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2016년 5월 12일

댓글:

2016년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by