Strange Error message

Hello!

I am new to Stan and this is probably a very basic question, but I have not found an answer.

I am trying to fit the stochastic volatility model from https://github.com/stan-dev/example-models/blob/master/misc/moving-avg/stochastic-volatility-optimized.stan. This works fine, but when I try to reparametrize the model to having mu = 0, but scaling the variance by sigma_y I get the following error:
“Error in sampler$call_sampler(args_list[[i]]) : " " c++ exception (unknown reason)”.
What does this mean? I can’t find any error in the code. The only change I have done is to replace mu by sigma in the “parameters” stage, and in “transformed parameters” I have removed mu. In the modelling stage, the only difference is that I multiply the standard error of y by sigma_y. This is the code I’m working with:

data {
int<lower=0> T; // # time points (equally spaced)
vector[T] y; // mean corrected return at time t
}
parameters {
real<lower=0> sigma_y; // variance of observations
real<lower=-1,upper=1> phi; // persistence of volatility
real<lower=0> sigma; // white noise shock scale
vector[T] h_std; // std log volatility time t
}
transformed parameters {
vector[T] h;
h <- h_std * sigma;
h[1] <- h[1] / sqrt(1 - phi*phi);
for (t in 2:T){
h[t] <- h[t] + phi *h[t-1];
}
}
model {
sigma ~ cauchy(0,5);
sigma_y ~ cauchy(0,2.5);
h_std ~ normal(0,1);
y ~ normal(0,exp(h/2)*sigma_y);
}

Any advice?

Thanks in advance!

Jens

Are you using the clang4 compiler from http://r.research.att.com/libs/clang-4.0.0-darwin15.6-Release.tar.gz ? That has a bug which prevents harmless exceptions from being caught.

Thanks for the response.
I know that I have downloaded the clang4 compiler, but I can’t tell if I’m using that one specific.
I opened the Makeconf file the first part reads:

R was configured using the following call

(not including env. vars and site configuration)

configure ‘CC=clang’ ‘CXX=clang++’ ‘OBJC=clang’ ‘CFLAGS=-Wall -g -O2’ ‘CXXFLAGS=-Wall -g -O2’ ‘OBJCFLAGS=-Wall -g -O2’ ‘FCFLAGS=-Wall -g -O2’ ‘F77FLAGS=-Wall -g -O2’ ‘–enable-memory-profiling’ ‘–x-libraries=/opt/X11/lib’ ‘–enable-R-framework’ ‘PKG_CONFIG_PATH=/usr/lib/pkgconfig:/opt/X11/lib/pkgconfig:/usr/local/lib/pkgconfig’

This fails if it contains spaces, or if it is quoted

include $(R_SHARE_DIR)/make/vars.mk

AR = ar
BLAS_LIBS = -L$(R_HOME)/lib$(R_ARCH) -lRblas
C_VISIBILITY =
CC = clang
CFLAGS = -Wall -g -O2 (LTO) CPICFLAGS = -fPIC CPPFLAGS = -I/usr/local/include CXX = clang++ CXXCPP = (CXX) -E
CXXFLAGS = -Wall -g -O2 $(LTO)
CXXPICFLAGS = -fPIC
CXX98 = clang++
CXX98FLAGS = -Wall -g -O2
CXX98PICFLAGS = -fPIC
CXX98STD =
CXX11 = clang++
CXX11FLAGS = -Wall -g -O2
CXX11PICFLAGS = -fPIC
CXX11STD = -std=gnu++11
CXX14 = clang++
CXX14FLAGS = -Wall -g -O2
CXX14PICFLAGS = -fPIC
CXX14STD = -std=gnu++14
CXX17 = clang++
CXX17FLAGS = -Wall -g -O2
CXX17PICFLAGS = -fPIC
CXX17STD = -std=gnu++1z

Does this mean that this is the compiler I’m using? If it does, what compiler should I use instead?

Thanks

We have this fixed for rstan 2.17.x, but in the meantime, it is probably best to use the compiler that comes with XCode. You can edit ~/.R/Makevars so that the CXX is environmental variable is /usr/bin/clang++ or wherever it lives on a Mac.