Forward-Backward functions
Scaled probabilities
HMMGradients.forward
— Functionalpha, 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 Nt2
≥ Nt
).
Returns:
alpha
a matrix of size(Nt,Ns)
containing the forward probabilitiesc
aNt
-long vector containing the normalization coefficients which can be used to compute the backward probabilities (seebackward
) 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.
HMMGradients.forward!
— Functionforward!(alpha,c,Nt,a,A,y)
In-place version of forward
.
HMMGradients.backward
— Functionbackward(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 Nt2
≥ Nt
).
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
.
HMMGradients.backward!
— Functionbackward!(beta,Nt,A,c,y)
In-place version of backward
.
backward!(beta,Nt,A,c,t2tr,y)
In-place version backward
with constrined path.
HMMGradients.posterior
— Functionposterior(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
.
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
.
Log-probabilities
HMMGradients.logforward
— Functionlogalpha, 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 Nt2
≥ Nt
).
Returns:
logalpha
a matrix of size(Nt,Ns)
containing the forward log-probabilitieslogML
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
).
HMMGradients.logforward!
— Functionlogforward!(logalpha,Nt,a,A,y)
In-place version of logforward
.
HMMGradients.logbackward
— Functionlogbackward(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 Nt2
≥ Nt
).
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
.
HMMGradients.logbackward!
— Functionlogbackward!(logbeta,Nt,A,y)
In-place version of logbackward
.
HMMGradients.logposterior
— Functionlogposterior(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
.
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
.