In the following simple “mixing gaussians” model (with 2 components), I’m not able to understand why the “Vectorized” form is NOT producing the same result as the “loop” form (see code below).

From my understanding this statements should be identical. What I’m I doing wrong?

Thank You

data {

int N;

real y[N];

}

parameters {

simplex[2] theta;

ordered[2] mu;

vector<lower=0>[2] sigma;

}

model {

sigma ~ lognormal(0,2);

mu ~ normal(0, 10);

//THIS DOES NOT WORK LIKE EXPECTED!!

target += log_sum_exp(log(theta[1])+normal_lpdf(y | mu[1], sigma[1]),log(theta[2])+normal_lpdf(y | mu[2], sigma[2]));

//THIS WORK!!

//for(n in 1:N)

// target += log_sum_exp(log(theta[1])+normal_lpdf(y[n] | mu[1], sigma[1]),log(theta[2])+normal_lpdf(y[n] | mu[2], sigma[2]));

}