David Heiberg <dhdav...@gmail.com> added the comment:

Just playing around with this and I think one thing to consider is how to 
handle negative weights. Should they even be allowed? One interesting behaviour 
I encountered with the current draft is the following:

    >>> r.sample(['katniss', 'prim', 'gale', 'peeta'] , weights=[-2,1,1,1], k=1)
    ['peeta']

This will always return ['peeta'], or whatever happens to be in the last index. 
I believe this is because in `choices`, the `cum_weights` list would be [-2, 
-1, 0, 1], causing it to only be able to select the last value in the 
population. 

Looking into random.choices, it suggests that the weights were designed with 
negative ones in mind. However they were not accounted for and end up 
influencing the weights of the indexes around it. Another example is this:

    >>> r.choices(['alice', 'bob', 'camile', 'david'], weights=[1, 1, -2, 1])
    ['alice']

This will always return ['alice'], showing that the negative weight of 'camile' 
is affecting indexes around it. 
Is there something I am missing? Otherwise this seems like it may warrant its 
own bug.

----------
nosy: +dheiberg

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

Reply via email to