Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-211

HMM Regime Decode Step

Problem

Perform one Viterbi step for a hidden Markov regime model. Given previous log-scores dp_prev, a transition matrix, and current emission likelihoods, compute for each state the best predecessor score and record the argmax backpointer.

Return [new_dp, backpointers]. Add a tiny epsilon before taking logs so zero probabilities stay finite.

Hint

The backpointer records which previous state produced the best path to each state.

Test cases

case 1
in: [[0,0],[[0.9,0.1],[0.2,0.8]],[0.6,0.4]]
expected: [[-0.6161861394238171,-1.1394342831883648],[0,1]]
case 2
in: [[-1,-2],[[0.9,0.1],[0.2,0.8]],[0.5,0.5]]
expected: [[-1.7985076962177717,-2.916290731874155],[0,1]]
case 3
in: [[0,0],[[0.5,0.5],[0.5,0.5]],[1,1]]
expected: [[-0.6931471805599453,-0.6931471805599453],[0,0]]
case 4
in: [[-10,0],[[0.9,0.1],[0.2,0.8]],[0.9,0.1]]
expected: [[-1.7147984280919266,-2.525728644308255],[1,1]]
Starter codePython
import math
def hmm_regime_decode_step(dp_prev, transition_matrix, emission_probs):
    # Your code here
    pass

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