Skip to content

Instantly share code, notes, and snippets.

@breakbee
Created August 9, 2014 19:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breakbee/1456db5dad0132c3f116 to your computer and use it in GitHub Desktop.
Save breakbee/1456db5dad0132c3f116 to your computer and use it in GitHub Desktop.
Gaussian Mixture Model for Stan
data {
int<lower=1> N;
int<lower=1> k;
real X[N];
}
parameters {
simplex[k] theta;
real mu[k];
}
model {
real ps[k];
for (i in 1:k){
mu[i] ~ normal(0, 1.0e+2);
}
for(i in 1:N){
for(j in 1:k){
ps[j] <- log(theta[j]) + normal_log(X[i], mu[j], 1.0);
}
increment_log_prob(log_sum_exp(ps));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment