Assignment

Write a function probability that takes five arguments: i) an output sequence $$x$$, ii) a sequence of symbols representing an alphabet $$\Sigma$$, iii) a sequence representing a hidden path $$\pi$$, iv) a sequence of states $$S$$ and v) an emission probability matrix $$E$$ of an HMM ($$\Sigma$$, $$S$$, $$T$$, $$E$$). The function must return the common logarithm of $$P(x | \pi)$$, i.e. the probability that the sequence $$x$$ is emitted by the HMM ($$\Sigma$$, $$S$$, $$T$$, $$E$$), given the hidden path $$\pi$$.

Example

>>> probability('xxyzyxzzxzxyxyyzxxzzxxyyxxyxyzzxxyzyzxzxxyxyyzxxzx', 'xyz', 'BBBAAABABABBBBBBAAAAAABAAAABABABBBBBABAABABABABBBB', 'AB', [[0.612, 0.314, 0.074], [0.346, 0.317, 0.336]])
-27.714089389027333
>>> probability('xzxyzxzyxzzyzxyyyzyzyxxzyyxxxyzxxzyxyyyyzyxyzzzyyy', 'xyz', 'ABBBBAAAABAAABBBBBBAAAABBBABBABAABABABABAAAABABABA', 'AB', [[0.371, 0.458, 0.171], [0.451, 0.405, 0.144]])
-25.437442522675354