Gaussian distribution with sum 1
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Felipe Bayona
le 8 Déc 2020
Réponse apportée : John D'Errico
le 11 Déc 2020
Hello Community
im trying to generate a 2D gaussian matrix, which the sum of all its values is equal to 1.
I mean, not distribuited around 1 (the center must be a value below 1 to achieve teh sum of all elements to be 1)
For sure Matlab must have already implemented something like that. Or, whats the mathematical approach I must use to develp my own function?
Thx a lot
1 commentaire
John D'Errico
le 11 Déc 2020
Please. It is a bad idea to accept your own answer when you don't understand what you are doing.
Réponse acceptée
Felipe Bayona
le 11 Déc 2020
1 commentaire
John D'Errico
le 11 Déc 2020
You are making some comments which lead me to the conclusion you do not understand what a distribution is.
w = gausswin(7)
sw = (sum(w) -1) / numel(w);
nw = w - sw
sum(nw)
The vector nw is NOT a set of normally distributed random numbers!!!!! In fact, these are not random numbers at all.
For example, do you see that the vector is perfectly symmetrical around the center element? Is that a surprise to you?
So accepting your own answer here is a bad idea, if you don't know what you are doing.
Plus de réponses (2)
John D'Errico
le 11 Déc 2020
Is the goal here to generate a set of random numbers which are apparently normally distributed, but with a sum of 1? Or is the goal to generate a set of numbers that have the SHAPE of a normal distribution PDF, yet have a sum of 1?
You seem to be asking for the former, yet your own accepted answer shows you generated a set of points off a Gaussian PDF, then shifted it so the sum was 1. As you should see, the result of what you did in your accepted answer is not a random set at all. A random set of numbers would not be perfectly symmetrical around the center element of the vector.
So IF you really want pseudo-random numbers with the property that the sum is 1, it is easy. Even trivially so. Use randn to generate a random vector.
n = 7;
X = randn(n,1);
sum(X)
We should see the sum was not 1. We now just make it so.
X = X - mean(X) + 1/n
Are they now pseudo-normally distributed? Is the sum as desired?
sum(X)
So the sum is now 1, and we have a vector which is indeed pseudo-randomly normally distributed. For a larger sample (so the histogram will look smooth), we can see it does indeed have the necessary properties.
n = 1e6;
X = randn(n,1);
X = X - mean(X) + 1/n;
sum(X)
histogram(X,'norm','pdf')
So while it is not clear what you are asking to do, but the title of your question was:
Gaussian distribution with sum 1
Your other comments also suggest that you may be confused as to what you are asking.
0 commentaires
Ameer Hamza
le 8 Déc 2020
What about
M = randn(10);
M_sum1 = M./sum(M, 'all');
Check:
>> sum(M_sum1, 'all')
ans =
1
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!