Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created May 27, 2014 12:14
Show Gist options
  • Select an option

  • Save cigrainger/5b05afedea540bcec8e9 to your computer and use it in GitHub Desktop.

Select an option

Save cigrainger/5b05afedea540bcec8e9 to your computer and use it in GitHub Desktop.
kl = []
num = range(0,25000,10)
for i in num:
lda = models.ldamodel.LdaModel(corpus=my_corpus,
id2word=dictionary,num_topics=i,distributed=True)
#Topic-word matrix
m1 = lda.expElogbeta
U,s,V = np.linalg.svd(p)
cm1 = s
#Document-topic matrix
lda_topics = lda[my_corpus]
m2 = matutils.corpus2dense(lda_topics, lda.num_topics)
l = []
for doc in my_corpus:
x = []
for i in range(len(doc)):
x.append(doc[i][1])
l.append(sum(x))
l = np.array(l)
cm2 = m2.dot(l)
cm2norm = np.linalg.norm(l)
cm2 = cm2/cm2norm
div = sym_kl(cm1,cm2)
kl.append(div)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment