From: jay on
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
From: someone on
"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

doc rand
doc sort

It seems to me that the only way 5 random numbers wouldn't
satisfy that constraint is if 2 or more of them are equal.
A very unlikely event.
From: Walter Roberson on
someone wrote:
> "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
>
> doc rand
> doc sort
>
> It seems to me that the only way 5 random numbers wouldn't satisfy that
> constraint is if 2 or more of them are equal. A very unlikely event.

Roger Stafford has discussed some limitations on generating random
variables with constraints -- if it is done incorrectly, the values tend
to cluster towards the middle instead of uniformly distributed. I think
sorting was okay, but I'd have to find the previous threads to be sure.
From: Roger Stafford on
Walter Roberson <roberson(a)hushmail.com> wrote in message <Ob91o.39684$YX3.15357(a)newsfe18.iad>...
> Roger Stafford has discussed some limitations on generating random
> variables with constraints -- if it is done incorrectly, the values tend
> to cluster towards the middle instead of uniformly distributed. I think
> sorting was okay, but I'd have to find the previous threads to be sure.
- - - - - - - - - -
I believe that "someone"'s indicated sort solution is perfectly valid, Walter. I'll admit that I paused a moment before coming to that conclusion, having the problem of random variables with a fixed sum in mind. However, I am convinced that both the solution to that problem and the sort method in this current problem do abide by the same basic principle.

That principle is that when generating a combination of random variables with some constraint to be placed on them as they are generated, it should be done as though the same random variables with the same statistical relationships were to be performed without constraints except that combinations not satisfying the constraint are always rejected. A simple enough principle.

In the current problem, doing a sort(rand(5,1)) and then dealing them out in ascending order to a, b, c, d, and e is the perfect equivalent of (though more efficient than) rejecting all values of rand(5,1) which are not already in sorted order. That is because, if the five variables of rand(5,1) were separately rearranged in sorted order in each of the 5! = 120 simplexes of the five-dimensional [0,1]^5 cube and reassigned to a, b, c, d, and e, these would each then have identical statistical distributions throughout that simplex as far as these latter variables are concerned. The 119 that are rejected, if rearranged, are statistically equivalent to the one that is accepted.

I won't attempt to explain in detail what is involved in the fixed sum random variable generation except to say that one first imagines a small tolerance within which the sum is allowed to vary. One can envision an distribution within these tight limits which would simulate the rejection procedure without doing any rejecting. Finally if this tolerance is allowed to approach zero, the required distribution can be shown to also approach a limit, and it is this limit that can be used in generating such random variables. In that sense this fixed sum generation also adheres to the above principle.

Roger Stafford
From: John D'Errico on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i23iuk$lng$1(a)fred.mathworks.com>...
> Walter Roberson <roberson(a)hushmail.com> wrote in message <Ob91o.39684$YX3.15357(a)newsfe18.iad>...
> > Roger Stafford has discussed some limitations on generating random
> > variables with constraints -- if it is done incorrectly, the values tend
> > to cluster towards the middle instead of uniformly distributed. I think
> > sorting was okay, but I'd have to find the previous threads to be sure.
> - - - - - - - - - -
> I believe that "someone"'s indicated sort solution is perfectly valid, Walter. I'll admit that I paused a moment before coming to that conclusion, having the problem of random variables with a fixed sum in mind.

I'd agree with Roger here, although I too had to think
about it to be confident. The constraint here is not a
difficult one to satisfy, and the sort is an adequate
solution.

You can view this problem differently from finding a
list of 5 values that are sorted in increasing order.
Instead, you can view it as finding a SINGLE point,
the coordinates of which represent a point that lives
in a specific 5-dimensional simplex. In the end though,
the sort is valid.

John
 |  Next  |  Last
Pages: 1 2 3 4 5 6 7
Prev: Speed bottleneck
Next: Error message for rayleighchan