The incremental log-sum-exp trick

less than 1 minute read

Often in machine learning it is necessary to compute the following quantity. We have a -dimensional vector —usually log-probabilities— and we want to calculate:

Calculating the quantity in a naive manner we can encounter underflows or overflows. For an arbitrary , we can shift the center of the exponential sum in the following way:

A typical value for is setting it to the maximum, , thus forcing the greatest value to be zero.

However, if the values are available in an incremental way we cannot compute the maximum value. The alternative incremental log-sum-exp trick can be computed using the following recurrence:

hence, for each , if then:

otherwise,

Updated: