Docsity

Hidden Markov Models: Applications and Algorithms, Study notes of Bioinformatics

Partial preview of the text

Download Hidden Markov Models: Applications and Algorithms and more Study notes Bioinformatics in PDF only on Docsity!

Lecture 7

Hidden Markov Models

Additional Reference

  • Biological Sequence Analysis by R. Durbin,

S. Eddy, A. Krogh, and G. Mitchison

Uses of Hidden Markov Models

  • Modeling stochastic processes
  • Sequence alignment
  • Phylogenetic tree construction
  • Microarray data analysis (clustering)
  • Protein secondary structure prediction
  • RNA secondary structure prediction
  • Ion channel modeling

Markov Model

  • A process is Markov if it has no memory,

that is, if the next state it assumes, depends

only on its present state and not on any

previous states.

  • The states can be observed and the transition

probabilities between states is known

  • Example – rolling a die has 6 possible states

each with a probability of 1/

CpG Islands

  • Hence, the CpG Island might be a good indicator of the start of a gene.
  • This leads to two questions:
    • How can we tell if a region is a CpG Island or not?
    • How do we identify CpG Islands in a long sequence of DNA?

CpG Islands

  • We can create a Markov model to generate the CpG Island regions starting with a Markov model that generates a DNA sequence (Markov chain).
  • On the arrows are transition probabilities:

ast =P(x (^) i =t|x (^) i-1=s)

A T

C G

DNA sequence model

  • The probability of the sequence is

P(x) = P(x (^) L, x (^) L-1,…,x 1 ) = P(x (^) L | x (^) L-1,…,x 1 )P(x (^) L-1|x (^) L-2,…,x 1 )…P(x 1 ) = P(x (^) L | x (^) L-1)P(x (^) L-1|x (^) L-2)…P(x 1 ) [Why?] = P(x 1 ) Πli=1 a (^) xi-1 xi

A T

C G

DNA Sequence Model

  • We can model the beginning and end of the sequences by adding a beginning state and end state. with P(x 1 =s) = aBs and P(E|x (^) L =a (^) tE )

A T

C G

B E

Example - CpG Islands

  • We can create a hidden Markov model to generate the CpG Island regions.
  • The “+” states are for nucleotides found in the CpG Islands.
  • The “-” states are nucleotides not found in the CpG Islands.
  • There is a complete set of transitions within each set of states.

A + C+ T+ G +

A - C- T- G -

Example - CpG Islands

  • Using the hidden Markov Model we can compute the transition probabilities by

T 0.177 0.239 0.292 0.

G 0.248 0.246 0.298 0.

C 0.322 0.298 0.078 0.

A 0.300 0.205 0.285 0.

  • A C G T

T 0.079 0.355 0.384 0.

G 0.161 0.339 0.375 0.

C 0.171 0.368 0.274 0.

A 0.180 0.274 0.426 0.

  • A C G T

= t ' st '

st st c

a c

Example - CpG Islands

  • For discrimination, the log liklihood ratio is calculated by

T -1.169 0.573 0.393 0.

G -0.624 0.461 0.331 -0.

C -0.913 0.302 1.812 -0.

A -0.740 0.419 0.580 -0.

β/L A C G T

∑= − ∑=

= (^) −+= −−^ = − L ii

L ii i ii i xx xx S x PPxx aaxx (|) 1 log 11 1 1 () log (|) β

The occasionally dishonest

casino

  • Uses a fair die most of the time but switches

to a loaded die

  • The loaded die has probability of 0.5 of a 6

and 0.1 for the other outcomes

  • The fair to loaded transition probability is
  • The loaded to fair transition probability is

Most Probable State Path

Given a sequence of emissions, we want to find the most probable sequence of states that would yield the emitted sequence. π*=argmaxπ P(x,π)

From Durbin et al

Viterbi Algorithm

Suppose that the probability v (^) k(i) (the Viterbi variable) of the most probably path ending in state k with observation i is known for all states k.

Then these probabilities can be calculated for observation x (^) i+1 as v (^) l (i+1) = el (x (^) i+1) max (^) k(v (^) k(i) akl )

All paths start in the begin state so v 0 (0) = 1.

Viterbi Algorithm

Initialization: (i=0): v 0 (0)=1, vk (0)=0 for k > 0

Recursion: (i=1…L): v (^) l (i)=e (^) l (xi )maxk vk (i-1)akl ); ptr (^) i =argmaxk vk (i-1)a (^) kl ).

