http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961
MATLAB Central Newsreader  How to generate vector of random numbers in any interval (e.g. [1 1]) that sums to 1)
Feed for thread: How to generate vector of random numbers in any interval (e.g. [1 1]) that sums to 1)
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 09 Nov 2010 12:43:11 +0000
How to generate vector of random numbers in any interval (e.g. [1 1]) that sums to 1)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794407
Vassilios Vassiliadis
Hello,<br>
I'd like to generate a vector of random numbers,which take values in any interval (e.g. [1 1]),and this vector sums to 1...<br>
<br>
Thanx in advance...<br>
Vassilis...

Tue, 09 Nov 2010 12:56:06 +0000
Re: How to generate vector of random numbers in any interval (e.g. [1 1]) that sums to 1)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794417
PLH
Just renormalise:<br>
<br>
y = rand(1,N); <br>
S = sum(y); <br>
y = y/S; % renormalisation

Tue, 09 Nov 2010 12:57:03 +0000
Re: How to generate vector of random numbers in any interval (e.g. [1 1]) that sums to 1)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794418
Bruno Luong
"Vassilios Vassiliadis" <v.vassiliadis@fme.aegean.gr> wrote in message <ibbfkv$l6m$1@fred.mathworks.com>...<br>
> Hello,<br>
> I'd like to generate a vector of random numbers,which take values in any interval (e.g. [1 1]),and this vector sums to 1...<br>
> <br>
> Thanx in advance...<br>
> Vassilis...<br>
<br>
Roger's fex submission is taylor made for your problem:<br>
<a href="http://www.mathworks.com/matlabcentral/fileexchange/9700randomvectorswithfixedsum">http://www.mathworks.com/matlabcentral/fileexchange/9700randomvectorswithfixedsum</a><br>
<br>
Bruno

Tue, 09 Nov 2010 13:06:27 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794426
ImageAnalyst
On Nov 9, 7:43 am, "Vassilios Vassiliadis"<br>
<v.vassilia...@fme.aegean.gr> wrote:<br>
> Hello,<br>
> I'd like to generate a vector of random numbers,which take values in any interval (e.g. [1 1]),and this vector sums to 1...<br>
><br>
> Thanx in advance...<br>
> Vassilis...<br>
<br>
<br>
I'm not sure that's possible. Can you tell me how you could take a<br>
bunch of numbers in the interval [100 50] and have that sum to<br>
1???? If you made the sum equal to 1, you'd no longer have values in<br>
the range 100 to 50  you'd have to change the range (the values of<br>
the numbers). I don't think you can have it both ways: both in the<br>
range and with the prescribed sum.

Tue, 09 Nov 2010 13:26:05 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794436
PLH
Firstly, my original post misunderstimated the problem (so apologies for that).<br>
<br>
Secondly, are both the interval and the number of random points required fixed at the outset or is it just the interval? If it's the interval, then N must be allowed to vary so that the constraint that the total equals one can be satisfied (e.g. elements randomly chosen from I = [100,1] with lots of points in the positive region). Otherwise, if both N and the interval are fixed, and the constraint is imposed, then not all of your points are random...<br>
<br>
Finally, as mentioned above, your constraint a priori limits your choice of interval. So, I presume you mean "any interval for N points such that the total of the elements equals 1"?<br>
<br>
> <br>
> I'm not sure that's possible. Can you tell me how you could take a<br>
> bunch of numbers in the interval [100 50] and have that sum to<br>
> 1???? If you made the sum equal to 1, you'd no longer have values in<br>
> the range 100 to 50  you'd have to change the range (the values of<br>
> the numbers). I don't think you can have it both ways: both in the<br>
> range and with the prescribed sum.

Tue, 09 Nov 2010 13:46:04 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794440
Bruno Luong
For N random number in (a,b), of course it is clear the sum target value must be within (N*a,N*b) so that the event is possible. In that case, Roger's FEX.<br>
<br>
Bruno

