Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
binfpy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
opensource
binfpy
Commits
eda971ca
Commit
eda971ca
authored
Aug 22, 2018
by
Mikael Boden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HMM_added
parent
f9a4551b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
prob.py
prob.py
+11
-5
No files found.
prob.py
View file @
eda971ca
...
...
@@ -865,24 +865,30 @@ class HMM():
> states = cpg_hmm.viterbi(X)
> print(states)
"""
X
=
_terminate
(
symseq
,
1
,
self
.
startsym
,
self
.
endsym
)
X
=
_terminate
(
symseq
,
1
,
self
.
startsym
,
self
.
endsym
)
# put start and end symbols on sequence
# Initialise state scores for each index in X
for
state
in
self
.
mystates
:
# Fill in emission probabilities for each index in X
# Fill in emission probabilities in V for each index of X
# (only the first position is really needed)
V
[
state
]
=
[
self
.
e
[
state
][
x
]
for
x
in
X
]
trace
[
state
]
=
[]
# Next loop through the sequence
for
j
in
range
(
len
(
X
)
-
1
):
i
=
j
+
1
# sequence index that we're processing
for
tostate
in
self
.
mystates
:
i
=
j
+
1
# sequence index that we're processing
start with 1, not 0
for
tostate
in
self
.
mystates
:
# check each state for i = 1, ...
tracemax
=
0
beststate
=
None
beststate
=
None
# the state v with max[Vv(i-1) * t(v,u)]
for
fromstate
in
self
.
mystates
:
# determine the best score propagated forward from previous state
score
=
V
[
fromstate
][
i
-
1
]
*
self
.
a
[
fromstate
][
tostate
]
if
score
>
tracemax
:
beststate
=
fromstate
tracemax
=
score
# record the transition that will appear in the traceback
trace
[
tostate
]
.
append
(
beststate
)
# finalise the dynamic programming score for current i in state u
V
[
tostate
][
i
]
=
self
.
e
[
tostate
][
X
[
i
]]
*
tracemax
# finally, assemble the string that describes the most probable path
ret
=
''
traced
=
'$'
for
j
in
range
(
len
(
X
)):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment