Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53856 > unrolled thread

Re: Weighted choices

Started byAntoon Pardon <antoon.pardon@rece.vub.ac.be>
First post2013-09-09 09:12 +0200
Last post2013-09-09 12:01 +0200
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Weighted choices Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-09 09:12 +0200
    Re: Weighted choices Steven D'Aprano <steve@pearwood.info> - 2013-09-09 09:11 +0000
      Re: Weighted choices Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-09 12:01 +0200

#53856 — Re: Weighted choices

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-09 09:12 +0200
SubjectRe: Weighted choices
Message-ID<mailman.164.1378710734.5461.python-list@python.org>
Op 09-09-13 02:21, Dennis Lee Bieber schreef:
> On Sun, 08 Sep 2013 19:48:55 +0200, Antoon Pardon
> <antoon.pardon@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.

-- 
Antoon Pardon

[toc] | [next] | [standalone]


#53858

FromSteven D'Aprano <steve@pearwood.info>
Date2013-09-09 09:11 +0000
Message-ID<522d90d1$0$29893$c3e8da3$5496439d@news.astraweb.com>
In reply to#53856
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@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

[toc] | [prev] | [next] | [standalone]


#53861

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-09 12:01 +0200
Message-ID<mailman.170.1378720899.5461.python-list@python.org>
In reply to#53858
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@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web