Skip to content
DeepForgeby svx
All problems
HardTime Seriests-315

HMM Backward Value

Problem

Perform one scaled backward step of a hidden Markov model: beta_new[i] = sum over j of A[i][j] * emission[j] * beta_next[j], then rescale the vector to sum to one. Here emission holds the probabilities of the current observation.

Return a zero vector when the total is zero.

Hint

The backward message sums over all next states weighted by transition, emission, and future evidence.

Test cases

case 1
in: [[0.6,0.4],[[0.9,0.1],[0.2,0.8]],[0.5,0.7]]
expected: [0.5120274914089347,0.48797250859106517]
case 2
in: [[1,1],[[0.5,0.5],[0.5,0.5]],[1,1]]
expected: [0.5,0.5]
case 3
in: [[0.6,0.4],[[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_backward_value(beta_next, transition, emission):
    # Your code here
    pass

4 test cases · run your code against them in the editor