1

I'm working with linear interpolation, where I have to calculate:
p' = \lambda_1*p_1 + \lambda_2*p_2 + \lambda_3*p_3.

However, p_1, p_2, and p_3 are joint probabilities, and thus cannot be expressed as a float due to underflow. So I work in the log space, taking log2(p_1),log2(p_2), and log2(p_3).

Given the logs of the probabilities, I'm not too sure how to calculate p' or log2(p'). I can also calculate log2(p_1* \lambda_1), etc if necessary.

1 Answers1

0

The usual approach is to find the largest of the terms, and compute the sum as that times a correction. In more detail

q[i] = log( lambda[i]) + log( p[i])) i = 1..
we want Q = log( exp( q[1]) + exp(q[2]) + .. )
let the largest q[i] be q[j], then we get 
Q = log( ( exp( q[1]-q[j]) + exp( q[1]-q[j]) + ..) * exp(q[j]))
  = q[j] + log( exp( q[1]-q[j]) + exp( q[1]-q[j]) + ..)

In evaluating the second term, all the q[i]-q[j] are negative so overflow can't occur. If any are so negative that underflow occurs just ignore it, because one of the terms ( exp( q[j]-q[j]) ) will be one.

dmuir
  • 4,211
  • 2
  • 14
  • 12