Tue, 09 Nov 2010 15:20:14 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794481
Walter Roberson
On 09/11/10 6:43 AM, Vassilios Vassiliadis wrote:<br>
<br>
> I'd like to generate a vector of random numbers,which take values in any<br>
> interval (e.g. [1 1]),and this vector sums to 1...<br>
<br>
If you use a fixed number of entries in the vector, then the last one <br>
will never be random: it's value is fully predictable by knowing the <br>
previous ones.<br>
<br>
If you do not use a fixed number of entries and just keep generating <br>
until the sum is 1, then your expected wait time for generation would be <br>
*quite* large (i.e., the only thing that keeps it from being infinite is <br>
the fact that binary floating point values have a fixed finite resolution.)

Tue, 09 Nov 2010 17:09:05 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794531
Roger Stafford
Walter Roberson <roberson@hushmail.com> wrote in message <PEdCo.12435$lL3.8212@newsfe08.iad>...<br>
> On 09/11/10 6:43 AM, Vassilios Vassiliadis wrote:<br>
> <br>
> > I'd like to generate a vector of random numbers,which take values in any<br>
> > interval (e.g. [1 1]),and this vector sums to 1...<br>
> <br>
> If you use a fixed number of entries in the vector, then the last one <br>
> will never be random: it's value is fully predictable by knowing the <br>
> previous ones.<br>
> ........<br>
        <br>
It does make sense to have random vectors which have a given sum, Walter. It is a standard problem in conditional probability analogous to asking to simulate a random toss of two dice given that their sum has been observed to be say seven. If two values, x and y, of the 'rand' function are chosen, this can be viewed statistically as the selection of a random point in a unit square in the xy plane where equal areas have equal probabilities. However if we require that their sum be given as say one, then it is a conditional probability problem and can be regarded as a uniformly distributed selection along the line of the square's diagonal where equal lengths then have equal probabilities as required by the conditional probability concept.<br>
<br>
Vassilios is asking how to generate random points in a certain polytope in ndimensional space corresponding to a given sum of random variables, and this makes perfectly good sense. Unfortunately if one simply normalizes a set of random values from 'rand' so as to have the given sum, this skews the distribution. In the case of the unit square doing so would have the effect of projecting the square's area orthogonally onto its diagonal which produces a triangular distribution along its length. It requires a little more sophistication to produce a uniform distribution lengthwise, which is why I wrote the 'randfixedsum' routine.<br>
<br>
Roger Stafford

Wed, 10 Nov 2010 09:09:03 +0000
Re: How to generate vector of random numbers in any interval (e.g. [1 1]) that sums to 1)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794754
Vassilios Vassiliadis
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ibbgev$emm$1@fred.mathworks.com>...<br>
> "Vassilios Vassiliadis" <v.vassiliadis@fme.aegean.gr> wrote in message <ibbfkv$l6m$1@fred.mathworks.com>...<br>
> > Hello,<br>
> > I'd like to generate a vector of random numbers,which take values in any interval (e.g. [1 1]),and this vector sums to 1...<br>
> > <br>
> > Thanx in advance...<br>
> > Vassilis...<br>
> <br>
> Roger's fex submission is taylor made for your problem:<br>
> <a href="http://www.mathworks.com/matlabcentral/fileexchange/9700randomvectorswithfixedsum">http://www.mathworks.com/matlabcentral/fileexchange/9700randomvectorswithfixedsum</a><br>
> <br>
> Bruno<br>
<br>
Thanx,I find it very useful...

