sorry to reopen this: I had the same problem and the thread was very helpful.
However, I’m trying to understand if the likelihood computation can be made more efficient. Along the way, I tried replacing the call to log_mix
in the likelihood function with a call to log_sum_exp
(since there are parts of the log_sum_exp
formula that can be precomputed in the transformed data section). So instead of:
log_mix(lambda,
uniform_lpdf(y | min_rt, max_rt),
wiener_lpdf(y | bs, ndt, bias, mu)
This:
log_sum_exp(log(lambda) + uniform_lpdf(y | min_rt, max_rt),
log1m(lambda) + wiener_lpdf(y | bs, ndt, bias, mu));
However- this causes divergences again. Any idea why?
As a reminder - this is the likelihood function:
real wiener_diffusion2_lpdf(real y, real mu, real bs,
real ndt, real bias, real lambda,
int dec, real min_rt, real max_rt) {
if (y < ndt) {
return(log(lambda) + uniform_lpdf(y | min_rt, max_rt));
} else {
if (dec == 1) {
return log_mix(lambda,
uniform_lpdf(y | min_rt, max_rt),
wiener_lpdf(y | bs, ndt, bias, mu)
);
} else {
return log_mix(lambda,
uniform_lpdf(y | min_rt, max_rt),
wiener_lpdf(y | bs, ndt, 1 - bias, - mu)
);
}
}
}