21
HMM Models of Alignment HMM Models of Alignment

HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

HMM Models of Alignment

HMM Models of Alignment

Page 2: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Motivations

As you may have noticed, the dynamic programming algorithm forfinding optimal sequence alignments is just equivalent to theViterbi algorithm as we learned it for HMMs.

Implies alignment is equivalent to an HMM.

We can gain insight into different aspects of alignment by lookingat it from this different (HMM) point of view.

Viterbi results are hard to interpret because they give noconfidence values. Recasting this as an HMM would allow us tocompute explicit posterior probabilities for each step of thealignment.

HMM Models of Alignment

Page 3: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Profile HMM

We’ve already seen an HMM model of alignment, namely profileHMMs:

This is a standard, first-order HMM; we index the observationsequence �X n as usual by position ie. Xt But note how the sequencerepresented by the HMM is indexed only implicitly, i.e. each position inthat sequence is represented by a different set of states in the HMM.

HMM Models of Alignment

Page 4: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Profile HMM Computation

If we run a Viterbi (or Forward-Backward calculation) on this profileHMM, what will the actual calculation look like?

draw the basic data structure that stores the state of the Viterbialgorithm during the calculation;

indicate precisely how the different aspects of the problem (i.e.the observation sequence, the HMM states) are represented onthis data structure.

HMM Models of Alignment

Page 5: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Profile HMM Computation Answer

It forms a two-dimensional matrix:

on the vertical dimension we have the set of states of the HMMD1M1I1D2M2I2...DmMmIm.

on the horizontal dimension we have the observation sequenceletters X1X2...Xn.

We fill in the two dimensional matrix by Viterbi (orforward-backward) in the usual way.

Any part of �X n could align to (be emitted by) any part of theHMM, because the deletion and insertion can shift theobservation sequence relative to the HMM sequence.

HMM Models of Alignment

Page 6: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Profile HMM “Moves”

Whether we’re doing Viterbi or forward-backward, we follow ourstandard process.

I.e. consider all possible moves to (from) a given cell, and writethe max (or sum) of those moves in this cell.

Draw the “moves” incoming to each of the possible states in terms ofhow they are represented on the matrix.

HMM Models of Alignment

Page 7: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Profile HMM “Moves” Answer

moves to the M state are “diagonal”, i.e. they advance both theobservation index t and our position in the HMM profile.moves to the I state are horizontal, i.e. the observation indexadvances but the profile index does not.moves to the D state are vertical, i.e. the profile index advancesbut the observation index does not.Since every profile position has exactly one D state, one M state,and one I state, it is convenient to keep one separate matrix justfor the D1,D2, ...Dm states, another matrix for just theM1,M2, ...Mm states, and a third matrix for the I1, I2, ...Im states.Then the vertical coordinate u in each matrix is just the position inthe profile that this coordinate represents.All the moves in the M matrix are diagonal; all the moves in the Dmatrix are vertical; all the moves in the I matrix are horizontal.There are also moves between the matrices, e.g. D → M andvice versa.

HMM Models of Alignment

Page 8: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Where is the Hidden Variable?

For posterior probability calculations, we want to sum p(θt ,�X)over all possible states of the hidden variable, to obtain p(�X).

So far, we’re used to thinking of the set of “all possible states” ofone hidden variable θt as corresponding to a single column ofthis two-dimensional matrix.

Will that work here?

HMM Models of Alignment

Page 9: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Probability Summation with Silent States

Note that in previous HMM matrices we never had “verticalmoves” (i.e. “silent states” that emit nothing) before.

Does this affect how we would calculate the probability of theobservation sequence via the forward-backward algorithm?

if not, why not?

if so, how?

HMM Models of Alignment

Page 10: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Probability Summation with Silent States Answer

When calculating forward and backward probabilities, be verycareful to include emission components only for the M and Istates, not the D states!

The fact that we have silent states (i.e. the D states don’t emitanything), means that one position in the observation sequencecan traverse multiple D states.

The “moves” on the matrix no longer all come from the previouscolumn: moves to D states are “vertical” (i.e. they stay in thesame column).

We can no longer sum p(�X) = θtp(�X ,θt) over the whole

column, because the states are no longer mutually exclusive.E.g. at t = 1 we could traverse states D1 → D2 → D3 → ....

HMM Models of Alignment

Page 11: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

What Are the Hidden Variables?

because of these complications, less obvious exactly what weshould take as our hidden variables.

traditionally, each successive state transition equals one morehidden variable. Concretely, there is uncertainty about what thenext state will be at each step, so each step in the path is ahidden variable forming a chain θ1 → θ2 → θ3 → ...

