I wonder when “sum” function returns nan or -nan value.
Would anyone mind letting me know a specific page in stan manual, if exists?
I’m heading to this occasional error message, so asking this question.
" Exception: multinomial_rng: Probabilites parameter is not a valid simplex. sum(Probabilites parameter) = -nan, but should be 1
Thanks in advance.
I don’t think there is a specific page about it in the Stan manual, but it means that one or more of the elements of the vector being summed are
NaN (or that one is positive infinity and the other is negative infinity, but that should not be happening with a simplex).
Hi Ben, I’m sorry to call you like this way, but do you have any idea to handle this precision problem? This is not a problem in rstan, so I didn’t post it in this website. However, if you don’t mind, I’d like to hear your valuable opinions.
There’s actually a description of floating point arithmetic and NaN behavior in the basic arithmetic part at the beginning of the reference manual (section 3.2, “primitive numerical data types”).
Ben answered the stack overflow problem on stack overflow—the answer is that you needed log-sum-exp to avoid the overflow. That’s built into Stan’s softmax function, for example.