Hello,
I have a fairly simple model that is running fine… but it’s too slow. I know there is way to vectorize everything to avoid loops and improve the speed, but every single thing I’ve done following various postings leads the code to crash (I don’t even get an error… it just doesn’t run).
Here is the code:
data {
int<lower=0> nsite;
int<lower=0> ngroup;
int<lower=0> n;
int<lower=0> nbin;
int<lower=0> nharm;
int<lower=0> site[n];
int<lower=0> group[n];
int<lower=0> bin[n];
matrix[nbin,nharm] Z;
int<lower=0> pattern[n];
}
parameters {
real a[nsite,ngroup,nharm];
}
transformed parameters {
vector[n] mu;
for(i in 1:n)
{
mu[i]=exp(a[site[i],group[i],1]*Z[bin[i],1]+a[site[i],group[i],2]*Z[bin[i],2]+a[site[i],group[i],3]*Z[bin[i],3]+a[site[i],group[i],4]*Z[bin[i],4]+a[site[i],group[i],5]*Z[bin[i],5]+a[site[i],group[i],6]*Z[bin[i],6]+a[site[i],group[i],7]*Z[bin[i],7]+a[site[i],group[i],8]*Z[bin[i],8]+a[site[i],group[i],9]*Z[bin[i],9]);
}
}
model {
for(k in 1:nharm)
{
for(i in 1:ngroup)
{
for(j in 1:nsite)
{
a[j,i,k]~normal(0,100);
}
}
}
pattern~poisson(mu);
}
generated quantities {
int<lower=0> newpattern[n];
for(i in 1:n)
{
newpattern[i]=poisson_rng(mu[i]);
}
}
I tried to vectorize newpattern so I don’t use a loop like I did in the model section for pattern… but that doesn’t run… I tried to vectorize mu in generated quantities… didn’t work… I tried many different ways to remove the loop to give a prior for each element of the array a… nothing worked. I have no idea left regarding what I can try to do. Any help would be greatly appreciated!
Thanks!