softmax | R Documentation |
uses logsumexp trick to prevent numerical overflow
softmax(x)
x |
a vector of numbers |
a vector of positive values that sum to one.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.