utility functions for Viterbi