Skip to content
BIASED

Stable log-sum-exp

Self-study exercise. Checking on the site is not available yet. Write and download a solution to work on your computer.

Finish logsumexp(x) for a 1-D array of logits: return log⁡∑iexi\log\sum_i e^{x_i}. The naïve formula overflows at moderate values — subtract m=max⁡ixim = \max_i x_i before the exponential: m+log⁡∑iexi−mm + \log\sum_i e^{x_i - m}.

Use NumPy (np.max, np.exp, np.log, np.sum).

Conditioning and numerical stability