Assignment

Write a function probability that takes three arguments: i) a sequence representing a hidden path $$\pi$$, ii) a sequence of states $$S$$ and iii) a transition probability matrix $$T$$ of an HMM ($$\Sigma$$, $$S$$, $$T$$, $$E$$). The function must return the common logarithm of $$P(\pi)$$, i.e. the probability that the hidden path $$\pi$$ was generated by the HMM ($$\Sigma$$, $$S$$, $$T$$, $$E$$). The function must assume that the HMM uses uniformly distributed initial probabilities.

Example

>>> probability('AABBBAABABAAAABBBBAABBABABBBAABBAAAABABAABBABABBAB', 'AB', [[0.194, 0.806], [0.273, 0.727]])
-18.299527450180978
>>> probability('BABAAABAABBBAABAAAAABABBABBABAABBBBAABAABABABABABA', 'AB', [[0.446, 0.554], [0.554, 0.446]])
-14.564199832264118