Wed, 10 Nov 2010 09:15:04 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794756
Vassilios Vassiliadis
Thank you very much for your help...<br>
<br>
Vassilios<br>
<br>
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ibbv7h$da7$1@fred.mathworks.com>...<br>
> Walter Roberson <roberson@hushmail.com> wrote in message <PEdCo.12435$lL3.8212@newsfe08.iad>...<br>
> > On 09/11/10 6:43 AM, Vassilios Vassiliadis wrote:<br>
> > <br>
> > > I'd like to generate a vector of random numbers,which take values in any<br>
> > > interval (e.g. [1 1]),and this vector sums to 1...<br>
> > <br>
> > If you use a fixed number of entries in the vector, then the last one <br>
> > will never be random: it's value is fully predictable by knowing the <br>
> > previous ones.<br>
> > ........<br>
>         <br>
> It does make sense to have random vectors which have a given sum, Walter. It is a standard problem in conditional probability analogous to asking to simulate a random toss of two dice given that their sum has been observed to be say seven. If two values, x and y, of the 'rand' function are chosen, this can be viewed statistically as the selection of a random point in a unit square in the xy plane where equal areas have equal probabilities. However if we require that their sum be given as say one, then it is a conditional probability problem and can be regarded as a uniformly distributed selection along the line of the square's diagonal where equal lengths then have equal probabilities as required by the conditional probability concept.<br>
> <br>
> Vassilios is asking how to generate random points in a certain polytope in ndimensional space corresponding to a given sum of random variables, and this makes perfectly good sense. Unfortunately if one simply normalizes a set of random values from 'rand' so as to have the given sum, this skews the distribution. In the case of the unit square doing so would have the effect of projecting the square's area orthogonally onto its diagonal which produces a triangular distribution along its length. It requires a little more sophistication to produce a uniform distribution lengthwise, which is why I wrote the 'randfixedsum' routine.<br>
> <br>
> Roger Stafford

Wed, 10 Nov 2010 12:11:03 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794801
Vassilios Vassiliadis
Hello,<br>
another issue which I've not managed to tackle is the following:<br>
Assuming that I generate a random vector of numbers restricted (only!!!) in the interval <br>
[1 1].Afterwards,as a second step,I'd like to properly 'transform' (is a sense) this vector in order to sum up to 1.How can I achieve this??<br>
<br>
Thanx in advance...<br>
Vassilios...<br>
<br>
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ibbv7h$da7$1@fred.mathworks.com>...<br>
> Walter Roberson <roberson@hushmail.com> wrote in message <PEdCo.12435$lL3.8212@newsfe08.iad>...<br>
> > On 09/11/10 6:43 AM, Vassilios Vassiliadis wrote:<br>
> > <br>
> > > I'd like to generate a vector of random numbers,which take values in any<br>
> > > interval (e.g. [1 1]),and this vector sums to 1...<br>
> > <br>
> > If you use a fixed number of entries in the vector, then the last one <br>
> > will never be random: it's value is fully predictable by knowing the <br>
> > previous ones.<br>
> > ........<br>
>         <br>
> It does make sense to have random vectors which have a given sum, Walter. It is a standard problem in conditional probability analogous to asking to simulate a random toss of two dice given that their sum has been observed to be say seven. If two values, x and y, of the 'rand' function are chosen, this can be viewed statistically as the selection of a random point in a unit square in the xy plane where equal areas have equal probabilities. However if we require that their sum be given as say one, then it is a conditional probability problem and can be regarded as a uniformly distributed selection along the line of the square's diagonal where equal lengths then have equal probabilities as required by the conditional probability concept.<br>
> <br>
> Vassilios is asking how to generate random points in a certain polytope in ndimensional space corresponding to a given sum of random variables, and this makes perfectly good sense. Unfortunately if one simply normalizes a set of random values from 'rand' so as to have the given sum, this skews the distribution. In the case of the unit square doing so would have the effect of projecting the square's area orthogonally onto its diagonal which produces a triangular distribution along its length. It requires a little more sophistication to produce a uniform distribution lengthwise, which is why I wrote the 'randfixedsum' routine.<br>
> <br>
> Roger Stafford

Wed, 10 Nov 2010 12:37:04 +0000
Re: How to generate vector of random numbers in any interval (e.g.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/295961#794808
Bruno Luong
"Vassilios Vassiliadis" <v.vassiliadis@fme.aegean.gr> wrote in message <ibe24n$9cr$1@fred.mathworks.com>...<br>
> Hello,<br>
> another issue which I've not managed to tackle is the following:<br>
> Assuming that I generate a random vector of numbers restricted (only!!!) in the interval <br>
> [1 1].Afterwards,as a second step,I'd like to properly 'transform' (is a sense) this vector in order to sum up to 1.How can I achieve this??<br>
> <br>
<br>
A proper way is to describe in term of probability distribution, covariance, conditional probability, then you might get some accurate answer. Because the term "properly transform" does not evoke any meaningful notion to anybody but you.<br>
<br>
To me Roger's uniform conditional probability is the most natural. Anything deviates from that is artificial thus must be specified accurately.<br>
<br>
Bruno