softmax: Softmax function and its inverse

View source: R/utils.R

softmaxR Documentation

Softmax function and its inverse

Description

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

Usage

softmax(eta, lambda = 1)

softmaxinv(p, lambda = 1, ref_position = length(p), ref_value = 0)

Arguments

eta

A numeric vector input

lambda

Tuning parameter (a single positive value)

p

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

ref_position

The reference position that should be used to calculate the inverse softmax function. The default is the last position.

ref_value

The value the reference position will be set to. The default is 0.

Details

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

The current functions define the softmax as:

\Large P(\eta_i) = \frac{e^{\lambda \eta_i}}{\sum_{j=1}^m e^{\lambda \eta_j}}

Value

Value of the softmax function or its inverse

Examples

softmax(5:7)
softmaxinv(softmax(5:7), ref_position = 1, ref_value = 5)

bmm documentation built on March 30, 2026, 5:08 p.m.