All problems
HMM Forward Likelihood Step
Problem
Compute the total likelihood of the next observation for one HMM forward step.
alpha_prev maps each previous state to its alpha value, transitions maps 'from to' keys to transition probabilities, and emissions maps each current state to its emission probability for the observed symbol.
Return the sum over current states j of emissions[j] * sum over previous states i of alpha_prev[i] * P(j | i). Missing transitions count as 0.0.
Hint
Accumulate incoming probability mass per current state, then weight it by that state's emission.
Test cases
case 1
in: [{"A":0.6,"B":0.4},{"A X":0.5,"A Y":0.5,"B X":0.25,"B Y":0.75},{"X":0.8,"Y":0.2}]
expected: 0.44000000000000006
case 2
in: [{"A":1},{"A B":0.3},{"B":0.5}]
expected: 0.15
case 3
in: [{"A":0.2,"B":0.8},{"A Z":1},{"Z":0.5}]
expected: 0.1
case 4
in: [{"A":1},{"A X":1},{"X":0}]
expected: 0
case 5
in: [{},{"A X":0.5},{"X":0.8}]
expected: 0
Starter codePython
def hmm_forward_likelihood_step(alpha_prev, transitions, emissions):
# Your code here
pass5 test cases · run your code against them in the editor