smax: The softmax function.

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/utils.r

Description

The softmax function: exponentiate a vector and then normalize.

Usage

1
smax(eta, g = NULL)

Arguments

eta

numeric array of the odds. The odds are de-meaned within each group.

g

a vector giving the group indices. If NULL, then we assume only one group is in consideration.

Details

Given vector η for a single group, essentially computes vector μ defined by

μ_i = \frac{\exp{η_i}}{∑_j \exp{η_j}}.

Note that this computation should be invariant with respect to level shifts of the η, and thus we de-mean the odds first.

Value

the exponentiated data normalized. For the row-wise version, each row is soft maxed.

Note

This function can deal with overflow in a semi-coherent way.

Author(s)

Steven E. Pav shabbychef@gmail.com

See Also

normalize, inv_smax.

Examples

1
2
3
4
# we can deal with large values:
set.seed(2345)
eta <- rnorm(12,sd=1000)
smax(eta)

ohenery documentation built on Oct. 30, 2019, 9:53 a.m.