Iza Romanowska <izaromanow...@gmail.com> added the comment:

Hi, 

Many thanks for engaging with this. 
I agree that we should very clearly separate negative weights from zero 
weights. A negative number is illegal and that's the end of it. However, a zero 
weight is not illegal, e.g., [0, 0, 0, 0.1] is a legal sequence to pass as 
weight. 

Raymond, I agree with you that this is conflating incremental preference with 
zero chance of occurring. From a standard user perspective, if the [0, 0, 0, 
0.1] sequence is passed as weights the first three options have a zero 
probability of selection thus that interpretation (even if in your opinion 
erroneous) is very likely to happen for most of the users. 

I think we all agree that an output that always chooses the last element of the 
sequence is not ok. We differ in opinion as to what should happen instead: 
raising an error or returning a value at random. My arguments for the latter 
are: 
 - this seems to be the standard for other programming languages (I've checked 
for R and NetLogo but this should be confirmed by others);
 - a weight sequence [1, 1, 1, 1] is equivalent to [10, 10, 10, 10] so if we 
don't want to make [0, 0, 0, 0] 'a special case' it should give the same 
behaviour (equal probability);
 - when a weight sequence is not provided (i.e., there are no odds given) a 
random selection is made. One can argue that the odds [,,,,] are similar to [0, 
0, 0, 0 ]. Perhaps the zero weights option could be pushed into the if-loop of 
no weights? 

I see the logic of the second solution, i.e., raising an error. It may make it 
more difficult to catch the issue for those doing simulations but at least it's 
not giving a wrong result. 
 
As mentioned this is a key algorithm for many scientific applications with 
predominantly non-computer science users like myself. So please do take into 
consideration that it will be often used naively. 

Many thanks.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38881>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to