Gaussian distribution with sum 1
Ältere Kommentare anzeigen
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 Kommentar
John D'Errico
am 11 Dez. 2020
Please. It is a bad idea to accept your own answer when you don't understand what you are doing.
Akzeptierte Antwort
Weitere Antworten (2)
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.
Ameer Hamza
am 8 Dez. 2020
What about
M = randn(10);
M_sum1 = M./sum(M, 'all');
Check:
>> sum(M_sum1, 'all')
ans =
1
Kategorien
Mehr zu Linear Least Squares finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
