Function easy_ml::linear_algebra::softmax

source ·
pub fn softmax<I, T: Numeric + Real>(data: I) -> Vec<T>
where I: Iterator<Item = T>,
Expand description

Computes the softmax of the values in an iterator, consuming the iterator.

softmax(z)[i] = ezi / the sum of ezj for all j where z is a list of elements

Softmax normalises an input of numbers into a probability distribution, such that they will sum to 1. This is often used to make a neural network output a single number.

The implementation shifts the inputs by the maximum value in the iterator, to make numerical overflow less of a problem. As per the definition of softmax, softmax(z) = softmax(z-max(z)).

Further information

§Panics

If the iterator contains NaN values, or any value for which PartialOrd fails.

This function will also fail if the length of the iterator or sum of all the values in the iterator exceeds the maximum or minimum number the type can represent.