This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mark.dickinson, rhettinger, tim.peters
Date 2020-06-26.20:57:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593205037.11.0.430730264801.issue41131@roundup.psfhosted.org>
In-reply-to
Content
I also looked at another method using binomial variates but couldn't get it to run faster than the alias method:

    def choices(population, weights, *, k=1):
        r = 1.0
        n = k
        selections = []
        for elem, p in zip(population, weights):
            v = binomial_variate(n, p / r)
            selections += [elem] * v
            n -= v
            r -= p
        shuffle(selections)
        return selections

The shuffle step took as much time as the alias method.  Also, the binomial variate was hard to compute quickly and without overflow/underflow issues for large inputs.
History
Date User Action Args
2020-06-26 20:57:17rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson
2020-06-26 20:57:17rhettingersetmessageid: <1593205037.11.0.430730264801.issue41131@roundup.psfhosted.org>
2020-06-26 20:57:17rhettingerlinkissue41131 messages
2020-06-26 20:57:16rhettingercreate