Skip to content

Instantly share code, notes, and snippets.

@brainprint
Forked from aufrank/softmax.R
Created November 17, 2016 20:46
Show Gist options
  • Save brainprint/bd5bc8cff319b74ff5545e513b16de4f to your computer and use it in GitHub Desktop.
Save brainprint/bd5bc8cff319b74ff5545e513b16de4f to your computer and use it in GitHub Desktop.
## from http://tr.im/hH5A
logsumexp <- function (x) {
y = max(x)
y + log(sum(exp(x - y)))
}
softmax <- function (x) {
exp(x - logsumexp(x))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment