Forward-Backward functions

Scaled probabilities

HMMGradients.forwardFunction

alpha, c = forward(Nt,a,A,y)

Computes the scaled forward probabilities ($\bar{\alpha}$) of an Hidden Markov Model (HMM) of Ns states with transition matrix A (must be a Ns × Ns matrix), initial probabilities a (must be a Ns-long vector) and observation likelihoods y (must be of size Nt2 × Ns with Nt2Nt).

Returns:

  • alpha a matrix of size (Nt,Ns) containing the forward probabilities
  • c a Nt-long vector containing the normalization coefficients which can be used to compute the backward probabilities (see backward) and the log maximum likelihood (sum(log.(c))).

alpha, c = forward(Nt,t2tr,A,y)

Here t2tr can be an Nt-1 vector of Pair{Vector{D},Vector{D}}. For example given Nt=3:

t2tr = [[1,1]=>[1,2],[1,2]=>[3,3],[3]=>[4]]

indicates that at time t=1 transitions from state 1 to 1 and from 1 to 2 are allowed. At time t=2 transitions from state 1 to 3 and from 2 to 3 are allowed. At time t=3 only the transition from state 3 to 4 is allowed. In practice these indices can be used to construct the (possibly sparse) time-dependent transition matrices described in the theory section.

source
HMMGradients.backwardFunction

backward(Nt,A,c,y)

Computes the scaled backward probabilities ($\bar{\beta}$) of an Hidden Markov Model (HMM) of Ns states with transition matrix A (must be a Ns × Ns matrix), scale coefficients c (must be a Nt-long vector which is produced by forward) and observation likelihoods y (must be of size Nt2 × Ns with Nt2Nt).

source

backward(Nt,A,c,t2tr,y)

Computes the scaled backward probabilities with constrained path indicated by the t2tr vector. See forward for a description of the structure and meaning of t2tr.

source
HMMGradients.posteriorFunction

posterior(Nt,a,A,y)

Computes the state posterior probabilities ($\gamma$) for an HMM model with initial probability a, transition probability matrix A and observation likelihoods y.

source

posterior(Nt,t2tr,A,y)

Computes the state posterior probabilities ($\gamma$) for an HMM model with constrained path t2tr (see forward), transition probability matrix A and observation likelihoods y.

source

Log-probabilities

HMMGradients.logforwardFunction

logalpha, logML = logforward(Nt,a,A,y)

Computes the scaled forward log-probabilities ($\hat{\alpha}$) of an Hidden Markov Model (HMM) of Ns states with log-transition matrix A (must be a Ns × Ns matrix), initial log-probabilities a (must be a Ns-long vector) and observation log-likelihoods y (must be of size Nt2 × Ns with Nt2Nt).

Returns:

  • logalpha a matrix of size (Nt,Ns) containing the forward log-probabilities
  • logML the log likelihood of the observation normalized by the sequence length, i.e. $\log(P(\mathbf{X}))/N_t$.

logalpha, logML = logforward(Nt,t2tr,A,y)

Returns the forward log-probabilities with a constrained path (see forward).

source
HMMGradients.logbackwardFunction

logbackward(Nt,A,y)

Computes the backward log-probabilities ($\hat{\beta}$) of an Hidden Markov Model (HMM) of Ns states with log-transition matrix A (must be a Ns × Ns matrix), scale coefficients and observation log-likelihoods y (must be of size Nt2 × Ns with Nt2Nt).

source

logbackward(Nt,A,t2tr,y)

Computes the backward log-probabilities with constrained path indicated by the t2tr vector. See forward for a description of the structure and meaning of t2tr.

source
HMMGradients.logposteriorFunction

logposterior(Nt,a,A,y)

Computes the state posterior log-probabilities ($\hat{\gamma}$) for an HMM model with initial probability a, transition probability matrix A and observation likelihoods y.

source

logposterior(Nt,t2tr,A,y)

Computes the state posterior log-probabilities ($\hat{\gamma}$) for an HMM model with constrained path t2tr (see forward), transition probability matrix A and observation likelihoods y.

source