forked from zdavidli/tool-presence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.stan
37 lines (33 loc) · 992 Bytes
/
model.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
data {
int N; // number of observations
int D; // dimension of observed vars
int K; // number of clusters
vector[D] x[N]; // training data
}
parameters {
ordered[K] mu; // locations of hidden states
vector<lower=0>[K] sigma; // variances of hidden states
simplex[K] theta[D]; // mixture components
}
model {
matrix[K,D] obs = rep_matrix(0.0, K, D);
// priors
for(k in 1:K){
mu[k] ~ normal(0,10);
sigma[k] ~ inv_gamma(1,1); //prior of normal distribution
}
for (d in 1:D){
theta[d] ~ dirichlet(rep_vector(2.0, K)); //prior of categorical distribution
}
// likelihood
for(i in 1:N) {
vector[D] increments;
for(d in 1:D){
increments[d]=log_mix(theta[d][1],
normal_lpdf(x[i][d] | mu[1], sigma[1]), normal_lpdf(x[i][d] | mu[2], sigma[2]));
}
target += log_sum_exp(increments);
}
}
generated quantities {
}