normalized.exponential: Normalized exponential of a vector

Description Usage Arguments Details Value

Description

Compute exp(x)/sum(exp(x)) in a numerically stable way

Usage

1

Arguments

x

Vector

Details

Computing exp(x)/sum(exp(x)) can lead to numerical instability if some of the components of x are very large or very small. This procedure recenters by the median to ensure a bit more stability. It is not bullet-proof but is sufficient for practical cases.

The computation of the median of a vector takes O(N log N), whereas taking the mean takes O(N). The mean can thus be used instead of the median if this function turns out to be a bottleneck, but the median is more robust to the few extreme components that typically cause numerical instability.

Value

exp(x)/sum(exp(x))


nickpoison/nltsa documentation built on May 23, 2019, 4:48 p.m.