Different behavior in Cmdstan and Rstan

Hello everyone,

I am trying to fit a very simple drift diffusion model in Cmdstan, where I am interested in doing a parameter recovery study.

I am using the model bellow.


data{
int N; // number of trials;
int resp[N]; // correct/error responses per trial;
real rt[N]; // response times per trial
}

parameters{
real tau_raw; // logit of non-decision time
real delta; // drift-rate
real<lower = 0> alpha; // boundary separation
real<lower = 0, upper = 1> beta; // starting point


}

transformed parameters{
real tau; // non-decision time at RT scale

tau = inv_logit(tau_raw)*min(rt);

}

model{
delta ~ normal(1,.1); 
alpha ~ normal(1.5,.1);
beta ~ normal(.5,.1);

tau_raw ~ normal(-.2,.48);

for (n in 1:N){
  if (resp[n] == 1){
    target += wiener_lpdf(rt[n] | alpha, tau, beta, delta);
  } else{
    target += wiener_lpdf(rt[n] | alpha, tau, 1 - beta, - delta);
    }
  }
}

Everything seems to be working well in rstan (Version 2.18.2), the model fits, no warnings, no need to change initial values, etc. However, when I try to fit the exact same model, with the same data in Cmdstan, I get the following message regarding boundary separation (alpha in the model above):

Exception: wiener_lpdf: Boundary separation is inf, but must be finite!

In some instances, the model doesn’t start to sample because there were to many exceptions.

I already have a very narrow prior on this parameter and I have tried to lower the init parameter, with no effect.

Does anyone know why do Rstan and Cmdstan might have different behaviors?

Thanks in advance!

Rstan code

library(rstan)
options(mc.cores = 3)
rstan_options(auto_write = TRUE)

library(RWiener)

set.seed(123)
dcrt <- rwiener(n = 200, 
        alpha = 1.5, 
        tau = .5, 
        beta = .5, 
        delta = 1)

  N <-nrow(dcrt) 
  rt <- dcrt$q
  resp <- ifelse(dcrt$resp == "upper", 1,0)

dstan <- list(
  N=N,
  rt=rt,
  resp=resp
)

# Dumping data for Cmdstan
stan_rdump(c("N","rt","resp"), file = "dCmdstan.R")

m_fit <- sampling(model_not_working, 
                  data = dstan, 
                  chains = 1)

Cmdstan code

cd $path_cmdstan

make $path_model/model
 
cd $path_wd

.$path_model/model sample data file=dCmdstan.R

Iformational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception: wiener_lpdf: Boundary separation is inf, but must be finite! (in model.stan’ at line 32)

1 Like

I would imagine that it is just different random number seeds.

Thank you for your response.

setting the same seed for both models (123) will still result in the appearance of warning messages in Cmdstan and not in Rstan.

I should have also added that I have fitted this same model in Rstan for more 3000 times (for an SBC) without any warning messages.

RStan is not going to show exception messages during warmup. Are you actually getting different posterior summaries when you do it in CmdStan?

Are these differences significant?

edit(I forgot that Rstan and Cmdstan have different number of iter by default. The table is now expressing the differences between interfaces using an equal number of iter and the same seed)

summary(Rstan_fit, probs = c(.05,.5,.95))$summary - summary(Cmdstan_fit, probs = c(.05,.5,.95))$summary
mean se_mean sd 5% 50% 95% n_eff Rhat
tau_raw -0.0097 -0.0001 0.0048 -0.0082 -0.0057 -0.0021 182.1492 -0.0003
delta -0.0015 0.0002 0.0051 -0.0024 0.0022 0.0057 -205.2629 0.0004
alpha 0.0021 0.0000 0.0030 -0.0020 0.0019 0.0058 228.5129 0.0000
beta -0.0017 0.0000 -0.0007 0.0001 -0.0021 -0.0019 -5.7200 -0.0007
tau -0.0007 0.0000 0.0005 -0.0007 -0.0004 -0.0001 158.8177 -0.0004
lp__ -0.1308 0.0057 0.0359 -0.2109 -0.1628 -0.0121 -230.8708 -0.0048

I doubt those differences matter, but you also have to make sure that you have the same compiler options specified in ~/.R/Makevars as in cmdstan/make/local .

1 Like

Thank you for walking me through this. Everything seems to be fine.