Utilities¶

maxstar(x, w, dim)[source]

Log of a sum of exponentials. For vectors, maxstar(x) is equivalent to log(sum(exp(x))). For matrices, maxstar(x) is a row vector and maxstar operates on each column of x. For N-D arrays, maxstar(x) operates along the first non-singleton dimension.

maxstar(x,w) is the log of a weighted sum of exponentials, equivalent to log(sum(w.*exp(x))). Vectors w and x must be the same length. For matrix x, the weights w can be input as a matrix the same size as x, or as a vector of the same length as columns of x. Weights may be zero or negative, but the result sum(w.*exp(x)) must be greater than zero.

maxstar(x, [], dim) operates along the dimension dim, and has the same dimensions as the MATLAB function max(x, [], dim).

Usage

y = maxstar(x, w, dim)

Inputs

• x
• w
• dim

Output

• y

Note

The max* function is described in Lin & Costello, Error Control Coding, 2nd Edition, equation 12.127, in the two-argument form max*(x1, x2) = max(x1, x2) + log(1 + exp(-abs(x1-x2))). The function max* can be applied iteratively: max*(x1, x2, x3) = max*(max*(x1, x2), x3). Functions max(x) ~ max*(x), and min(x) ~ -max*(-x).

Algorithm: The double precision MATLAB expresson log(sum(exp(x))) fails if all(x < -745), or if any(x > 706). This is avoided using m = max(x) in max*(x) = m + log(sum(exp(x - m))).

Example

% If
x = [2 8 4 7 3 9]
% then
maxstar(x, [], 1)
% is [7.0067 8.0067 9.0067],
% and
maxstar(x, [], 2)
% is [8.0206 9.1291].