smoothmax
result = smoothmax(x, beta=1)
Input: x, beta · Output: result
What it is
Smooth (differentiable) approximation to max(x): (1/beta) * logsumexp(beta * x), which tracks the true maximum more tightly as beta grows (at the cost of a stiffer gradient). x is a scalar, Vec, or Mat/Signal, flattened; beta is an optional positional scalar defaulting to 1 (a non-positive or non-finite beta falls back to the plain hard max).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = smoothmax(x, beta=1) | x scalar, Vec, Mat, or Signalx is a scalar, Vec, or Mat/Signal, flattened.beta scalar (default 1)beta is an optional positional scalar defaulting to 1 (a non-positive or non-finite beta falls back to the plain hard max). | result scalar or Num | Returns a scalar Num. |
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