Presentation is loading. Please wait.

Presentation is loading. Please wait.

. Parameter Estimation For HMM Lecture #7 Background Readings: Chapter 3.3 in the text book, Biological Sequence Analysis, Durbin et al., 2001.

Similar presentations


Presentation on theme: ". Parameter Estimation For HMM Lecture #7 Background Readings: Chapter 3.3 in the text book, Biological Sequence Analysis, Durbin et al., 2001."— Presentation transcript:

1 . Parameter Estimation For HMM Lecture #7 Background Readings: Chapter 3.3 in the text book, Biological Sequence Analysis, Durbin et al., 2001.

2 2 Reminder: Hidden Markov Model Markov Chain transition probabilities: p(S i+1 = t|S i = s) = a st Emission probabilities: p(X i = b| S i = s) = e s (b) S1S1 S2S2 S L-1 SLSL x1x1 x2x2 X L-1 xLxL M M M M TTTT For each integer L, this defines a probability space in which the simple events are HMM of length L.

3 3 Hidden Markov Model for CpG Islands The states: Domain(S i )={+, -}  {A,C,T,G} (8 values) In this representation P(x i | s i ) = 0 or 1 depending on whether x i is consistent with s i. E.g. x i = G is consistent with s i =(+,G) and with s i =(-,G) but not with any other state of s i. A-A- T+T+ A T G + G … … … …

4 4 Reminder: Most Probable state path S1S1 S2S2 S L-1 SLSL x1x1 x2x2 X L-1 xLxL M M M M TTTT Given an output sequence x = (x 1,…,x L ), A most probable path s*= (s * 1,…,s * L ) is one which maximizes p(s|x).

5 5 Reminder: Viterbi’s algorithm for most probable path s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi For i=1 to L do for each state l : v l (i) = e l (x i ) MAX k {v k (i-1)a kl } ptr i (l)=argmax k {v k (i-1)a kl } [storing previous state for reconstructing the path] Termination: the probability of the most probable path Initialization: v 0 (0) = 1, v k (0) = 0 for k > 0 0 We add the special initial state 0. p(s 1 *,…,s L * ;x 1,…,x l ) =

6 6 A-A- C-C- T-T- T+T+ A CTT G + G Predicting CpG islands via most probable path: Output symbols: A, C, G, T (4 letters). Markov Chain states: 4 “-” states and 4 “+” states, two for each letter (8 states). The most probable path (found by Viterbi’s algorithm) predicts CpG islands. Experiment (Durbin et al, p. 60-61) shows that the predicted islands are shorter than the assumed ones. In addition quite a few “false negatives” are found.

7 7 Reminder: Most probable state s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi Given an output sequence x = (x 1,…,x L ), s i is a most probable state (at location i) if: s i =argmax k p(S i =k |x).

8 8 Reminder: finding most probable state 1. The forward algorithm finds {f k (s i ) = P(x 1,…,x i,s i =k): k = 1,...m}. 2. The backward algorithm finds {b k (s i ) = P(x i+1,…,x L |s i =k ): k = 1,...m}. 3. Return {p(S i =k|x) = f k (s i ) b k (s i ) |k=1,...,m}. To Compute for every i simply run the forward and backward algorithms once, and compute {f k (s i ) b k (s i )} for every i, k. s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi f l (i) = p(x 1,…,x i,s i =l ), the probability of a path which emits (x 1,..,x i ) and in which state s i =l. b l (i)= p(x i+1,…,x L,s i =l), the probability of a path which emits (x i+1,..,x L ) and in which state s i =l.

9 9 Finding the probability that a letter is in a CpG island via the algorithm for most probable state: The probability that an occurrence of G is in a CpG island (+ state) is: ∑ s + p(S i =s + |x) = ∑ s + F(S i =s + )B(S i =s + ) Where the summation is formally over the 4 “+” states, but actually only state G + need to be considered (why?) A-A- C-C- T-T- T+T+ A CTT G + G

10 10 Parameter Estimation for HMM An HMM model is defined by the parameters: a kl and e k (b), for all states k,l and all symbols b. Let θ denote the collection of these parameters. s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi lk b a kl ek(b)ek(b)

11 11 Parameter Estimation for HMM To determine the values of (the parameters in) θ, use a training set = {x 1,...,x n }, where each x j is a sequence which is assumed to fit the model. Given the parameters θ, each sequence x j has an assigned probability p(x j |θ) (or p(x j | θ,HMM)). s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

12 12 Maximum Likelihood Parameter Estimation for HMM The elements of the training set {x 1,...,x n }, are assumed to be independent, p(x 1,..., x n |θ) = ∏ j p (x j |θ). ML parameter estimation looks for θ which maximizes the above. The exact method for finding or approximating this θ depends on the nature of the training set used.

13 13 Data for HMM Possible properties of (the sequences in) the training set: 1.For each x j, the information on the states s j i (the symbols x j i are usually known). 2.The size (number of sequences) of the training set S1S1 S2S2 S L-1 SLSL x1x1 x2x2 X L-1 xLxL M M M M TTTT

