Skip to content

Commit

Permalink
Merge pull request #10 from gstamatelat/simplify-variables
Browse files Browse the repository at this point in the history
Remove redundant scaled_prob variable
  • Loading branch information
asmith26 authored Oct 28, 2021
2 parents eb7af6d + 96bffc4 commit f94f4b2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions vose_sampler/vose_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ def alias_initialisation(self):
n = len(self.dist)
self.table_prob = {} # probability table
self.table_alias = {} # alias table
scaled_prob = {} # scaled probabilities
small = [] # stack for probabilities smaller that 1
large = [] # stack for probabilities greater than or equal to 1

# Construct and sort the scaled probabilities into their appropriate stacks
for o, p in self.dist.items():
scaled_prob[o] = Decimal(p) * n
self.table_prob[o] = Decimal(p) * n

if scaled_prob[o] < 1:
if self.table_prob[o] < 1:
small.append(o)
else:
large.append(o)
Expand All @@ -50,12 +49,11 @@ def alias_initialisation(self):
s = small.pop()
l = large.pop()

self.table_prob[s] = scaled_prob[s]
self.table_alias[s] = l

scaled_prob[l] = (scaled_prob[l] + scaled_prob[s]) - Decimal(1)
self.table_prob[l] = (self.table_prob[l] + self.table_prob[s]) - Decimal(1)

if scaled_prob[l] < 1:
if self.table_prob[l] < 1:
small.append(l)
else:
large.append(l)
Expand Down

0 comments on commit f94f4b2

Please sign in to comment.