doing multiplication by adding logarithms---is zero the identity element?

2k views Asked by At

Conceptually, I need to multiply the probabilities of each event in a coincidence. Since there may be very many events involved, I have the computer add the logarithms to avoid underflow.

But suddenly I can't convince myself that I should initialize the return value to zero before I start adding. I know zero is the identity element for addition, and I remember this is how I do it, but, looking at a graph of the logarithm, I can clearly see that the antilog of zero is negative infinity.

So initializing the return value to zero should be equivalent to multiplying all my probabilities by negative infinity, which is definitely not correct. What am I doing wrong?

3

There are 3 answers

5
Michael J. Barber On BEST ANSWER

The antilog of zero is one, not negative infinity. That means that starting adding with zero for the logarithm is the same as starting multiplying with one for the probabilities themselves.

2
duffymo On

If you are multiplying values together, they look like this:

product = 1*p1*....*pn

If you take the natural log of both sides it looks like this:

ln(product) = ln(1) + ln(p1) + .... + ln(pn)

But ln(1) = 0, so that's how you initialize the sum of logarithms. Set it to zero.

Remember what you're summing here: the log of each probability adds into the log of the total probability. Once you complete the sum, you can get the product like this:

product = exp(ln(product)) = exp(ln(sum of ln(pn))
1
Ricardo Marimon On

If you are calculating the intersection of events. Just multiply them. No need to take into logarithmic space. If it gets really really small then is zero probability for the intersection of events.