Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sebastian's resampling wheel

  • Loading branch information...
commit bc0f9dfad88933957e6de5e7d734e9176f576995 1 parent cca3c6a
huanghuang authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 3-19.py
View
13 3-19.py
@@ -147,6 +147,19 @@ def eval(r, p):
p3.append(p[bisect.bisect(acc, random.random()*s)])
#weighted sample solution 2
+index = int(random.random() * N)
+beta = 0.0
+mw = max(w)
+for i in range(N):
+ beta += random.random() * 2.0 * mw
+ while beta > w[index]:
+ beta -= w[index]
+ index = (index + 1) % N
+ p3.append(p[index])
+p = p3
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.