Learn R Programming

plotHMM (version 2023.8.28)

eln: Log probability arithmetic

Description

Binary operators in log probability space, to avoid numerical underflow.

Usage

elnproduct(elnx, elny)
elnsum(elnx, elny)
logsumexp(exponents.vec)

Value

Numeric vector with one (logsumexp) or more (others) log probability value(s).

Arguments

elnx, elny, exponents.vec

numeric vectors of log probabilities.

Author

Toby Dylan Hocking

References

http://bozeman.genome.washington.edu/compbio/mbt599_2006/hmm_scaling_revised.pdf

Examples

Run this code

px <- c(0.1, 0.5, 0.9)
py <- c(0.001, 0.123, 0.999)
lx <- log(px)
ly <- log(py)
library(plotHMM)
elnproduct(lx, ly)
elnsum(lx, ly)
logsumexp(ly)

Run the code above in your browser using DataLab