Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.learn.em
Commits
af6fd843
Commit
af6fd843
authored
May 06, 2015
by
Elie KHOURY
Browse files
added logging info for the EM training
parent
2782bcab
Changes
2
Hide whitespace changes
Inline
Side-by-side
bob/learn/em/test/test_em.py
View file @
af6fd843
...
...
@@ -18,6 +18,9 @@ from bob.learn.em import KMeansMachine, GMMMachine, KMeansTrainer, \
import
bob.learn.em
import
bob.core
bob
.
core
.
log
.
setup
(
"bob.learn.em"
)
#, MAP_GMMTrainer
def
loadGMM
():
...
...
bob/learn/em/train.py
View file @
af6fd843
...
...
@@ -6,6 +6,8 @@
# Copyright (C) 2011-2015 Idiap Research Institute, Martigny, Switzerland
import
numpy
import
bob.learn.em
import
logging
logger
=
logging
.
getLogger
(
'bob.learn.em'
)
def
train
(
trainer
,
machine
,
data
,
max_iterations
=
50
,
convergence_threshold
=
None
,
initialize
=
True
,
rng
=
None
):
"""
...
...
@@ -42,16 +44,21 @@ def train(trainer, machine, data, max_iterations = 50, convergence_threshold=Non
average_output
=
trainer
.
compute_likelihood
(
machine
)
for
i
in
range
(
max_iterations
):
average_output_previous
=
average_output
trainer
.
m_step
(
machine
,
data
)
trainer
.
e_step
(
machine
,
data
)
if
convergence_threshold
!=
None
and
hasattr
(
trainer
,
"compute_likelihood"
):
average_output
=
trainer
.
compute_likelihood
(
machine
)
else
:
logger
.
info
(
"Iteration = %d "
,
i
)
#Terminates if converged (and likelihood computation is set)
if
convergence_threshold
!=
None
and
abs
((
average_output_previous
-
average_output
)
/
average_output_previous
)
<=
convergence_threshold
:
break
if
convergence_threshold
!=
None
:
convergence_value
=
abs
((
average_output_previous
-
average_output
)
/
average_output_previous
)
logger
.
info
(
"Iteration = %d
\t
convergence value = %f "
,
i
,
convergence_value
)
if
convergence_value
<=
convergence_threshold
:
break
if
hasattr
(
trainer
,
"finalize"
):
trainer
.
finalize
(
machine
,
data
)
...
...
Write
Preview
Supports
Markdown
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