Skip to content

Instantly share code, notes, and snippets.

@DeoluA
Forked from aufrank/softmax.R
Created June 12, 2017 20:48
Show Gist options
  • Save DeoluA/4461c9d6de3655abefa23208dbad0329 to your computer and use it in GitHub Desktop.
Save DeoluA/4461c9d6de3655abefa23208dbad0329 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