Skip to content

Commit

Permalink
Cache LLH calls. 40% performance increase.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwintersinger committed Jun 30, 2015
1 parent ea174d7 commit 90d1778
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tssb.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def path_lt(path1, path2):
epsilon = finfo(float64).eps
lengths = []
for n in range(self.num_data):

llhmap = {}
# Get an initial uniform variate.
ancestors = self.assignments[n].get_ancestors()
current = self.root
Expand All @@ -106,7 +106,9 @@ def path_lt(path1, path2):

max_u = 1.0
min_u = 0.0
llh_s = log(rand()) + self.assignments[n].logprob(self.data[n:n+1])
old_llh = self.assignments[n].logprob(self.data[n:n+1])
llhmap[self.assignments[n]] = old_llh
llh_s = log(rand()) + old_llh

while True:
new_u = (max_u-min_u)*rand() + min_u
Expand All @@ -118,8 +120,11 @@ def path_lt(path1, path2):
old_node.remove_datum(n)
new_node.add_datum(n)
self.assignments[n] = new_node
new_llh = new_node.logprob(self.data[n:n+1])

if new_node in llhmap:
new_llh = llhmap[new_node]
else:
new_llh = new_node.logprob(self.data[n:n+1])
llhmap[new_node] = new_llh
if new_llh > llh_s:
break
elif abs(max_u-min_u) < epsilon:
Expand Down

0 comments on commit 90d1778

Please sign in to comment.