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
. The naïve formula overflows at moderate values —
subtract before the exponential:
.
Use NumPy (np.max, np.exp, np.log, np.sum).