14 14 Case 1: ML when Sequences are fully known We know the complete structure of each sequence in the training set {x 1,...,x n }. We wish to estimate a kl and e k (b) for all pairs of states k, l and symbols b. By the ML method, we look for parameters θ* which maximize the probability of the sample set: p(x 1,...,x n | θ*) =MAX θ p(x 1,...,x n | θ). s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

15 15 Case 1: Sequences are fully known s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi Let m kl = |{i: s i-1 =k,s i =l}| (in x j ). m k (b)=|{i:s i =k,x i =b}| (in x j ). For each x j we have:

16 16 Case 1 (cont) s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi By the independence of the x j ’s, p(x 1,...,x n | θ)=∏ j p(x j |θ). Thus, if A kl = #(transitions from k to l) in the training set, and E k (b) = #(emissions of symbol b from state k) in the training set, we have:

17 17 Case 1 (cont) So we need to find a kl ’s and e k (b)’s which maximize: Subject to:

18 18 Case 1 (cont) Rewriting, we need to maximize:

19 19 Case 1 (cont) Then we will maximize also F. Each of the above is a simpler ML problem, which is similar to ML parameters estimation for a die, treated next.

20 20 ML parameters estimation for a die Let X be a random variable with 6 values x 1,…,x 6 denoting the six outcomes of a die. Here the parameters are θ ={  1,  2,  3,  4,  5,  6 }, ∑θ i =1 Assume that the data is one sequence: Data = (x 6,x 1,x 1,x 3,x 2,x 2,x 3,x 4,x 5,x 2,x 6 ) So we have to maximize Subject to: θ 1 +θ 2 + θ 3 + θ 4 + θ 5 + θ 6 =1 [and θ i  0 ]

21 21 Side comment: Sufficient Statistics u To compute the probability of data in the die example we only require to record the number of times N i falling on side i (namely,N 1, N 2,…,N 6 ). u We do not need to recall the entire sequence of outcomes u {N i | i=1…6} is called sufficient statistics for the multinomial sampling.

22 22 Sufficient Statistics u A sufficient statistics is a function of the data that summarizes the relevant information for the likelihood  Formally, s(Data) is a sufficient statistics if for any two datasets D and D’ s(Data) = s(Data’ )  P(Data|  ) = P(Data’|  ) Datasets Statistics Exercise: Define “sufficient statistics” for the HMM model.

