Dear Stan users,
I’m using a Stan model adapted from The Virtual Brain to fit real SEEG data.
The model computes the joint log probability of slp
(SEEG log power) and snsr_pwr
.
During fitting (using optimize
with LBFGS), I encountered the following error messages in the early phase of optimization:
Exception: normal_lpdf: Scale parameter is -85.0778, but must be > 0!
Error evaluating model log probability: Non-finite function evaluation.
However, the optimization eventually terminates normally.
My questions:
-
I confirmed that the initial values for the scale parameters
eps_slp
andeps_snsr_pwr
are strictly positive (both set to 1.0), and they are also constrained in the model usingT[0,]
.
→ Is it still possible fornormal_lpdf(..., ..., scale)
to evaluate with a negative scale parameter during optimization? -
Since this error occurred early and the optimization finished successfully,
→ Can these errors be safely ignored, or are they indicative of deeper instability in the model?
I attach the stan code for your reference.
transformed parameters{
// Euler integration of the epileptor without noise
row_vector[nn] x[nt];
row_vector[nn] z[nt];
row_vector[ns] mu_slp[nt];
row_vector[ns] mu_snsr_pwr = rep_row_vector(0, ns);
for (t in 1:nt) {
if(t == 1){
x[t] = x_step(x_init, z_init, I1, time_step);
z[t] = z_step(x_init, z_init, x0, K*SC, time_step, tau0);
}
else{
x[t] = x_step(x[t-1], z[t-1], I1, time_step);
z[t] = z_step(x[t-1], z[t-1], x0, K*SC, time_step, tau0);
}
mu_slp[t] = amplitude * (log(gain * exp(x[t])')' + offset);
mu_snsr_pwr += mu_slp[t] .* mu_slp[t];
}
mu_snsr_pwr = mu_snsr_pwr / nt;
}
model {
x0 ~ normal(x0_mu, 1.0);
amplitude ~ normal(1.0, 10.0)T[0,];
offset ~ normal(0, 10.0);
tau0 ~ normal(20, 10.0)T[5,];
K ~ normal(1.0, 10.0)T[0,];
for (i in 1:nn){
x_init[i] ~ normal(-2.0, 10.0);
z_init[i] ~ normal(3.5, 10.0);
}
eps_slp ~ normal(1, 10)T[0,];
eps_snsr_pwr ~ normal(1, 10)T[0,];
for (t in 1:nt) {
target += normal_lpdf(slp[t] | mu_slp[t], eps_slp);
}
target += normal_lpdf(snsr_pwr | mu_snsr_pwr, eps_snsr_pwr);
}
All initial parameter values (including x_init
, z_init
, eps_slp
, etc.) are confirmed to be in valid ranges.
Any help in understanding whether this issue is critical or safe to ignore would be greatly appreciated!
Thanks in advance!