logsumexp-softmax-tests swMATH ID: 42124 Software Authors: Blanchard, Pierre; Higham, Desmond J.; Higham, Nicholas J. Description: Accurately computing the log-sum-exp and softmax functions. Evaluating the log-sum-exp function or the softmax function is a key step in many modern data science algorithms, notably in inference and classification. Because of the exponentials that these functions contain, the evaluation is prone to overflow and underflow, especially in low-precision arithmetic. Software implementations commonly use alternative formulas that avoid overflow and reduce the chance of harmful underflow, employing a shift or another rewriting. Although mathematically equivalent, these variants behave differently in floating-point arithmetic and shifting can introduce subtractive cancellation. We give rounding error analyses of different evaluation algorithms and interpret the error bounds using condition numbers for the functions. We conclude, based on the analysis and numerical experiments, that the shifted formulas are of similar accuracy to the unshifted ones, so can safely be used, but that a division-free variant of softmax can suffer from loss of accuracy. Homepage: https://academic.oup.com/imajna/article/41/4/2311/5893596?login=false Source Code: https://github.com/higham/logsumexp-softmax-tests Dependencies: Matlab Keywords: log-sum-exp; softmax; floating-point arithmetic; rounding error analysis; overflow; underflow; condition number Related Software: SciPy; FEniCS; trlib; FFC; UFC; UFL; GQTPAR; SyFi; DOLFIN; FIAT; PRMLT; MNIST; R; Matlab Cited in: 6 Publications Standard Articles 1 Publication describing the Software, including 1 Publication in zbMATH Year Accurately computing the log-sum-exp and softmax functions. Zbl 07528305Blanchard, Pierre; Higham, Desmond J.; Higham, Nicholas J. 2021 all top 5 Cited by 15 Authors 1 Anikin, Anton S. 1 Blanchard, Pierre 1 Geiger, Tobias 1 Higham, Desmond J. 1 Higham, Nicholas J. 1 Matyukhin, V. V. 1 Matyukhin, Vladislav 1 Milz, Johannes 1 Pasechnyuk, D. A. 1 Pasechnyuk, Dmitry 1 Reisinger, Christoph 1 Ulbrich, Michael 1 Wachsmuth, Daniel 1 Wachsmuth, Gerd 1 Zhang, Yufei Cited in 4 Serials 2 SIAM Journal on Control and Optimization 1 IMA Journal of Numerical Analysis 1 Computational Mathematics and Mathematical Physics 1 Mathematical Control and Related Fields Cited in 5 Fields 3 Operations research, mathematical programming (90-XX) 2 Numerical analysis (65-XX) 1 Ordinary differential equations (34-XX) 1 Calculus of variations and optimal control; optimization (49-XX) 1 Systems theory; control (93-XX) Citations by Year