Prev: Speed bottleneck
Next: Error message for rayleighchan
From: Matt J on 21 Jul 2010 06:02 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i25clh$jhi$1(a)fred.mathworks.com>... > This later version is rather similar in a sense to the solutions that have been given often in this group for the problem of n random variables with a predetermined sum which I mentioned earlier, where n rand's are taken and then they are each divided by their sum times the desired sum value. Both techniques tend to concentrate values in the center regions at the expense of the outer regions - that is disproportionately to the n-dimensonal volumes of those regions. And yes for large n they begin to approach gaussian distributions (the central limit theorem at work again.) ======= As I was saying to Walter, I really don't follow that reasoning. If we're now talking about Z=rand(1,N); X=Z/sum(Z); it is quite clear that each X(i)--->0 as N--->inf. Also, X does not result from the summation of i.i.d random vectors for any N, so I don't see how the Central Limit Theorem would imply that the elements X(i) tend to be jointly Gaussian as N-->inf.
From: Roger Stafford on 21 Jul 2010 15:47 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i26gj2$s3o$1(a)fred.mathworks.com>... > "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i25clh$jhi$1(a)fred.mathworks.com>... > > > This later version is rather similar in a sense to the solutions that have been given often in this group for the problem of n random variables with a predetermined sum which I mentioned earlier, where n rand's are taken and then they are each divided by their sum times the desired sum value. Both techniques tend to concentrate values in the center regions at the expense of the outer regions - that is disproportionately to the n-dimensonal volumes of those regions. And yes for large n they begin to approach gaussian distributions (the central limit theorem at work again.) > ======= > > As I was saying to Walter, I really don't follow that reasoning. If we're now talking about > > Z=rand(1,N); > X=Z/sum(Z); > > it is quite clear that each X(i)--->0 as N--->inf. Also, X does not result from the summation of i.i.d random vectors for any N, so I don't see how the Central Limit Theorem would imply that the elements X(i) tend to be jointly Gaussian as N-->inf. - - - - - - - - - - - As I understand it, Matt, the argument would go something like this. In your notation, for each individual Z(i), when it is divided by sum(Z) for N > 1, that affects the distribution of the resulting X(i). It no longer possesses its original uniform distribution on [0,1] (or whatever distribution it might have had.) Theoretically it can still range from 0 to 1 but statistically it is crowded more and more closely in towards 0 for increasing N. Its theoretical mean and variance can be calculated as a function of N. If we were to translate and rescale it so as to have mean zero and variance one, its distribution would begin to resemble more and more the bell-shaped curve of a standard normal distribution as N increases - and yes stretching out towards infinity in both plus and minus directions. And this is actually independent of whatever distribution the original Z's possessed, assuming they were independent. So apparently says the mysterious central limit theorem in one of its numerous manifestations (please don't ask me which one.) You will note that this is not in contradiction with the fact that the mean value of X(i) must itself approach zero as N approaches infinity. It just says that if you continue to shift and rescale it so as to match standard normal in mean and variance for each N, then the rest of the distribution curve will also approach normality. The CLT is a remarkable theorem. Roger Stafford
From: Paulo on 22 Jul 2010 06:44 "jay " <ssjzdl(a)gmail.com> wrote in message <i22vhv$frn$1(a)fred.mathworks.com>... > I need to generate 5 random variables between [0,1], let's say a, b, c, d, e. The constraint is that a<b<c<d<e. How to make this happen? Please advise. thanks while(1) %infinite loop a=rand();b=rand();c=rand();d=rand();e=rand(); %put random values on variables if((a<b) && (b<c) && (c<d) && (d<e)) , break ,end %test if constraint is true %if constraint is true than stop the loop end fprintf('a=%d b=%d c=%d d=%d',a,b,c,d); % just to show the values
From: John D'Errico on 22 Jul 2010 09:27 "Paulo " <paulojmdsilva(a)gmail.com> wrote in message <i297dj$bd7$1(a)fred.mathworks.com>... > "jay " <ssjzdl(a)gmail.com> wrote in message <i22vhv$frn$1(a)fred.mathworks.com>... > > I need to generate 5 random variables between [0,1], let's say a, b, c, d, e. The constraint is that a<b<c<d<e. How to make this happen? Please advise. thanks > > > while(1) %infinite loop > a=rand();b=rand();c=rand();d=rand();e=rand(); %put random values on variables > if((a<b) && (b<c) && (c<d) && (d<e)) , break ,end %test if constraint is true > %if constraint is true than stop the loop > end > fprintf('a=%d b=%d c=%d d=%d',a,b,c,d); % just to show the values This is a rejection method, quite an inefficient way to do the same thing as a sort on this problem. Since there are 5! = 24 ways to generate a set of 5 numbers, only ONE of which is sorted, this dumps its results into the bit bucket nearly 96% of the time. 23/24 ans = 0.958333333333333 It makes far more sense to generate 5 numbers (as a vector, in ONE operation) and then use sort on them. sort(rand(1,5)) The statistics of this result are the same in the end, yet it wastes far less cpu time to do the operation. John
From: Paulo on 22 Jul 2010 10:43
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i29gvb$cs2$1(a)fred.mathworks.com>... > "Paulo " <paulojmdsilva(a)gmail.com> wrote in message <i297dj$bd7$1(a)fred.mathworks.com>... > > "jay " <ssjzdl(a)gmail.com> wrote in message <i22vhv$frn$1(a)fred.mathworks.com>... > > > I need to generate 5 random variables between [0,1], let's say a, b, c, d, e. The constraint is that a<b<c<d<e. How to make this happen? Please advise. thanks > > > > > > while(1) %infinite loop > > a=rand();b=rand();c=rand();d=rand();e=rand(); %put random values on variables > > if((a<b) && (b<c) && (c<d) && (d<e)) , break ,end %test if constraint is true > > %if constraint is true than stop the loop > > end > > fprintf('a=%d b=%d c=%d d=%d',a,b,c,d); % just to show the values > > This is a rejection method, quite an inefficient way to > do the same thing as a sort on this problem. Since > there are 5! = 24 ways to generate a set of 5 numbers, > only ONE of which is sorted, this dumps its results into > the bit bucket nearly 96% of the time. > > 23/24 > ans = > 0.958333333333333 > > It makes far more sense to generate 5 numbers (as a > vector, in ONE operation) and then use sort on them. > > sort(rand(1,5)) > > The statistics of this result are the same in the end, yet > it wastes far less cpu time to do the operation. > > John That's a good point but unless he wants to create those variables many many times it doesn't matter much, also there's no problem with variables when they got the same value, my code is simple and doesn't require any fancy manipulations or functions. |