logsumexp
result = lse(x)
Input: x · Output: result
What it is
Numerically stable log(sum(exp(x))), via the usual max-shift so a large input can't overflow exp. x is a scalar, Vec, or Mat/Signal, flattened.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = lse(x) | x scalar, Vec, Mat, or Signalnot documented yet | result scalar or Num | Returns a scalar Num — -inf for an empty x. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
crest(x) := max(abs(x)) / rms(x)
xs = [0, 1, 2, 3]
print("hard max = {max(xs)}")
print("logsumexp = {logsumexp(xs):.4f}") # >= hard max, a proven upper bound
print("smoothmax b=50 = {smoothmax(xs, 50):.4f}") # -> hard max as beta grows
print("softmax = {softmax(xs)}") # the gradient of logsumexp
output
hard max = 3 logsumexp = 3.4402 smoothmax b=50 = 3.0000 softmax = [0.032059, 0.087144, 0.236883, 0.643914]
from numerics-dsp
How it works
smooth-max family: logsumexp(x), smoothmax(x[, beta]), softmax(x).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
lse — documented in the same entry.