Hi all,
I got a (maybe stupid) question about how to run simulate efficiently…
I have written a model with the structure
functions {
real[,] run_simulation(argument1; argument2) {
[....]
return(results);
}
data {
int N1;
int N2;
real experimental_results[N1,N2];
}
parameters{
real<lower=0> parameter_1;
real<lower=0> parameter_2;
real<lower=0> sigma;
}
transformed parameters {
real simulations[N1, N2];
simulation = run_simulation(parameter_1, parameter_2);
}
model {
//priors
parameter_1 ~ lognormal (1,2);
parameter_2 ~ lognormal (1,2);
//likelihood
for (i in 1:N1) {
for (j in 1:N2) {
experimental_results[i,j] ~ normal (simulation[i,j] + sigma )
}
}
I’m wondering if the way of writing the likelyhood in for loops like this
//likelihood
for (i in 1:N1) {
for (j in 1:N2) {
experimental_results[i,j] ~ normal (simulation[i,j] + sigma )
}
}
Does this mean that my run_simulation is run N1*N2 times in each iteration, or is it run once? Are there better ways of writing this?
Thanks!