Weighted choices
Steven D'Aprano
steve at pearwood.info
Mon Sep 9 05:11:45 EDT 2013
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.
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. 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.
A more important question is, should the selection be done with or
without replacement? 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?
--
Steven
More information about the Python-list
mailing list