Utilities

logmod(x, base, signed)[source]

Log modulus function, signed by default

Returns a smooth, sign-preserving logarithm sign(x) .* log(1 + abs(x)), which behaves like a logarithm for large magnitudes but is defined at zero.

USAGE:

y = logmod (x, base, signed)

INPUTS:

xn x 1 real vector

OPTIONAL INPUTS:
  • base – logarithm base, one of exp(1), 2 or 10 (default: exp(1))

  • signed – when 1 (default) return a signed y; when 0 return the unsigned log modulus

OUTPUTS:

yn x 1 log modulus of x

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].