Using the wiener_lpdf() function in the cmdstanr package to implement a diffusion model, the construction of a Markov chain was unsuccessful

I encountered the following problem when running the code related to the seven parameter diffusion model using the latest version 2.35 of the cmdstanr package. After repeated modifications, it still persists. I really can’t find the reason. I hope to receive everyone’s help.Thank you.
The code I am running mainly comes from Valentin Pratz - The full diffusion model in Stan - Level 1 And I made corresponding adjustments. The current code does not report any errors, but building a Markov chain was unsuccessful.
##example
I used a new version of the function wiener_lpdf (rt [i] | a, t0, w, v [cnd [i]], sv, sw, st0)
I mainly learned from the following link.
#2822


estimate1.R (1.4 KB)

#code:
library(cmdstanr)
load(“L1dat.RData”)
data ← Level1dat
summary(data)
et_cmdstan_path(path=NULL)
chains = 4

initial values

init.stan = function(){
L = list()
for (i in 1:chains) {
L[[i]] = list(
sv = 1 + runif(1, -0.1, 0.1),
sw = 0.1 + runif(1, -0.05, 0.05),
st0 = 0.2 + runif(1, -0.05, 0.05)
)
}
return(L)
}

Compiling model

#mc ← cmdstan_model(“Level1.stan”)
#mc<-cmdstan_model(file)
mc ← cmdstan_model(“D:\seven\level1\level1.stan”)
stan.data = list(
N = nrow(data),
Ncnds = 3,
rt = data$RT,
stim = as.numeric(data$Stim),
resp = as.numeric(data$Resp),
cnd = as.numeric(data$Cond),
a = 1,
t0 = 0.3,
w = 0.45,
v = c(3.5, 2.5, 1.5)
)
outdir = “fits”
dir.create(outdir, recursive = T, showWarnings = FALSE)
m ← mc$sample(data=stan.data,
init = init.stan(),
refresh = 25,
iter_sampling = 250,
iter_warmup = 250,
chains = chains,
parallel_chains = 4,
output_dir = outdir,
output_basename = “fit”,
save_warmup = TRUE
)
##issues
unning MCMC with 4 parallel chains…

Chain 2 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410Warning: Chain 2 finished unexpectedly!

Chain 1 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410Warning: Chain 1 finished unexpectedly!

Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:

Chain 3 Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 0.999729, but must be smaller than 2*(A-priori bias) = 0.9 (in ‘C:/Users/13201/AppData/Local/Temp/RtmpYrSjfs/model-6fc8368c44a1.stan’, line 29, column 8 to column 72)

Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,

Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

Chain 3 Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:

Chain 4 Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 0.999978, but must be smaller than 2*(A-priori bias) = 0.9 (in ‘C:/Users/13201/AppData/Local/Temp/RtmpYrSjfs/model-6fc8368c44a1.stan’, line 29, column 8 to column 72)

Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,

Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

##Expected output
I hope to generate Markov chains normally.Hope to receive help.

####Current version:
cmdstanr packages 2.35

L1dat.RData (23.3 KB)
estimate1.R (1.4 KB)
level1.stan (1.6 KB)
The data and code are given here. I hope someone who understands can help take a look, thank you very much.

@Franzi

I’ve opened an issue from this: Eigen assertion failure in `hcubature` · Issue #3075 · stan-dev/math · GitHub

2 Likes

OK!Thank you for your help.

Hi @jlb -

We just released another round of release candidates which include a fix for the error you were receiving here.

Thanks for helping test out new features!

Great, thank you. I should thank you for helping me solve the problem that has been bothering me for a long time.

I’m very sorry to bother you again.I ran the code with the new version, but I still had some issues. I still don’t know what could be causing this. If you have time, can you help me take a look? Thank you very much.
Chain 4 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410 Warning: Chain 4 finished unexpectedly! Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: Chain 1 Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 1, but must be smaller than 2*(A-priori bias) = 0.9 (in ‘C:/Users/13201/AppData/Local/Temp/RtmpiIkg55/model-ac6ca4348a.stan’, line 29, column 8 to column 72) Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. Chain 1 Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: Chain 3 Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 0.989669, but must be smaller than 2*(A-priori bias) = 0.9 (in ‘C:/Users/13201/AppData/Local/Temp/RtmpiIkg55/model-ac6ca4348a.stan’, line 29, column 8 to column 72) Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. Chain 3 Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: Chain 2 Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 0.999998, but must be smaller than 2*(A-priori bias) = 0.9 (in ‘C:/Users/13201/AppData/Local/Temp/RtmpiIkg55/model-ac6ca4348a.stan’, line 29, column 8 to column 72) Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified. Chain 2 Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:

Chain 1 Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 1, but must be smaller than 2*(A-priori bias) = 0.9 (in ‘C:/Users/13201/AppData/Local/Temp/RtmpiIkg55/model-ac6ca4348a.stan’, line 29, column 8 to column 72) Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

@jlb Just to make sure you’re not getting an old version of the code, I recommend deleting both the built executable file and the 2.35.0-rc2 folder and re-running the analysis with the new code. It’s possible there is another issue we’ve missed, but I ran the code a few times without seeing the error after we made some changes that are present in rc3

1 Like

Ok, thank you, I’m going to try again as you say.



I’m very sorry to bother you again. I deleted the previous version of the file and ran it with the new version. Unfortunately, it still has such problems. Can you help me take a look?

Dear @WardBrian, I also included the new version of hcubature into my files and still obtain the following error message:

It looks quite similar to the one @jlb reports. I don’t know how to test which line of the code fails or in which iteration, as this error occurs in the sampling in R and not in one of the tests in stan-math.

@Franzi are you pulling from github or downloading the rc3 tarball?

I pulled the develop branch from github.

Hm. I have not been able to re-create any failures since the changes, which make it very difficult to debug.

Had R printed anything yet about what iteration number, or was this during initialization?

This was during initialization. The first iteration was not yet found when this error occurred.

I’m trying again to reproduce locally. In the mean time, can you try to include this code in the executable?

#define BOOST_STACKTRACE_USE_ADDR2LINE 1
#include <stdexcept>
#include <iostream>
#include <boost/stacktrace.hpp>
#undef eigen_assert
#define eigen_assert(x) \
  if (!(x)) { std::cerr << boost::stacktrace::stacktrace() << std::endl;\
               throw (std::runtime_error("Eigen asserted!")); }

This will print the locations of where Eigen asserted. The easiest way to do this is probably with the user_header argument to cmdstan_model in cmdstanr.

I think you will also need to compile with debug symbols (CXXFLAGS+= -ggdb3) to get meaningful output.

@Franzi did you run a make clean-all before building the model?

I’ve been re-running it in a loop all morning until it finishes initialization and I’ve yet to get a failure. If you have one, can you save out the initial values used and the seed and pass them along?

Hey @WardBrian, now, I installed the new release on a cluster. There, the model compiles and and starts sampling. This is good.

I have to wait until the sampling is finished to see whether the error does not occur during sampling. If this is the case, I will post another message here.

I ran the code with the new version but I still get the following problem, I don’t know what caused it.What should I do?
Model executable is up to date!
Running MCMC with 4 sequential chains…

Chain 1 Iteration: 1 / 650 [ 0%] (Warmup)
Chain 1 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410
警告: Chain 1 finished unexpectedly!

Chain 2 Iteration: 1 / 650 [ 0%] (Warmup)
Chain 2 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410
警告: Chain 2 finished unexpectedly!

Chain 3 Iteration: 1 / 650 [ 0%] (Warmup)
Chain 3 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410
警告: Chain 3 finished unexpectedly!

Chain 4 Iteration: 1 / 650 [ 0%] (Warmup)
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: Exception: wiener_lpdf: Inter-trial variability in A-priori bias = 1, but must be smaller than 2*(A-priori bias) = 1 (in ‘C:/Users/admin/AppData/Local/Temp/Rtmpg154Tn/model-3ef034a841bc.stan’, line 10, column 8 to column 95) (in ‘C:/Users/admin/AppData/Local/Temp/Rtmpg154Tn/model-3ef034a841bc.stan’, line 61, column 2 to line 63, column 15)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Assertion failed: index >= 0 && index < size(), file stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/DenseCoeffsBase.h, line 410
Chain 4 finished unexpectedly!
Use read_cmdstan_csv() to read the results of the failed chains.
No CmdStan runs finished successfully. Unable to run bin/stansummary.

1: ‘threads_per_chain’ is set but the model was not compiled with ‘cpp_options = list(stan_threads = TRUE)’ so ‘threads_per_chain’ will have no effect!
2: All chains finished unexpectedly! Use the $output(chain_id) method for more information.

3: No chains finished successfully. Unable to retrieve the fit.