stabilize calculation of log-likelihood to avoid -inf