A hidden Markov model has initial probabilities pi (length K), a transition matrix A (K by K, row i gives p(next state j | state i)), and an emission matrix B (K by M, row i gives p(symbol m | state i)). Observations are integers in 0..M-1.
The forward recursion computes p(obs) without enumerating state paths:
alpha_0(i) = pi_i * B[i, o_0]alpha_t(j) = (sum_i alpha_(t-1)(i) A[i, j]) * B[j, o_t]p(obs) = sum_i alpha_(T-1)(i)Implement forward_likelihood(pi, A, B, obs) and return p(obs) as a float.
pi sums to 1. Each row of A and of B sums to 1. All entries are nonnegative.0..M-1. Otherwise raise ValueError.ValueError.Each step is a vector-matrix product followed by an elementwise multiply with one column of B.
No results yet
Run your code to check it against the examples, or submit to run every test.