Termination: P(x,π^ )=maxk (vk (L)ak0 ); πL=argmaxk (vk (L)ak0 ).

Traceback (i=L…1): πi-1 =ptr (^) i (πi ).

Viterbi Algorithm

  • Multiplying many probabilities together

results in very small numbers that will give

underflow.

  • This and other algorithms should be done in

log space (log(v l(i)) so that the products

become sums and the numbers stay

reasonable.

Backward Algorithm and Posterior

State Probabilities

  • While the Viterbi algorithm finds the most probable path through the model, we might want to know what the most probable state is for an observation x (^) i.
  • The probability that an observation x (^) i came from a state k given the observed sequence is the posterior probability. (i.e. P(πi =k|x) )
  • P(πi =k|x) = P(πi =k, x) /P(x)
  • P(πi =k, x) = f (^) k(i) b (^) k(i) where b (^) k(i)=P(x (^) i+1…x (^) L | πi =k) (the backward variable)

The Backward Algorithm

Initialization (i=L): bk(L)=ak0 for all k

Recursion (i=L-1…1): bl (i) = Σl a (^) kl el (x (^) i+1) b (^) k(i+1)

Termination: P(x) = Σl a (^) 0l el (x 1 ) b (^) l (1)

Posterior Probabilities

From Durbin et al

Posterior Decoding

  • The posterior probability is useful for two different forms of decoding (in additiion the Viterbi decoding discussed previously).
  • These are used when there are more than one path that has similar probability as the most probable one.
  • One approach is to use an alternative path to look at a state assignment at a particular point i.

Training and Testing the HMM

  • The parameters of the model are fit on a

training set, ie., the parameters are chosen

so that the training set is the most likely

outcome for the model.

  • A test set is used to make sure the model is

well-trained.

  • If so, the model can be used on new data.

Parameter Estimation when the state sequence is known

  • If we know all the paths, we can count the number times a particular transition or emission occurs out of the total number of times that it was possible to get a maximum likelihood estimate for the transition and emission probabilities. akl = Akl / Σl’ Akl’ ek(b) = Ek(b)/ Σb’ Ek (b’)
  • This can be proven to be the MLE.

Estimation when the paths are

unknown

  • In this case there is no closed form estimate for the transition and emission probabilities.
  • Instead, an iterative method must be used to estimated the values for the transition and emission probabilities using current values.
  • The new values replace the old values and the iteration continues until convergence occurs.
  • This procedure is called the Baum-Welch Algorithm.

Baum-Welch Algorithm

  • Calculates the transition and emission matric as the expected number of times each transition or emission is used given the training sequence.
  • To do this, the forward and backward values are used.
  • The probability that a (^) kl is used at position i in sequence x is P(πi =k,πi+1=l|x,θ) = f (^) k(i)akl el (x (^) i+1)b (^) l (i+1)/P(x)

Baum-Welch Algorithm

Initialization: Pick arbitrary model parameters Recurrence: Set all the A and E variables to their pseudocount values r (or to zero) For each sequence j = 1…n: Calculate fk (i) for sequence j using the forward algorithm Calculate bk(i) for sequence j using the backward algorithm Add the contribution of sequence j to A and E Calculate the new model parameters Calculate the new log likelihood of the model Termination: Stop if the change in the log likelihood is less than some predefined threshold or the maximum number of iterations is exceeded

Parameter Estimation with HMM

1: 1/ 2: 1/ 3: 1/ 4: 1/ 5: 1/ 6: 1/

1: 1/ 2: 1/ 3: 1/ 4: 1/ 5: 1/ 6: 1/

Fair Loaded

1: 0. 2: 0. 3: 0. 4: 0. 5: 0. 6: 0.

1: 0. 2: 0. 3: 0. 4: 0. 5: 0. 6: 0.

Fair Loaded

With hidden Markov models, we can calculate

the most likely emission and transition

probabilities from the sequence of outcomes.

HMM Topology

  • Thus far we have studied how to determine the unknown parameters for a model of know topology.
  • Use knowledge about the process being described to decide the topology.
  • Picking a very general topology and letting the model fit itself by reducing unused connections to low probability is not a good approach since the model gets caught in local maxima.

Silent States

  • Silent states or null states are states that do not emit symbols. In the previous example the begin and end states were silent.
  • These can be added anywhere in the model.