23 23 Maximum Likelihood Estimate By the ML approach, we look for parameters that maximizes the probability of data (i.e., the likelihood function ). We will find the parameters by considering the corresponding log-likelihood function: A necessary condition for (local) maximum is: 0 1 )|(log 5 1 6     θ    i i j j j NNDataP  

24 24 Finding the Maximum Rearranging terms: Divide the j th equation by the i th equation: Sum from j=1 to 6: So there is only one local – and hence global – maximum. Hence the MLE is given by:

25 25 Generalization for distribution with any number n of outcomes Let X be a random variable with n values x 1,…,x k denoting the k outcomes of Independently and Identically Distributed experiments, with parameters θ ={  1,  2,...,  k } (θ i is the probability of x i ). Again, the data is one sequence of length n: Data = (x i 1,x i 2,...,x i n ) Then we have to maximize Subject to: θ 1 +θ 2 +....+ θ k =1

26 26 Generalization for n outcomes (cont) By treatment identical to the die case, the maximum is obtained when for all i: Hence the MLE is given by:

27 27 Fractional Exponents Some models allow n i ’s to be fractions (since we are uncertain of a die outcome, and consider it “6” with 20% confidence and “5” with 80%): We still can have And the same analysis yields:

28 28 Apply the ML method to HMM Let A kl = #(transitions from k to l) in the training set. E k (b) = #(emissions of symbol b from state k) in the training set. We need to: s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

29 29 Apply to HMM (cont.) We apply the previous technique to get for each k the parameters {a kl |l=1,..,m} and {e k (b)|b  Σ}: s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi Which gives the optimal ML parameters

30 30 Summary of Case 1: Sequences are fully known We know the complete structure of each sequence in the training set {x 1,...,x n }. We wish to estimate a kl and e k (b) for all pairs of states k, l and symbols b. Summary: when everything is known, we can find the (unique set of) parameters θ* which maximizes p(x 1,...,x n | θ*) =MAX θ p(x 1,...,x n | θ). s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

31 31 Adding pseudo counts in HMM If the sample set is too small, we may get a biased result. In this case we modify the actual count by our prior knowledge/belief: r kl is our prior belief and transitions from k to l. r k (b) is our prior belief on emissions of b from state k. s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

32 32 Case 2: State paths are unknown For a given θ we have: p(x 1,..., x n |θ)= p(x 1 | θ)    p (x n |θ) (since the x j are independent) s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi For each sequence x, p(x|θ)=∑ s p(x,s|θ), The sum taken over all state paths s which emit x.

33 33 Case 2: State paths are unknown Thus, for the n sequences (x 1,..., x n ) we have: p(x 1,..., x n |θ)= ∑ p(x 1,..., x n, s 1,..., s n |θ), Where the summation is taken over all tuples of n state paths (s 1,..., s n ) which generate (x 1,..., x n ). For simplicity, we will assume that n=1. s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi (s 1,..., s n )

34 34 Case 2: State paths are unknown So we need to maximize p(x|θ)=∑ s p(x,s|θ), where the summation is over all the sequences S which produce the output sequence x. Finding θ * which maximizes ∑ s p(x,s|θ) is hard. [Unlike finding θ * which maximizes p(x,s|θ) for a single sequence (x,s).] s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

35 35 ML Parameter Estimation for HMM The general process for finding θ in this case is 1.Start with an initial value of θ. 2.Find θ’ so that p(x|θ’) > p(x|θ) 3.set θ = θ’. 4.Repeat until some convergence criterion is met. A general algorithm of this type is the Expectation Maximization algorithm, which we will meet later. For the specific case of HMM, it is the Baum- Welch training.

36 36 Baum Welch training We start with some values of a kl and e k (b), which define prior values of θ. Then we use an iterative algorithm which attempts to replace θ by a θ * s.t. p( x |θ * ) > p( x |θ) This is done by “imitating” the algorithm for Case 1, where all states are known: s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi

37 37 Baum Welch training In case 1 we computed the optimal values of a kl and e k (b), (for the optimal θ) by simply counting the number A kl of transitions from state k to state l, and the number E k (b) of emissions of symbol b from state k, in the training set. This was possible since we knew all the states. S i = lS i-1 = k x i-1 = b … … x i = c

38 38 Baum Welch training When the states are unknown, the counting process is replaced by averaging process: For each edge s i-1  s i we compute the average number of “k to l” transitions, for all possible pairs (k,l), over this edge. Then, for each k and l, we take A kl to be the sum over all edges. S i = ?S i-1 = ? x i-1 = b x i = c ……

39 39 Baum Welch training Similarly, For each edge s i  b and each state k, we compute the average number of times that s i =k, which is the expected number of “k → b” transmission on this edge. Then we take E k (b) to be the sum over all such edges. These expected values are computed by assuming the current parameters θ: S i = ?S i-1 = ? x i-1 = b x i = c

40 40 A kl and E k (b) when states are unknown A kl and E k (b) are computed according to the current distribution θ, that is: s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi A kl =∑ s A s kl p(s|x,θ), where A s kl is the number of k to l transitions in the sequence s. E k (b)=∑ s E s k (b)p(s|x,θ), where E s k (b) is the number of times k emits b in the sequence s with output x.

41 41 Baum Welch: step 1a Count expected number of state transitions For each i, k,l, compute the state transitions probabilities by the current θ: s1s1 SiSi sLsL X1X1 XiXi XLXL S i-1 X i-1.. P(s i-1 =k, s i =l | x,θ) For this, we use the forwards and backwards algorithms

42 42 Reminder: finding state probabilities p(s i =k,x) = f k (s i ) b k (s i ) {f k (i) b k (i)} for every i and k are computed by one run of the backward/forward algorithms as follows: s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL sisi XiXi f k (i) = p(x 1,…,x i,s i =k ), the probability that in a path which emits (x 1,..,x i ), state s i =k. b k (i)= p(x i+1,…,x L |s i =k), the probability that a path which emits (x i+1,..,x L ), given that state s i =k.

43 43 Baum Welch: Step 1a (cont) Claim: By the probability distribution of HMM s1s1 SiSi sLsL X1X1 XiXi XLXL S i-1 X i-1.. (a kl and e l (x i ) are the parameters defined by , and f k (i-1), b k (i) are the forward and backward functions)

44 44 Step 1a: Computing P(s i-1 =k, s i =l | x,θ) P(x 1,…,x L,s i-1 =k,s i =l|  ) = P(x 1,…,x i-1,s i-1 =k|  ) a kl e l (x i ) P(x i+1,…,x L |s i =l,  ) = f k (i-1) a kl e l (x i ) b l (i) Via the forward algorithm Via the backward algorithm s1s1 s2s2 s L-1 sLsL X1X1 X2X2 X L-1 XLXL S i-1 X i-1 sisi XiXi x p(s i-1 =k,s i =l | x,  ) = f k (i-1) a kl e l (x i ) b l (i)

45 45 Step 1a (end) For each pair (k,l), compute the expected number of state transitions from k to l, as the sum of the expected number of k to l transitions over all L edges :


Download ppt ". Parameter Estimation For HMM Lecture #7 Background Readings: Chapter 3.3 in the text book, Biological Sequence Analysis, Durbin et al., 2001."

Similar presentations


Ads by Google