diff --git a/utils.py b/utils.py index 554ab0958..9d9b93cd1 100644 --- a/utils.py +++ b/utils.py @@ -193,7 +193,9 @@ def probability(p): """Return true with probability p.""" return p > random.uniform(0.0, 1.0) + def weighted_sample_with_replacement(n, seq, weights): + """Pick n samples from seq at random, with replacement, with the probability of each element in proportion to its corresponding weight."""