softmax: The Softmax

View source: R/softmax.R

softmaxR Documentation

The Softmax

Description

Applies the softmax to a vector or each record of a matrix.

Usage

softmax(x)

Arguments

x

Numeric vector or matrix. If vector, then the softmax of the vector will be returned. If matrix, then the softmax will be applied independently to each record (and a matrix returned).

Details

Returns a vector or matrix whose elements (if vector) or records (if matrix) are computed as exp⁠(x)/⁠sum(exp⁠(x))⁠. The softmax converts a vector or matrix record into a set of proportions which sum to one. If a matrix is provided for the x argument, then the softmax is applied independently for each record.

Value

A numeric vector or matrix whose elements (if vector) or records (if matrix) sum to one.

See Also

normalize for vector or matrix normalization.

Examples

# Perform softmax on vector.
softmax(x=c(-0.25,0.75,1.5,0))

LocaTT documentation built on June 14, 2026, 1:06 a.m.