Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sab_pyhsmm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Bruijns
sab_pyhsmm
Commits
3ba405ec
Commit
3ba405ec
authored
8 years ago
by
Scott Linderman
Browse files
Options
Downloads
Patches
Plain Diff
python 3 imports
parent
6c831346
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyhsmm/internals/hmm_states.py
+8
-8
8 additions, 8 deletions
pyhsmm/internals/hmm_states.py
pyhsmm/internals/hsmm_states.py
+3
-3
3 additions, 3 deletions
pyhsmm/internals/hsmm_states.py
pyhsmm/util/plot.py
+2
-1
2 additions, 1 deletion
pyhsmm/util/plot.py
with
13 additions
and
12 deletions
pyhsmm/internals/hmm_states.py
+
8
−
8
View file @
3ba405ec
...
@@ -605,20 +605,20 @@ class HMMStatesEigen(HMMStatesPython):
...
@@ -605,20 +605,20 @@ class HMMStatesEigen(HMMStatesPython):
@staticmethod
@staticmethod
def
_messages_backwards_log
(
trans_matrix
,
log_likelihoods
):
def
_messages_backwards_log
(
trans_matrix
,
log_likelihoods
):
from
hmm_messages_interface
import
messages_backwards_log
from
pyhsmm.internals.
hmm_messages_interface
import
messages_backwards_log
return
messages_backwards_log
(
return
messages_backwards_log
(
trans_matrix
,
log_likelihoods
,
trans_matrix
,
log_likelihoods
,
np
.
empty_like
(
log_likelihoods
))
np
.
empty_like
(
log_likelihoods
))
@staticmethod
@staticmethod
def
_messages_forwards_log
(
trans_matrix
,
init_state_distn
,
log_likelihoods
):
def
_messages_forwards_log
(
trans_matrix
,
init_state_distn
,
log_likelihoods
):
from
hmm_messages_interface
import
messages_forwards_log
from
pyhsmm.internals.
hmm_messages_interface
import
messages_forwards_log
return
messages_forwards_log
(
trans_matrix
,
log_likelihoods
,
return
messages_forwards_log
(
trans_matrix
,
log_likelihoods
,
init_state_distn
,
np
.
empty_like
(
log_likelihoods
))
init_state_distn
,
np
.
empty_like
(
log_likelihoods
))
@staticmethod
@staticmethod
def
_messages_forwards_normalized
(
trans_matrix
,
init_state_distn
,
log_likelihoods
):
def
_messages_forwards_normalized
(
trans_matrix
,
init_state_distn
,
log_likelihoods
):
from
hmm_messages_interface
import
messages_forwards_normalized
from
pyhsmm.internals.
hmm_messages_interface
import
messages_forwards_normalized
return
messages_forwards_normalized
(
trans_matrix
,
log_likelihoods
,
return
messages_forwards_normalized
(
trans_matrix
,
log_likelihoods
,
init_state_distn
,
np
.
empty_like
(
log_likelihoods
))
init_state_distn
,
np
.
empty_like
(
log_likelihoods
))
...
@@ -640,19 +640,19 @@ class HMMStatesEigen(HMMStatesPython):
...
@@ -640,19 +640,19 @@ class HMMStatesEigen(HMMStatesPython):
@staticmethod
@staticmethod
def
_sample_forwards_log
(
betal
,
trans_matrix
,
init_state_distn
,
log_likelihoods
):
def
_sample_forwards_log
(
betal
,
trans_matrix
,
init_state_distn
,
log_likelihoods
):
from
hmm_messages_interface
import
sample_forwards_log
from
pyhsmm.internals.
hmm_messages_interface
import
sample_forwards_log
return
sample_forwards_log
(
trans_matrix
,
log_likelihoods
,
return
sample_forwards_log
(
trans_matrix
,
log_likelihoods
,
init_state_distn
,
betal
,
np
.
empty
(
log_likelihoods
.
shape
[
0
],
dtype
=
'
int32
'
))
init_state_distn
,
betal
,
np
.
empty
(
log_likelihoods
.
shape
[
0
],
dtype
=
'
int32
'
))
@staticmethod
@staticmethod
def
_sample_backwards_normalized
(
alphan
,
trans_matrix_transpose
):
def
_sample_backwards_normalized
(
alphan
,
trans_matrix_transpose
):
from
hmm_messages_interface
import
sample_backwards_normalized
from
pyhsmm.internals.
hmm_messages_interface
import
sample_backwards_normalized
return
sample_backwards_normalized
(
trans_matrix_transpose
,
alphan
,
return
sample_backwards_normalized
(
trans_matrix_transpose
,
alphan
,
np
.
empty
(
alphan
.
shape
[
0
],
dtype
=
'
int32
'
))
np
.
empty
(
alphan
.
shape
[
0
],
dtype
=
'
int32
'
))
@staticmethod
@staticmethod
def
_resample_multiple
(
states_list
):
def
_resample_multiple
(
states_list
):
from
hmm_messages_interface
import
resample_normalized_multiple
from
pyhsmm.internals.
hmm_messages_interface
import
resample_normalized_multiple
if
len
(
states_list
)
>
0
:
if
len
(
states_list
)
>
0
:
loglikes
=
resample_normalized_multiple
(
loglikes
=
resample_normalized_multiple
(
states_list
[
0
].
trans_matrix
,
states_list
[
0
].
pi_0
,
states_list
[
0
].
trans_matrix
,
states_list
[
0
].
pi_0
,
...
@@ -666,7 +666,7 @@ class HMMStatesEigen(HMMStatesPython):
...
@@ -666,7 +666,7 @@ class HMMStatesEigen(HMMStatesPython):
def
_expected_statistics_from_messages
(
def
_expected_statistics_from_messages
(
trans_potential
,
likelihood_log_potential
,
alphal
,
betal
,
trans_potential
,
likelihood_log_potential
,
alphal
,
betal
,
expected_states
=
None
,
expected_transcounts
=
None
):
expected_states
=
None
,
expected_transcounts
=
None
):
from
hmm_messages_interface
import
expected_statistics_log
from
pyhsmm.internals.
hmm_messages_interface
import
expected_statistics_log
expected_states
=
np
.
zeros_like
(
alphal
)
\
expected_states
=
np
.
zeros_like
(
alphal
)
\
if
expected_states
is
None
else
expected_states
if
expected_states
is
None
else
expected_states
expected_transcounts
=
np
.
zeros_like
(
trans_potential
)
\
expected_transcounts
=
np
.
zeros_like
(
trans_potential
)
\
...
@@ -678,7 +678,7 @@ class HMMStatesEigen(HMMStatesPython):
...
@@ -678,7 +678,7 @@ class HMMStatesEigen(HMMStatesPython):
### Vitberbi
### Vitberbi
def
Viterbi
(
self
):
def
Viterbi
(
self
):
from
hmm_messages_interface
import
viterbi
from
pyhsmm.internals.
hmm_messages_interface
import
viterbi
self
.
stateseq
=
viterbi
(
self
.
trans_matrix
,
self
.
aBl
,
self
.
pi_0
,
self
.
stateseq
=
viterbi
(
self
.
trans_matrix
,
self
.
aBl
,
self
.
pi_0
,
np
.
empty
(
self
.
aBl
.
shape
[
0
],
dtype
=
'
int32
'
))
np
.
empty
(
self
.
aBl
.
shape
[
0
],
dtype
=
'
int32
'
))
...
...
This diff is collapsed.
Click to expand it.
pyhsmm/internals/hsmm_states.py
+
3
−
3
View file @
3ba405ec
...
@@ -500,7 +500,7 @@ class HSMMStatesEigen(HSMMStatesPython):
...
@@ -500,7 +500,7 @@ class HSMMStatesEigen(HSMMStatesPython):
def
messages_backwards
(
self
):
def
messages_backwards
(
self
):
# NOTE: np.maximum calls are because the C++ code doesn't do
# NOTE: np.maximum calls are because the C++ code doesn't do
# np.logaddexp(-inf,-inf) = -inf, it likes nans instead
# np.logaddexp(-inf,-inf) = -inf, it likes nans instead
from
hsmm_messages_interface
import
messages_backwards_log
from
pyhsmm.internals.
hsmm_messages_interface
import
messages_backwards_log
betal
,
betastarl
=
messages_backwards_log
(
betal
,
betastarl
=
messages_backwards_log
(
np
.
maximum
(
self
.
trans_matrix
,
1e-50
),
self
.
aBl
,
np
.
maximum
(
self
.
aDl
,
-
1000000
),
np
.
maximum
(
self
.
trans_matrix
,
1e-50
),
self
.
aBl
,
np
.
maximum
(
self
.
aDl
,
-
1000000
),
self
.
aDsl
,
np
.
empty_like
(
self
.
aBl
),
np
.
empty_like
(
self
.
aBl
),
self
.
aDsl
,
np
.
empty_like
(
self
.
aBl
),
np
.
empty_like
(
self
.
aBl
),
...
@@ -519,7 +519,7 @@ class HSMMStatesEigen(HSMMStatesPython):
...
@@ -519,7 +519,7 @@ class HSMMStatesEigen(HSMMStatesPython):
return
super
(
HSMMStatesEigen
,
self
).
messages_backwards
()
return
super
(
HSMMStatesEigen
,
self
).
messages_backwards
()
def
sample_forwards
(
self
,
betal
,
betastarl
):
def
sample_forwards
(
self
,
betal
,
betastarl
):
from
hsmm_messages_interface
import
sample_forwards_log
from
pyhsmm.internals.
hsmm_messages_interface
import
sample_forwards_log
if
self
.
left_censoring
:
if
self
.
left_censoring
:
raise
NotImplementedError
raise
NotImplementedError
caBl
=
np
.
vstack
((
np
.
zeros
(
betal
.
shape
[
1
]),
np
.
cumsum
(
self
.
aBl
[:
-
1
],
axis
=
0
)))
caBl
=
np
.
vstack
((
np
.
zeros
(
betal
.
shape
[
1
]),
np
.
cumsum
(
self
.
aBl
[:
-
1
],
axis
=
0
)))
...
@@ -533,7 +533,7 @@ class HSMMStatesEigen(HSMMStatesPython):
...
@@ -533,7 +533,7 @@ class HSMMStatesEigen(HSMMStatesPython):
@staticmethod
@staticmethod
def
_resample_multiple
(
states_list
):
def
_resample_multiple
(
states_list
):
from
hsmm_messages_interface
import
resample_log_multiple
from
pyhsmm.internals.
hsmm_messages_interface
import
resample_log_multiple
if
len
(
states_list
)
>
0
:
if
len
(
states_list
)
>
0
:
Ts
=
[
s
.
T
for
s
in
states_list
]
Ts
=
[
s
.
T
for
s
in
states_list
]
longest
=
np
.
argmax
(
Ts
)
longest
=
np
.
argmax
(
Ts
)
...
...
This diff is collapsed.
Click to expand it.
pyhsmm/util/plot.py
+
2
−
1
View file @
3ba405ec
from
__future__
import
division
from
__future__
import
division
import
numpy
as
np
import
numpy
as
np
from
matplotlib
import
pyplot
as
plt
from
matplotlib
import
pyplot
as
plt
from
stats
import
cov
from
pyhsmm.util.stats
import
cov
def
plot_gaussian_2D
(
mu
,
lmbda
,
color
=
'
b
'
,
centermarker
=
True
,
label
=
''
,
alpha
=
1.
,
ax
=
None
,
artists
=
None
):
def
plot_gaussian_2D
(
mu
,
lmbda
,
color
=
'
b
'
,
centermarker
=
True
,
label
=
''
,
alpha
=
1.
,
ax
=
None
,
artists
=
None
):
'''
'''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment