Weighted choices

Antoon Pardon antoon.pardon at rece.vub.ac.be
Mon Sep 9 06:01:37 EDT 2013


Op 09-09-13 11:11, Steven D'Aprano schreef:
> On Mon, 09 Sep 2013 09:12:05 +0200, Antoon Pardon wrote:
> 
>> Op 09-09-13 02:21, Dennis Lee Bieber schreef:
>>> On Sun, 08 Sep 2013 19:48:55 +0200, Antoon Pardon
>>> <antoon.pardon at rece.vub.ac.be> declaimed the following:
>>>
>>>> Op 08-09-13 04:12, Jason Friedman schreef:
>>>>> choices = dict()
>>>>> choices["apple"] = 10
>>>>> choices["pear"] = 20
>>>>> choices["banana"] = 15
>>>>> choices["orange"] = 25
>>>>> choices["kiwi"] = 30
>>>>>
>>>>> I want to pick sets of fruit, three in a set, where the chance of
>>>>> selecting a given fruit is proportional to its weight.  In the
>>>>> example above, pears should appear twice as often as apples and kiwis
>>>>> should appear twice as often as bananas.
>>>>
>>>> Just a small question. Is a set of three bananas an acceptable
>>>> outcome?
>>>
>>> 	If we are talking probabilities, regardless of what the weighting 
> is,
>>> it should be probable (if unlikely) to get three-of-a-kind.
>>
>> Why should that be? I'm unfamiliar with any kind of imperative that
>> discourages people from wanting sets with three different kinds of
>> fruit.
> 
> Then that's hardly *random*, is it? Or at least, it is a non-uniform 
> distribution, with much less randomness that a free choice.

I don't see how a problem where one can pick a number of items from a
collection, without refilling that collection after each choice makes
it that much less random.

> The OP specifies that the chance of selecting a given fruit is 
> proportional to its weight. That is not the case if you insist each piece 
> of fruit must be different.

So? It wouldn't be the first time, a specification wasn't complete or
not eniterly what the OP really wanted. As far as I can see, it happens
often enough that someone answers the question he thinks the OP wants
to ask, instead of the question that was really asked. Noone seems to
have a problem with that. So what is the big problem now if I
explicitly ask whether that is the case here or not?

If the OP had answerd "no", that wouldn't have been a problem, but I'm
surprised to get these kind of reactions just for inquiring.

> E.g. consider the case where there are five 
> different kinds of fruit (apple, pear, etc.) and you choose five pieces. 
> You *must* get one each of apple, pear etc., no matter how small the 
> weights are, and so the probability of getting set(apple, pear, banana, 
> orange, kiwi) is exactly 1, even if there are ten million apples to 
> choose from and only one orange.

So? You think it never happened some wanted to solve a problem without
a solution?

> A more important question is, should the selection be done with or 
> without replacement? 

Is it? Because my question and your question are very similar. You see
when you just start with one piece of fruit of each at the beginning
and you don't replace, the outcome is that you can't get three bananas
as outcome.

> That is, after selecting by chance an apple, does 
> that mean there is one fewer apple to select next time, and hence the 
> weight need to be slightly reduced? Or is the apple returned to the pool, 
> and the weights remain unchanged?

So you don't have any problem with adjusting the weight, ... unless
there is only one apple available which would mean the weight would be
adjusted to 0.

-- 
Antoon Pardon



More information about the Python-list mailing list