ビタビアルゴリズムを理解も兼ねて実装してみました. # -*- coding:utf-8 -*- states = ("rainy","sunny") observations = ("walk","shop","clean","shop","walk") start_prob = {"rainy":0.6,"sunny":0.4} transit_prob = {"rainy":{"rainy":0.7,"sunny":0.3}, "sunny":{"rainy":0.4,"sunny":0.6}} emission_prob = {'rainy' : {'walk': 0.1, 'shop': 0.4, 'clean': 0.5}, 'sunny' : {'walk': 0.6, 'shop': 0.3, 'clean': 0.1}} def viterbi(observs,state