-
Notifications
You must be signed in to change notification settings - Fork 35
/
BA10C.py
51 lines (35 loc) · 1.55 KB
/
BA10C.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# Copyright (C) 2019-2023 Simon Crase
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# BA10C Implement the Viterbi Algorithm
import numpy as np
from hmm import Viterbi
from helpers import create_hmm
if __name__=='__main__':
# xs,alphabet,States,Transition,Emission=create_hmm(ext=4)
# print ( Viterbi(xs,alphabet,States,Transition,Emission))
# print ()
Transition = np.array([
[ 0.641, 0.359],
[ 0.729, 0.271]])
Emission = np.array([
[0.117, 0.691, 0.192],
[0.097, 0.42, 0.483]])
print (Viterbi('xyxzzxyxyy','xyz','AB',Transition,Emission))
Transition1 = np.array([
[ 0.634, 0.366],
[ 0.387, 0.613]])
Emission1 = np.array([
[ 0.532, 0.226, 0.241],
[ 0.457, 0.192, 0.351]])
print (Viterbi('zxxxxyzzxyxyxyzxzzxzzzyzzxxxzxxyyyzxyxzyxyxyzyyyyzzyyyyzzxzxzyzzzzyxzxxxyxxxxyyzyyzyyyxzzzzyzxyzzyyy',
'xyz','AB',Transition1,Emission1))