forward_backward: Forward-backward algorithm

Description Usage Arguments Value

View source: R/RcppExports.R

Description

Forward-backward algorithm using the scaling technique. That's more stable (and maybe even faster) than the method with the logarithm. Warning: this function overwrites the lliks matrix.

Usage

1
forward_backward(initP, trans, lliks, seqlens, posteriors, nthreads = 1L)

Arguments

initP

matrix of initial probabilities: each column corresponds to a sequence

trans

transition matrix (rows are previous state, columns are next state)

lliks

matrix with emission probabilities for each datapoint and each state. Columns are datapoints and rows are states.

seqlens

length of each subsequence of datapoints (set this to ncol(lliks) if there is only one sequence).

posteriors

the posteriors matrix where the posteriors will be written. its value when the function is called does not matter, but it needs to have the right dimensions (rows are states and columns are observations).

nthreads

number of threads used. Sequences of observations are processed independently by different threads (if length(seqlens) > 1).

Value

a list with the following arguments:

posteriors

posterior probability of being in a certain state for a certain datapoint. Same matrix used as input argument.

tot_llik

total log-likelihood of the data given the hmm model.

new_trans

update for the transition probabilities (it is already normalized).


lamortenera/kfoots documentation built on May 20, 2019, 7:34 p.m.