Learn R Programming

ohenery (version 0.1.3)

smax: The softmax function.

Description

The softmax function: exponentiate a vector and then normalize.

Usage

smax(eta, g = NULL)

Value

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

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.

Author

Steven E. Pav shabbychef@gmail.com

Details

Given vector \(\eta\) for a single group, essentially computes vector \(\mu\) defined by $$\mu_i = \frac{\exp{\eta_i}}{\sum_j \exp{\eta_j}}.$$

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

See Also

normalize, inv_smax.

Examples

Run this code
# we can deal with large values:
set.seed(2345)
eta <- rnorm(12,sd=1000)
smax(eta)

Run the code above in your browser using DataLab