Hi Everyone,

I am new to Stan. I am trying to run my code in Matlab but every time I run it, I face this error “Rejecting initial value:

Error evaluating the log probability at the initial value.” I put part of my code here. Any suggestion? Thank you in advance.

evol_code = {

‘data {’

’ int<lower=0> T; ‘

’ int<lower=0> N; ‘

’ real<lower=0,upper=1> Fhat[N,T]; ‘

’ int<lower=0,upper=1> Tr[N,N]; ‘

’ int<lower=0,upper=1> U[N,N]; ‘

’}’

‘parameters {’

’ real mu[N]; ‘

’ real<lower=0> delta_tau[N]; ‘

’}’

‘transformed parameters {’

’ real<lower=0> tau[N];’

’ real<lower=0> M[N,T];’

’ real<lower=0,upper=1> F[N,T];’

’ real<lower=0> den;’

’ for (n in 1:N){’

’ tau[n] = 0; ‘

’ for (s in 1:N)’

’ tau[n] = tau[n] + U[s,n]*delta_tau[s];’
’ }’
‘for(i in 1:T){’
’ den = 0.01;
’ for (n in 1:N){’
’ if (tau[n] > i - 1){’
’ M[n,i] = 0.01;’
’ }else{’
’ M[n,i] = exp(mu[n]*(i-1 - tau[n]));’

’ }’

’ den = den + M[n,i];’

’ }’

’ for (n in 1:N){’

’ M[n,i] = M[n,i]/ den;’

’ }’

’}’

‘for (i in 1:T){’

‘for (n in 1:N){’

‘F[n,i]=0;’

‘for (k in 1:N){’

’ F[n,i]= F[n,i] + U[i,k]*M[k,i];’

’}’

’}’

’}’

’}’

‘model {’

’ for(n in 1:N) {’

’ mu[n] ~ normal(0, 0.1);’

’ delta_tau[n] ~ exponential(2);’

’ for (i in 1:T){’

’ Fhat[n,i] ~ normal(F[n,i],0.01);’

’ }’

’ }’

’}’

};

evol_dat = struct(‘T’,11,‘N’,6,…

‘Fhat’,Fdata,…

‘Tr’,Trdata,‘U’,Udata);

model = StanModel(‘verbose’,true,‘model_code’,evol_code,‘data’,evol_dat);

model.compile();

fit_vb = model.vb();

print(fit_vb);

‘Tr’,Trdata,‘U’,Udata);