Skip to content

Commit dc40ac4

Browse files
committed
Merge pull request dongwookim-ml#3 from judaschrist/master
Error correction in gibbs sampling for sLDA
2 parents b54c324 + e2b58ea commit dc40ac4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ptm/slda_gibbs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ def stochasticEM(self, max_iter, docs, responses):
7676
self.doc_topic_sum[di,old_topic] -= 1
7777

7878
z_bar = np.zeros([self.K,self.K]) + self.doc_topic_sum[di,:] + np.identity(self.K)
79-
z_bar /= z_bar.sum(0)
79+
# this seems more straightforward than z_bar/z_bar.sum(1)
80+
z_bar /= self.doc_topic_sum[di,:].sum() + 1
8081

8182
#update
82-
prob = (self.WK[word, :])/(self.sumK[:]) * (self.doc_topic_sum[di,:]) * np.exp(np.negative((responses[di] - np.dot(z_bar.T,self.eta))**2))
83+
prob = (self.WK[word, :])/(self.sumK[:]) * (self.doc_topic_sum[di,:]) * np.exp(np.negative((responses[di] - np.dot(z_bar,self.eta))**2)/2/self.sigma)
8384

8485
new_topic = sampling_from_dist(prob)
8586

0 commit comments

Comments
 (0)