Numerical stability of GPs with negative binomial likelihood

Yeah I’ve had lots of problems (not just when doing a GP) with neg_binomial_2_log_rng during warmup because the (log) mean parameter can get way too large. You could try something like this:

  int neg_binomial_2_log_safe_rng(real eta, real phi) {
    real gamma_rate = gamma_rng(phi, phi / exp(eta));
    if (gamma_rate > exp(20.7)) gamma_rate = exp(20.7); // i think this is the max value before overflow but haven't double checked
    return poisson_rng(gamma_rate);
  }
5 Likes