R/eln.R

Defines functions elnproduct elnsum logsumexp

Documented in elnproduct elnsum logsumexp

logsumexp <- function(exponents.vec){
  m <- max(exponents.vec)
  m + log(sum(exp(exponents.vec-m)))
}

elnsum <- function(elnx, elny){
  ifelse(
    elnx == -Inf, elny, 
  ifelse(
    elny == -Inf, elnx,
  ifelse(
    elny < elnx,
    elnx + log(1+exp(elny-elnx)),
    elny + log(1+exp(elnx-elny)))))
}

elnproduct <- function(elnx, elny){
  ifelse(
    elnx == -Inf | elny == -Inf,
    -Inf,
    elnx+elny)
}

Try the plotHMM package in your browser

Any scripts or data that you put into this service are public.

plotHMM documentation built on Sept. 8, 2023, 5:47 p.m.