Created
October 5, 2014 16:22
-
-
Save soonraah/3813bd0533654b4dc038 to your computer and use it in GitHub Desktop.
Stan code to train multi dimensional GMM (Gaussian Mixture Model) with diagonal covariance.
This file contains hidden or 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=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 | |
vector<lower=0.0>[D] sigma[M]; // standard deviation | |
} | |
model { | |
real ps[M]; | |
for(n in 1:N){ | |
for(m in 1:M){ | |
ps[m] <- log(weights[m]); | |
for(d in 1:D){ | |
ps[m] <- ps[m] + normal_log(X[n, d], mu[m, d], sigma[m, d]); | |
} | |
} | |
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