softmax: Softmax Function

View source: R/S02_Math.R

softmaxR Documentation

Softmax Function

Description

A generalization of the logistic function that takes a K-dimensional vector of arbitrary values and converts it to a K-dimensional vector of real values in the range (0,1) that sum to 1. The function is also known as the normalized exponential.

Usage

softmax(x)

Arguments

x

A vector of values from -Inf to Inf.

Details

The function can take either a vector or a matrix of values. If a matrix is passed in, the function is applied to each row of the matrix.

Value

A vector of values from 0 to 1 that sum to 1.

Examples

set.seed(3902)
ex <- softmax(rnorm(5))
sum(ex) # Should equal 1
mat <- matrix(rnorm(9), 3, 3)
ex <- softmax(mat)
rowSums(ex) # Each row should sum to 1

rettopnivek/arfpam documentation built on Oct. 20, 2024, 7:24 p.m.