Log probabilities

Problem

Sometimes we need to sum two probabilities that are in log-space. If we let and be the two log probabilities then the straight-forward method to compute the sum of the probabilities in log-space, , would be

\[ p = \log (e^a + e^b). \]

This can result in numerical instability (underflow) when or are large and negative.

Show that another way to compute is given by

\[ p = \max\{a, b\} + \log (1 + e^{-|a - b|}). \]

The function can be computed efficiently and precisely in C++ with log1p.

Solution

show