问题
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