Learn R Programming

utilities (version 0.4.0)

softmax: Softmax and inverse-softmax functions

Description

softmax returns the value of the softmax function. softmaxinv returns the value of the inverse-softmax function.

Usage

softmax(eta, lambda = 1, gradient = FALSE, hessian = FALSE)

softmaxinv(p, lambda = 1, gradient = FALSE, hessian = FALSE)

Arguments

eta

A numeric vector input

lambda

Tuning parameter (a single positive value)

gradient

Logical; if TRUE the output will include a 'gradient' attribute

hessian

Logical; if TRUE the output will include a 'hessian' attribute

p

A probability vector (i.e., numeric vector of non-negative values that sum to one)

Value

Value of the softmax function

Details

The softmax function is a bijective function that maps a real vector with length m-1 to a probability vector with length m with all non-zero probabilities. The softmax function is useful in a wide range of probability and statistical applications. The present functions define the softmax function and its inverse, both with a tuning parameter.

Examples

Run this code
# NOT RUN {
softmax(5:7)
softmaxinv(softmax(5:7))
# }

Run the code above in your browser using DataLab