Files
labs/Module-5/4.HMMs_Implementation.ipynb

2.5 KiB

In [ ]:
ob_types = ('W','N')
# W for working and N for not working
states = ('L','M')
#M is the malicious and L is Legitimate
In [ ]:
import numpy as np
observation = ('W','W','W','N')
start = np.matrix('0.1 0.9')
transition = np.matrix('0.7 0.3 ; 0.1 0.9')
emission = np.matrix('0.2 0.8 ; 0.4 0.6')
In [ ]:
from hidden_markov import hmm
ob_types = ('W','N')
# W for working and N for not working
states = ('L','M')
#M is the malicious and L is Legitimate
observation = ('W','W','W','N')
start = np.matrix('0.1 0.9')
transition = np.matrix('0.7 0.3 ; 0.1 0.9')
emission = np.matrix('0.2 0.8 ; 0.4 0.6')
_hmm = hmm(states, ob_types, start, transition,emission)
print("Forward algorithm")
print(_hmm.forward_algo(observation))
print("Viterbi algorithm: ")
print(_hmm.viterbi(observation))

Forward algorithm gives us the probability of an observerd sequence in the HMM

Viterbi algorithm is used to find out the most likely sequence of hidden states that can generate the given set of observations