Hello,
I am trying to model Dirichlet process Gaussian mixture model using Stan.
I know that it is impossible, so I tried to mimic Dirichlet process using stick breaking by assuming the maximum number of clusters. I saw similar approach in PyMC3 link
Well, the dirichlet process is not the problem in this topic.
Do you have any suggestions to speed up mixture model?
Below is the stan code. It is simple code. I tried to remove the double for loops but failed.
Thanks in advance!
model {
real alpha = 1;
real a=0.001;
real b=0.001;
real ps[C];
sigma_cl ~ inv_gamma(a,b);
mu_cl ~ normal(0,5);
//alpha~gamma(6,1);
v ~ beta(1,alpha);
for(i in 1:N){
for(c in 1:C){
ps[c]=log(pi[c])+normal_lpdf(y[i]|mu_cl[c],sigma_cl[c]);
}
target += log_sum_exp(ps);
}
}
You can see the full analysis here
https://ecosang.github.io/blog/study/dirichlet-process-with-stan/