Created
April 10, 2013 23:11
-
-
Save alexbeutel/5359257 to your computer and use it in GitHub Desktop.
from stan lda example
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
data { | |
int<lower=2> K; // num topics | |
int<lower=2> V; // num words | |
int<lower=1> M; // num docs | |
int<lower=1> N; // total word instances | |
int<lower=1,upper=V> w[N]; // word n | |
int<lower=1,upper=M> doc[N]; // doc ID for word n | |
vector<lower=0>[K] alpha; // topic prior | |
vector<lower=0>[V] beta; // word prior | |
} | |
parameters { | |
simplex[K] theta[M]; // topic dist for doc m | |
simplex[V] phi[K]; // word dist for topic k | |
} | |
model { | |
for (m in 1:M) | |
theta[m] ~ dirichlet(alpha); // prior | |
for (k in 1:K) | |
phi[k] ~ dirichlet(beta); // prior | |
for (n in 1:N) { | |
real gamma[K]; | |
for (k in 1:K) | |
gamma[k] <- log(theta[doc[n],k]) + log(phi[k,w[n]]); | |
lp__ <- lp__ + log_sum_exp(gamma); // likelihood | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment