-
-
Save huynhnguyen/9ff41dab13d77333816db04a6d50032f to your computer and use it in GitHub Desktop.
open journal (2/6/2017)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = np.random.randint(0,10,[n_topics, n_words])*1.0 | |
sum_over_topic = np.sum(p, axis=1) | |
dists = np.divide(p.T,sum_over_topic).T | |
n_topics = 3 | |
n_words = 10 | |
docs_topic = [0, 1, 2, 2, 1, 2, 0, 1, 2] | |
docs = [] | |
for d_topic in docs_topic: | |
_pvals = dists[d_topic] | |
# print(np.sum(_pvals[:,-1])) | |
docs.append(np.random.multinomial(n_words, _pvals, 1)[0]) | |
from sklearn.decomposition import LatentDirichletAllocation as LDA | |
lda = LDA(3) | |
np.argmax(lda.fit_transform(docs),axis=1) | |
n_topics = 3 | |
n_words = 10 | |
docs_topic = [0, 1, 2, 2, 1, 2, 0, 1, 2] | |
sess = ed.get_session() | |
# DATA | |
pi_true = np.random.dirichlet(np.Vocab) | |
z_data = np.array([np.random.choice(K, 1, p=pi_true)[0] for n in range(N)]) | |
print('pi={}'.format(pi_true)) | |
# MODEL | |
topic_over_docs = Dirichlet(tf.ones(n_words)) | |
w_ = Dirichlet(tf.ones(n_words)) | |
w_ = Categorical(probs= pi, sample_shape=N) | |
# INFERENCE | |
qpi = Dirichlet(tf.nn.softmax(tf.Variable(tf.random_normal([K])))) | |
inference = ed.KLqp({pi: qpi}, data={z: z_data}) | |
inference.run(n_iter=15000, n_samples=30) | |
print('Inferred pi={}'.format(sess.run(qpi.mean()))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment