softmax {covalchemy} | R Documentation |
Softmax Function with Special Handling for Infinite Values
Description
This function computes the softmax of a vector x
, with special handling for infinite values.
The softmax function transforms input values into a probability distribution by exponentiating
each value, then normalizing by the sum of all exponentiated values.
The function ensures numerical stability, particularly when dealing with very large or very small values,
and handles cases where the values are infinite (Inf
).
Usage
softmax(x)
Arguments
x |
A numeric vector for which the softmax function will be calculated. |
Value
A numeric vector of the same length as x
, where the values represent probabilities summing to 1.
Examples
softmax(c(10, 5, 2))
softmax(c(Inf, -Inf, 0))
softmax(c(-Inf, -Inf, -Inf))
[Package covalchemy version 1.0.0 Index]