Learn R Programming

mclust (version 6.1)

logsumexp: Log sum of exponentials

Description

Efficient implementation (via Fortran) of the log-sum-exp function.

Usage

logsumexp(x, v = NULL)

Value

Returns a vector of values of length equal to the number of rows of x.

Arguments

x

a matrix of dimension \(n \times k\) of numerical values. If a vector is provided, it is converted to a single-row matrix.

v

an optional vector of length \(k\) of numerical values to be added to each row of x matrix. If not provided, a vector of zeros is used.

Author

Luca Scrucca

Details

Given the matrix x, for each row \(x_{[i]} = [x_1, \dots, x_k]\) (with \(i=1,\dots,n\)), the log-sum-exp (LSE) function calculates $$ \text{LSE}(x_{[i]}) = \log \sum_{j=1}^k \exp(x_j + v_j) = m + \log \sum_{j=1}^k \exp(x_j + v_j - m) $$ where \(m = \max(x_1+v_1, \dots, x_k+v_k)\).

See Also

softmax

Examples

Run this code
x = matrix(rnorm(15), 5, 3)
v = log(c(0.5, 0.3, 0.2))
logsumexp(x, v)

Run the code above in your browser using DataLab