I need to evaluate a sum of values that are on many different orders of magnitude in scale but might be signed. I’ve had great luck with the “log-sum-exp” trick for an unsigned version of my problem, so I’m hoping to apply this to the signed values.
Suppose $z,z’\in\mathbb C$ are stored using separate real and imaginary parts in double precision. We wish to compute $w:=\log(e^z + e^{z’})$. Here I’m not concerned about which branch of log we get back—at the end of the day only $e^w$ matters, the logs are just for numerical stability.
For any $a\in\mathbb C$, by an identical argument to the log-sum-exp trick we know $$W=a+\log(e^{z-a}+ e^{z’-a}),$$ again up to branch of log.
Is there a good “policy” for choosing $a$ to promote numerical stability, similar to the max suggested for the real valued log-sum-exp trick?
log1p
here to get some stability for inputs of wildly different size. $\endgroup$