This function computes the softmax of a numeric vector. The softmax function transforms a vector of real values into a probability distribution, where each element is between 0 and 1 and the sum of all elements is 1. @seealso DNN_predictor

af.softmax(x)

Arguments

x

A numeric vector for which the softmax transformation is to be computed.

Value

A numeric vector representing the softmax-transformed values of x.

Details

The softmax function is calculated as: $$softmax(x_i) = \frac{exp(x_i)}{\sum_{j} exp(x_j)}$$ In the case of overflow (i.e., when exp(x_i) is too large), this function handles Inf values by assigning 1 to the corresponding positions and 0 to the others before Softmax. @seealso DNN_predictor

Examples

x <- c(1, 2, 3)
af.softmax(x)
#> [1] 0.09003057 0.24472847 0.66524096