Avoiding -inf when calculating Log Likelihood (MATLAB)

混江龙づ霸主 提交于 2020-01-15 23:38:16

问题


When using MATLAB to calculate

Log_likelihood=log((1/1e8)*exp(-0.5*SSR)),

if SSR (i.e. standard squared error) is large (e.g. SSR=1e4) then the exp() becomes zero and the Log_likelihood becomes -inf.

Is there any numerical/mathematical trick that can handle this problem?

Thank You


回答1:


Assuming your log is a natural logarithm:

log(a*exp(b)) = log(a) + log(exp(b)) = log(a) + b.

Where a=(1/1e8), b = -0.5*SSR
Moreover, log(1/1e8) = log(1) - log(1e8), so the above turns to be -log(1e8) + b, while the first term is a constant and can be precalculated.



来源:https://stackoverflow.com/questions/29372670/avoiding-inf-when-calculating-log-likelihood-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!