Integrate_1d error

I am receiving the following error when trying to evaluate an integral in Stan:

Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: integrate: error estimate of integral 1.8538e-46 exceeds the given relative tolerance times norm of integral


I have followed some advice from another thread and printed out the parameter/data values where the error occurs. Using this information I calculated the integral in R. The resulting integral (conditional on the data and parameter values that produced the first error) is:

\int_0^{9.13938} \exp(t-1-2\exp(t-1) - \exp(9.13938-t-1))dt \approx 1.533059e-43.

I have tried changing the tolerance level to 1e-100 but this does not help.

What can I do to avoid the error when my integral is close to zero?

Aside: It is interesting that the initial values for all of my parameters is 1. Is this to be expected? I have init=0 in my code.

1 Like
1 Like

Do you know what the smallest positive real number is in Stan? Is there a built-in function to obtain it?

That’d be a question for @andrjohns, @Bob_Carpenter or @wds15. I would have guessed it is limited by boost. My understanding is that anything smaller than 1E-16 will be much too small, but I could be horribly wrong.

1 Like

1e-16 is about the machine double precision.

Anyway…what about other random inits to start the chain?

Things cannot be evaluated with an infinite precision…and requiring such extreme precision is a hint that one should rescale the problem in many cases.

2 Likes

1e-16 (roughly) is the relative precision. I don’t think there’s anything stopping you from computing 1e-100+1e-100.

2 Likes

Great idea! I sampled some initial values from my prior distributions and the code runs now.