powered by
uses logsumexp trick to prevent numerical overflow
softmax(x)
a vector of positive values that sum to one.
a vector of numbers
softmax2 <- function(x) exp(x) / sum(exp(x)) softmax(c(1, 2, 3) * 1000) # NaN NaN NaN softmax2(c(1, 2, 3) * 1000) # 0 0 1
Run the code above in your browser using DataLab