optimize naive bayes classifier caching the log-likelihood denominator