I’m trying to fit a version of vanilla LDA that takes in the word distribution for each document. So I just take
\beta_k = topic distributions ~ Dir(\gamma)
\theta_d = per document mixture proportions ~ Dir(\alpha)
\xi_d = per document observed word distribution~ Dir(B \cdot \theta)
where B is the matrix of \beta_k as row vectors.
Here’s my stan code
data {
int<lower=1> K; // num topics
int<lower=1> V; // num words
int<lower=0> D; // num docs
simplex[V] xi[D]; // word proportions for each doc
// hyperparameters
vector<lower=0>[K] alpha;
vector<lower=0>[V] gamma;
}
parameters {
simplex[K] theta[D]; // topic mixtures
simplex[V] beta[K]; // word dist for k^th topic
}
model {
for (d in 1:D) {
theta[d] ~ dirichlet(alpha);
}
for (k in 1:K) {
beta[k] ~ dirichlet(gamma);
}
for (d in 1:D) {
vector[V] eta;
eta = beta[1] * theta[d, 1];
for (k in 2:K) {
eta = eta + beta[k] * theta[d, k];
}
xi[d] ~ dirichlet(eta);
}
}
}
When I try to fit this model, I get the usual Stan error
Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can’t start sampling from this initial value.
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Error in sampler$call_sampler(c(args, dotlist)) : Initialization failed.
I must have missed a constraint, or maybe the model is flawed. Any help is greatly appreciated!