Re: Generate a sequence of random numbers that sum up to 1?

2006-04-29 Thread Paul Rubin
Anthony Liu [EMAIL PROTECTED] writes: OK, I actually just want to manually create Hidden Markov Models by randomly generating the initial state probabilities PI, OK, this sounds like you actually want to divide the unit interval up into pieces of varying sizes. Example (untested): n = 10

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-24 Thread Terry Reedy
fumanchu [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm surprised noone has pursued a course of subtraction rather than division. I believe someone did mention the subtraction method in one of the initial responses. But the problem is this. If you independently sample n

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Gerard Flanagan
Nick Craig-Wood wrote: Gerard Flanagan [EMAIL PROTECTED] wrote: def distribution(N=2): p = [0] + sorted( random.random() for _ in range(N-1) ) + [1] for j in range(N): yield p[j+1] - p[j] spread = list(distribution(10)) print spread print sum(spread)

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread fumanchu
I'm surprised noone has pursued a course of subtraction rather than division. Say you want 10 numbers: s = 1.0 n = [] for x in xrange(9): ... value = random.random() * s ... n.append(value) ... s -= value ... n.append(s) n [0.727922901516, 0.082128708606867745,

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Alex Martelli
fumanchu [EMAIL PROTECTED] wrote: I'm surprised noone has pursued a course of subtraction rather than division. Say you want 10 numbers: s = 1.0 n = [] for x in xrange(9): ... value = random.random() * s ... n.append(value) ... s -= value ... n.append(s) n

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Robert Kern
Alex Martelli wrote: fumanchu [EMAIL PROTECTED] wrote: I'm surprised noone has pursued a course of subtraction rather than division. Say you want 10 numbers: s = 1.0 n = [] for x in xrange(9): ... value = random.random() * s ... n.append(value) ... s -= value ... n.append(s) n

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Edward Elliott
Alex Martelli wrote: Such total disuniformity, where the very distribution of each value is skewed by the preceding one, may still be random for some sufficiently vague meaning of random, but my intuition suggests it's unlikely to prove satisfactory for the OP's purposes. It does seem very

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Alex Martelli
Anthony Liu [EMAIL PROTECTED] wrote: ... As a matter of fact, given that we have to specify the number of states for an HMM, I would like to create a specified number of random floating numbers whose sum is 1.0. def forAL(N): N_randoms = [random.random() for x in xrange(N)] total

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Gerard Flanagan
Anthony Liu wrote: I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up to 1 . I am not sure how to do this. Any idea? Thanks.

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Gerard Flanagan
Gerard Flanagan wrote: Anthony Liu wrote: I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up to 1 . I am not sure how to do this. Any

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Gerard Flanagan
Gerard Flanagan wrote: Gerard Flanagan wrote: Anthony Liu wrote: I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up to 1 . I

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Anthony Liu
Thanks a lot, Alex and Gerard. I am actually not very concerned about the inter-dependency of the floating numbers generated randomly. They are good enough if they are subject to the constraint of summing up to 1. It is simply not worth the time to get an HMM by training it on a large corpus.

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Nick Craig-Wood
Gerard Flanagan [EMAIL PROTECTED] wrote: def distribution(N=2): p = [0] + sorted( random.random() for _ in range(N-1) ) + [1] for j in range(N): yield p[j+1] - p[j] spread = list(distribution(10)) print spread print sum(spread) This is simpler, easier to prove

Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Anthony Liu
I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up to 1 . I am not sure how to do this. Any idea? Thanks.

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Michael Spencer
Anthony Liu wrote: I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up to 1 . I am not sure how to do this. Any idea? Thanks.

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Mel Wilson
Anthony Liu wrote: I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up to 1 . I am not sure how to do this. Any idea? Thanks. numbers.append

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Edward Elliott
Anthony Liu wrote: But, I want the random numbers just generated sum up to 1 . This seems like an odd request. Might I ask what it's for? Generating random numbers in [0,1) that are both uniform and sum to 1 looks like an unsatisfiable task. Each number you generate restricts the

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-22 às 03:16 +, Edward Elliott escreveu: If that level of accuracy matters, you might consider generating your rands as integers and then fp-dividing by the sum (or just store them as integers/fractions). Or using decimal module:

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Anthony Liu
OK, I actually just want to manually create Hidden Markov Models by randomly generating the initial state probabilities PI, the transition probabilities A and the emission probabilities B, instead of learning such statistics from a corpus. They have to be subject the constraint that sum(PI) =