data{ int N; //number of data int K; // number of components real x[N]; //data vector[K] alpha; //hyperparameter for mixing ratio real beta; //hyperparameter for center of component } parameters{ real mu[K]; //parameter for center of componet simplex[K] ratio; //parameter for mixing ratio } /** learning model: p(x|w) = sum_{k=1}^{K} ratio_k N(x-mu_k|1) priors: varphi(w|alpha,beta) = Dir(ratio|alpha) prod_k N(mu_k|0,beta) **/ model{ real p_comp[K]; //log priors ratio ~ dirichlet(alpha); for(k in 1:K){ mu[k] ~ normal(0, beta); } //log likelihood for(i in 1:N){ for(k in 1:K){ p_comp[k] <- log(ratio[k])+normal_log(x[i], mu[k], 1); } increment_log_prob(log_sum_exp(p_comp)); } }