IssamLaradji/scikit-learn — pull request #1 by AlexanderFabisch (2013-12-29 20:22:17+00:00)
Title: Numerically stable softmax

This version of softmax does not return `nan`s for outputs greater than 709, e.g.

Z = array([[1, 2, 3], [1, 709, 3], [2, 710, 4]], dtype=float64)
print _softmax(Z)

>>>> [[ 9.00305732e-002 2.44728471e-001 6.65240956e-001]
[ 3.30755300e-308 1.00000000e+000 2.44396947e-307]
[ 3.30755300e-308 1.00000000e+000 2.44396947e-307]]

The previous version returned

>>>> [[ 9.00305732e-002 2.44728471e-001 6.65240956e-001]
[ 3.30755300e-308 1.00000000e+000 2.44396947e-307]
[ 0.00000000e+000 nan 0.00000000e+000]]