Compilation error on rstan

The code that’s throwing this error is:

var fx = f(x, xc, theta_var, x_r, x_i, msgs);
fx.grad();
gradient = theta_var[n].adj();
if (is_nan(gradient)) {
  if (fx.val() == 0) {
    gradient = 0;
  } else {
    throw_domain_error("gradient_of_f", "The gradient of f", n,
                       "is nan for parameter ", "");
  }
}

return gradient;

So if the function is f(\theta_1, \theta_2, ...), \frac{\partial f}{\partial \theta_4} is evaluating to NaN (probably due to an overflow) and f is evaluating to something non-zero. It’s pretty common for gradients to be NaN at limits of integration, but as long as f is zero we ignore it. My first reaction was to look for integrations with infinite limits, but since this is nested finite integrals I don’t know where to start looking either.

One of your comments says PDE solution. What PDE is this solving? Is there a way to discretize this spatially and solve it with the ODE solver?

Otherwise it’s probably rather crude but just do the integrals with the ODE solver. This problem happened yesterday: Difference in behavior between integrate_1d and integrate - #11 by bbbales2 . I think we need to do something different for our integration. This quadrature just blows up too much and it’s nigh impossible to debug.

1 Like