Skip to content

Instantly share code, notes, and snippets.

@soonraah
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soonraah/c7f680f90af757d80d50 to your computer and use it in GitHub Desktop.
Save soonraah/c7f680f90af757d80d50 to your computer and use it in GitHub Desktop.
Stan code for multi dimension GMM with full covariance
data {
int<lower=1> D; // number of dimensions
int<lower=1> N; // number of samples
int<lower=1> M; // number of mixture components
vector[D] X[N]; // data to train
}
parameters {
simplex[M] weights; // mixture weights
vector[D] mu[M]; // means
cov_matrix[D] sigma[M]; // covariance matrix
}
model {
real ps[M];
for(n in 1:N){
for(m in 1:M){
ps[m] <- log(weights[m]) + multi_normal_log(X[n], mu[m], sigma[m]);
}
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