J. Clifford Dyer wrote:
> My understanding of what you are looking for is that on each individual
> selection,
> the probability of picking a given name is that name's prob value, divided by
> the
> sum of all prob values. That is, in the following case:
> items = [('Mary', 96),('Shimon', 1)
On 2007-11-17, Bruza <[EMAIL PROTECTED]> wrote:
> OOPS. I pressed the Send too fast.
>
> The problem w/ Boris's solution is that after repeated calling
> of randomPick(3,items), 'Jane' is not the most "frequent
> appearing" member in all the out list of 3 member lists...
How does this solution fai
On Sat, 17 Nov 2007 13:51:16 -0800, [EMAIL PROTECTED] wrote:
> I am not guaranteeing this even works. I am seeing that there is some
> collision among the numbers, but it will work for the most part.
"Work for the most part" -- is that another way of saying "Apart from the
bugs, this is bug-free
Knuth says to pick N distinct records from a collection where the
probability is equal you should:
first fill up N records by chosing the first seen.
if less than N were in the collection, quit.
otherwise, t = (the number of items looked at) or N to start.
while your not at the end of the colle
On Fri, 2007-11-16 at 16:47 -0800, Bruza wrote:
I think I need to explain on the probability part: the "prob" is a
> relative likelihood that the object will be included in the output
> list. So, in my example input of
>
> items = [('Mary',30), ('John', 10), ('Tom', 45), ('Jane', 15)]
>
> So, f
How about this variation on your intial attempt?
# Untested!
def randomPick(n, items):
def pickOne():
index = random.randint(0, 99)
currentP = 0
for (obj, p) in items:
currentP += p
if currentP > index:
return obj
selection = set()
while len(selection) < n:
On Fri, 16 Nov 2007 16:47:16 -0800, Bruza wrote:
> I think I need to explain on the probability part: the "prob" is a
> relative likelihood that the object will be included in the output list.
> So, in my example input of
>
> items = [('Mary',30), ('John', 10), ('Tom', 45), ('Jane', 15)]
>
> S
Bruza wrote:
> On Nov 16, 4:47 pm, Bruza <[EMAIL PROTECTED]> wrote:
>> On Nov 16, 6:58 am, duncan smith <[EMAIL PROTECTED]>
>> wrote:
>>
>>
>>
>>> Bruza wrote:
I need to implement a "random selection" algorithm which takes a list
of [(obj, prob),...] as input. Each of the (obj, prob) repr
Maybe it would help to make your problem statement a litte rigorous so
we can get a clearer idea of whats required.
One possible formulation:
Given a list L of pairs of values, weightings: [ (v_0, w_0), (v_1,
w_1), ], and some N between 1 and length(L)
you would like to randomly select a set
On Nov 16, 4:47 pm, Bruza <[EMAIL PROTECTED]> wrote:
> On Nov 16, 6:58 am, duncan smith <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > Bruza wrote:
> > > I need to implement a "random selection" algorithm which takes a list
> > > of [(obj, prob),...] as input. Each of the (obj, prob) represents how
> > > l
On Nov 16, 6:58 am, duncan smith <[EMAIL PROTECTED]>
wrote:
> Bruza wrote:
> > I need to implement a "random selection" algorithm which takes a list
> > of [(obj, prob),...] as input. Each of the (obj, prob) represents how
> > likely an object, "obj", should be selected based on its probability
> >
Bruza wrote:
> I need to implement a "random selection" algorithm which takes a list
> of [(obj, prob),...] as input. Each of the (obj, prob) represents how
> likely an object, "obj", should be selected based on its probability
> of
> "prob".To simplify the problem, assuming "prob" are integers, an
Boris Borcic wrote:
> Bruza wrote:
>> No. That does not solve the problem. What I want is a function
>>
>> def randomPick(n, the_items):
>>
>> which will return n DISTINCT items from "the_items" such that
>> the n items returned are according to their probabilities specified
>> in the (item, pro)
Bruza wrote:
> No. That does not solve the problem. What I want is a function
>
> def randomPick(n, the_items):
>
> which will return n DISTINCT items from "the_items" such that
> the n items returned are according to their probabilities specified
> in the (item, pro) elements inside "the_items
Bruza <[EMAIL PROTECTED]> writes:
> But how about the general case, for N > 1 and N < len(items)? Is there
> some clever algorithm using Python standard "random" package
Yeah, I'm not sure what the name for it is, but there'ss a well known
algorithm that's sort of an online verison of random.choic
This recipe of mine may help:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498229
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Bruza wrote:
> No. That does not solve the problem. What I want is a function
>
> def randomPick(n, the_items):
>
> which will return n DISTINCT items from "the_items" such that
> the n items returned are according to their probabilities specified
> in the (item, pro) elements inside "the_items
On Nov 15, 9:32 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Nov 15, 10:40�pm, Bruza <[EMAIL PROTECTED]> wrote:
>
>
>
> > I need to implement a "random selection" algorithm which takes a list
> > of [(obj, prob),...] as input. Each of the (obj, prob) represents how
> > likely an object,
On Nov 15, 10:40�pm, Bruza <[EMAIL PROTECTED]> wrote:
> I need to implement a "random selection" algorithm which takes a list
> of [(obj, prob),...] as input. Each of the (obj, prob) represents how
> likely an object, "obj", should be selected based on its probability
> of
> "prob".To simplify the
Bruza wrote:
> I need to implement a "random selection" algorithm which takes a list
> of [(obj, prob),...] as input. Each of the (obj, prob) represents how
> likely an object, "obj", should be selected based on its probability
> of
> "prob".To simplify the problem, assuming "prob" are integers, an
20 matches
Mail list logo