Computing average log-likelihood without taking exponents

1 view (last 30 days)
I am trying to compute the average log-likelihood where the likelihoods (probabilities) are very close to zero. I currently do so using:
mean_loglik = log(mean(exp(loglik)));
where loglik is a column vector of log-likelihoods. Doing so, all likelihoods (exp(loglik)) are rounded to zero, quashing the information because:
log(mean(zeros(size(loglik))))==-Inf
happens when taking the exponents. I have tried:
mean_loglik = log(mean(exp(loglik)));
dex = 1;
while (isfinite(mean_loglike)==0);
mean_loglik = log(mean(exp(loglik + dex * log(10^200)))) - dex * log(10^200);
dex=dex+1;
end% while
This essentially "multiplies" the likelihoods by some huge number, then "divides" them by such a number, doing so in the log stage rather than once exponentiated.
There are few problems with this. (1) It can get caught in infinite loop; (2) limiting the loop (e.g. adding && (dex<200)) might not solve the original issue; (3) this can be computationally very slow.
I have also tried to get the algebra to simplify using log rules, but haven't found an appropriate transformation. Is there some matlab function (or mathematical transformation) to solve or avoid this problem?
Example Code:
loglik = unifrnd(-1e100,-1e97,1000,1);
mean_loglik = log(mean(exp(loglik)));
dex=1;
while (isfinite(mean_loglik)==0) && (dex<2000);
mean_loglik = log(mean(exp(loglik + dex * log(10^200)))) - dex * log(10^200);
dex = dex+1;
end% while
isfinite(mean_loglik)

Accepted Answer

Michael Thacker
Michael Thacker on 2 Sep 2015
Edited: Michael Thacker on 2 Sep 2015
To solve this problem, I have opted to use the technique described in the question, but do so in a way that does not loop. Rather than adding some "large" number, I simply normalize each so that the largest number (least negative log-likelihood) is normalized to zero to take the exponent, then reverse it after I take the mean.
See code below:
loglik = unifrnd(-1e100,-1e97,1000,1);
mean_loglik = log(mean(exp(loglik - max(loglik)))) + max(loglik);
end% while
isfinite(mean_loglik)
Note that loglik has all negative values. Anything still rounded to zero is VERY nearly zero when we take the mean and should not impact the overall outputs in my application.

More Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!