softmax: Softmax Function

Description Usage Arguments Details Value Examples

View source: R/utility_functions.R

Description

A generalization of the logistic function 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

1

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

1
2
3
4
5
6
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/utilityf documentation built on March 1, 2021, 7:05 p.m.