From: Javier Montoya on
On Jun 12, 2:09 pm, Steven D'Aprano <st...(a)REMOVE-THIS-
cybersource.com.au> wrote:
> On Sat, 12 Jun 2010 03:05:43 -0700, Javier Montoya wrote:
> > Dear all,
>
> > I need to generate a vector of random float numbers between [0,1] such
> > that their sum equals 1 and that are distributed non-uniformly. Is there
> > any python function that generates such a vector?
>
> You haven't explained your requirements in anywhere near enough detail.
> Any of these match your description:
>
> [1.0]
> [0.0, 0.0, 0.0, 0.0, 1.0]
> [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.3]
> [0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.03, 0.03, 0.84]
>
> and many, many more. What do you mean by "non-uniformly"? Do you have any
> specific distribution in mind? Do you have to have a particular number of
> items?
>
> For instance, you could do this:
>
> L = []
> total = 0.0
> while total < 1:
>     x = random.uniform(0, 1-total)
>     L.append(x)
>     total += x
>
> assert sum(L) == total == 1.0
>
> --
> Steven

Hi Steven,

The number of items in the vector is usually between [4,15]. I was
having in mind sth. like:
[0.25, 0.23, 0.30, 0.22] for the 4 elems case.

Best wishes
From: Ian on
On 12/06/10 11:05, Javier Montoya wrote:
> Dear all,
>
> I need to generate a vector of random float numbers between [0,1] such
> that their sum equals 1 and that are distributed non-uniformly.
> Is there any python function that generates such a vector?
>
> Best wishes
>
Hi Javier,

The answer to your question is "No", and the reason is that your
requirement is impossible.

Whatever distribution you choose - and you have not said what you
require - will be altered by any scaling to meet the constraint that the
total is 1.

What exactly are you trying to achieve?

Regards

Ian
From: Javier Montoya on
On Jun 12, 3:21 pm, Ian <hobso...(a)gmaiil.com> wrote:
> On 12/06/10 11:05, Javier Montoya wrote:> Dear all,
>
> > I need to generate a vector of random float numbers between [0,1] such
> > that their sum equals 1 and that are distributed non-uniformly.
> > Is there any python function that generates such a vector?
>
> > Best wishes
>
> Hi Javier,
>
> The answer to your question is "No", and the reason is that your
> requirement is impossible.
>
> Whatever distribution you choose - and you have not said what you
> require - will be altered by any scaling to meet the constraint that the
> total is 1.
>
> What exactly are you trying to achieve?
>
> Regards
>
> Ian

Hi Ian, I found that the Dirichlet distribution is suitable for my
case.
Regards