softmax: softmax

softmaxR Documentation

softmax

Description

uses logsumexp trick to prevent numerical overflow

Usage

softmax(x)

Arguments

x

a vector of numbers

Value

a vector of positive values that sum to one.

Examples


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


zhenkewu/baker documentation built on Feb. 7, 2024, 4:20 p.m.