Hi,
I previously had a thread on some similar issues with integrate_1d() here.
https://discourse.mc-stan.org/t/calling-integrate-1d-reports-parsing-error-parser-expected/19611
I’m starting a new thread since the previous one was dealing with all kinds of issues as I was learning my way around this functionality. Previously, @bbbales helped me rewrite my code and I was able to fix most of my problems. But I notice that I occasionally get the below message. I’ve been ignoring this for the time being, but I’m now trying to figure out if that messes up my posterior.
Chain 1 Exception: Exception: Exception: Error in function boost::math::quadrature::sinh_sinh<double>::integrate: The sinh_sinh quadrature evaluated your function at a singular point, leading to the value nan.
Chain 1 Exception: Exception: Exception: Error in function boost::math::quadrature::sinh_sinh<double>::integrate: The sinh_sinh quadrature evaluated your function at a singular point, leading to the value nan.
Chain 1 sinh_sinh quadrature cannot handle singularities in the domain.
Chain 1 If you are sure your function has no singularities, please submit a bug against boost.math
Chain 1 (in '/home/karim/Code/takeup/stan_models/takeup_functions.stan', line 88, column 2, included from
Chain 1 '/tmp/RtmpXSRlSq/model-43e777e2eb735.stan', line 2, column 0) (in '/home/karim/Code/takeup/stan_models/takeup_functions.stan', line 88, column 2, included from
Chain 1 '/tmp/RtmpXSRlSq/model-43e777e2eb735.stan', line 2, column 0) (in '/home/karim/Code/takeup/stan_models/takeup_functions.stan', line 88, column 2, included from
Chain 1 '/tmp/RtmpXSRlSq/model-43e777e2eb735.stan', line 2, column 0)
Below is my code (two small functions). I call expected_delta
from another function that is called by algebra_solver_newton
. expected_delta
uses integrate_1d
calling expected_delta_part
where the problem happens.
real expected_delta_part(real v, real xc, real[] theta, data real[] x_r, data int[] x_i) {
real w = theta[1];
real u_sd = theta[2];
real wmv_cdf = Phi_approx((w - v) / u_sd);
real v_lpdf = normal_lpdf(v | 0, 1);
return v * exp(v_lpdf) * wmv_cdf; // <---------- This is the line reported as the problem
}
real expected_delta(real w, real total_error_sd, real u_sd, data real[] x_r, data int[] x_i) {
real delta_part;
real F_w;
print("w = ", w, ", u_sd = ", u_sd);
delta_part = integrate_1d(expected_delta_part, negative_infinity(), positive_infinity(), { w, u_sd }, x_r, x_i, 0.00001);
print("delta_part = ", delta_part);
F_w = Phi_approx(w / total_error_sd);
return - delta_part / (F_w * (1 - F_w));
}
I exported this function using rstan and tested in R’s integrate
function and seems to work fine. I tried all kinds of extreme values for the theta
variables (w
and u_sd
) but the function works fine unless I pass it a NaN.
In the above Stan code, I also added a print
statement to try and show the values passed into integrate_1d
that cause the problem but I can’t seem to catch it. Below is the kind of output I’m seeing (running a single chain). I expected the exception to be raised between printing out w
and u_sd
and printing delta_part
.
Chain 1 w = 0.125534, u_sd = 0.836498
Chain 1 delta_part = -0.304586
Chain 1 w = 0.125534, u_sd = 0.836498
Chain 1 delta_part = -0.304586
Chain 1 Exception: Exception: Exception: Error in function boost::math::quadrature::sinh_sinh<double>::integrate: The sinh_sinh quadrature evaluated your function at a singular point, leading to the value nan.
Chain 1 Exception: Exception: Exception: Error in function boost::math::quadrature::sinh_sinh<double>::integrate: The sinh_sinh quadrature evaluated your function at a singular point, leading to the value nan.
Chain 1 sinh_sinh quadrature cannot handle singularities in the domain.
Chain 1 If you are sure your function has no singularities, please submit a bug against boost.math
Chain 1 (in '/home/karim/Code/takeup/stan_models/takeup_functions.stan', line 88, column 2, included from
Chain 1 '/tmp/RtmpXSRlSq/model-43e777e2eb735.stan', line 2, column 0) (in '/home/karim/Code/takeup/stan_models/takeup_functions.stan', line 88, column 2, included from
Chain 1 '/tmp/RtmpXSRlSq/model-43e777e2eb735.stan', line 2, column 0) (in '/home/karim/Code/takeup/stan_models/takeup_functions.stan', line 88, column 2, included from
Chain 1 '/tmp/RtmpXSRlSq/model-43e777e2eb735.stan', line 2, column 0)
Any suggestions on how I can figure out the cause of this exception?
I’m using the R package {cmdstanr} and using cmdstan version 2.26.
Thanks!
Karim