Computing average log-likelihood without taking exponents
이전 댓글 표시
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)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Exponents and Logarithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!