All problems
HMM Forward Value
Problem
Perform one scaled forward step of a hidden Markov model. Given the previous forward vector alpha_prev, the row-stochastic transition matrix, and the emission probabilities for the new observation, compute alpha_new[j] = emission[j] * sum over i of alpha_prev[i] * A[i][j], then rescale the vector to sum to one.
Return a zero vector when the total is zero.
Hint
Propagate through the transition columns first, then weight by the emission.
Test cases
case 1
in: [[0.5,0.5],[[0.9,0.1],[0.2,0.8]],[0.6,0.4]]
expected: [0.6470588235294118,0.35294117647058826]
case 2
in: [[0.3,0.7],[[0.8,0.2],[0.1,0.9]],[0.5,0.5]]
expected: [0.31,0.69]
case 3
in: [[0.5,0.5],[[0.9,0.1],[0.2,0.8]],[0,0]]
expected: [0,0]
case 4
in: [[1,0],[[1,0],[0,1]],[0.3,0.7]]
expected: [1,0]
Starter codePython
def hmm_forward_value(alpha_prev, transition, emission):
# Your code here
pass4 test cases · run your code against them in the editor