loo_moment_match fails if new log likelihood is -Inf
avehtari opened this issue · 0 comments
I had seen the same issue in some of my models, but started to investigate after JackL posted a simple example in Stan discourse
https://discourse.mc-stan.org/t/error-when-adding-looic-to-a-zero-one-inflated-beta-regression-model-in-brms/34337
The problem arises when log_liki_new
and log_prob_new
both evaluate as -Inf, and the log ratio contains -log_liki_new + log_prob_new
and -Inf + Inf returns NaN. The similar computation can happen in split moment matching.
In these cases, it would be fine that we reject the problematic evaluation in the same way as Stan would reject it during sampling. In importance sampling we can do rejection by making the weight to be 0, which me can make by making the log ratio -Inf (thus we now compute -Inf + Inf is -Inf). We can safely allow -Infs in our importance sampling algorithms.