We could still do that, but note that the “path step index” w has anon-trivial mapping to the observation and profile indexes t,u;specifically w = t +u−NM , where NM is the number of matchstates traversed so far on this path.

More convenient: note that on any given path, one position Xt

can still be emitted by only one M or I state. We can refer to onesuch specific emission as θt = Mu, which means state Mu inobservation column t in the matrix.

HMM Models of Alignment

Page 12: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Total Likelihood Computation

Propose what you think would be the simplest way to compute p(�X)over this matrix structure.

HMM Models of Alignment

Page 13: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Total Likelihood Computation Answer

Best to think of p(�X) as summing over all possible paths acrossthe matrix.

Easiest place to sum it is at the places where all the pathsconverge to a single state, i.e. START or END. i.e.

p(�X) = fn+1,END = b0,START

Also possible to sum over all possible Mu and Iu states that couldemit a specific observation letter Xt :

p(�X) =m

u=1ft,Mu bt,Mu +

m

u=1ft,Iu bt,Iu

HMM Models of Alignment

Page 14: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Posterior Computation

Computing the posterior that a specific state Mu emits a specificletter Xt is just

p(θt = Mu|�X n) =p(θt = Mu,�X t)p(�X n

t+1|θt = Mu)

p(�X n)

=ft,Mu bt,Mu

p(�X n)

HMM Models of Alignment

Page 15: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Forward Computation

Draw the move(s) that must be taken into account for computingthe forward probability ft,Mu (i.e. for aligning letter Xt to profileletter Mu).

Write the corresponding recursion equation for ft,Mu .

HMM Models of Alignment

Page 16: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Forward Computation Answer

The possible moves are all diagonal (because the M stateadvances both t,u), originating from θt−1 = Du−1, Iu−1,Mu−1.

The recursion has the usual forward, transition and emissioncomponents:

ft,Mu =s=D,I,M

ft−1,su−1p(Mu|su−1)p(Xt |Mu)

HMM Models of Alignment

Page 17: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Backward Computation

Draw the move(s) that must be taken into account for computingthe backward probability bt,Mu (i.e. for aligning letter Xt to profileletter Mu).

Write the corresponding recursion equation for bt,Mu .

HMM Models of Alignment

Page 18: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Backward Computation Answer

The possible moves are

Mu → Mu+1 (diagonal);

Mu → Du+1 (vertical);

Mu → Iu (horizontal);

The recursion has to be written carefully, because the details of thetransition and the emission depend on exactly which state we aretransitioning to:

bt,Mu = bt+1,Mu+1p(Mu+1|Mu)p(Xt+1|Mu+1)

+bt+1,Iu p(Iu|Mu)p(Xt+1|Iu)

+bt,Du+1p(Du+1|Mu)

HMM Models of Alignment

Page 19: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

Deletion Posteriors?

What if we want to know the posterior p(Du|�X n) that profileposition u is deleted (doesn’t emit anything)?

Note that this isn’t tied to a specific observation position t ,because any part of �X n could align to any part of the HMM.

We need to know p(Du,�X n). As usual we get this by summation

p(Du,�X n) =n

t=1p(θt = Du,�X t)p(�X n

t+1|θt = Du)

Note that p(�X nt+1|θt = Du) will include a contribution from

p(�X nt+1|θt = Du+1). Transitioning from Du → Du+1 does not

advance t !

HMM Models of Alignment

Page 20: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

What If We Score Every Position the Same?

We could still use our profile HMM, but it seems unnecessarilycomplicated.

We only need a single M state, a single D state, and a single Istate.

But how are we going to track what position in the profilesequence we’re at?

Treat the profile sequence as another observation sequence �Y m

with position index u.

Now we have to track not just index t but also u as we movebetween states.

M increments both t,u; I increments only t ; D increments only u.

HMM Models of Alignment

Page 21: HMM Models of Alignment - UCLA-DOE Institute · Profile HMM We’ve already seen an HMM model of alignment, namely profile HMMs: This is a standard, first-order HMM; we index the

HMM with Two Observation Sequences

Again, any part of �X can align against any part of �Y .

A single state (e.g. M) is represented not by a one dimensionalrow (all possible θt ) but instead by a two dimensional matrix (allpossible θt,u).

Again, best to think of p(�X ,�Y ) as summed over all possible pathsacross the matrices. Again, this summation is easiest to do at theSTART state (i.e. p(�X ,�Y ) = b0,START ).

To get the posterior that Xt ,Yu align, just compute it fromp(θt,u = M,�X ,�Y ).

To get the posterior that Xt is not aligned to �Y , need to sum overall possible positions in Y, i.e. 1− m

u=1 p(θt,u = M,�X ,�Y )

HMM Models of Alignment