Skip to contents

Numerically stable softmax function

Usage

softmax(x)

Arguments

x

Numeric. A vector of reals to map to probabilities.

Examples

softmax(1:3)
#> [1] 0.09003057 0.24472847 0.66524096
softmax(1:3 + 9999999)
#> [1] 0.09003057 0.24472847 0.66524096
softmax(c(12345, 67890, 99999999))
#> [1] 0 0 1