Commit cbf1f1c5 authored by Guillaume HEUSCH's avatar Guillaume HEUSCH

[algorithm] fixed criteria for stopping the training loop

parent 0d6da9b9
Pipeline #21776 passed with stage
in 22 minutes and 58 seconds
...@@ -98,12 +98,12 @@ class MLP(Algorithm): ...@@ -98,12 +98,12 @@ class MLP(Algorithm):
n_iter = 0 n_iter = 0
previous_cost = 0 previous_cost = 0
current_cost = 1 current_cost = 1
while (n_iter < self.max_iter) or (abs(previous_cost - current_cost) > self.precision): while (n_iter < self.max_iter) and (abs(previous_cost - current_cost) > self.precision):
previous_cost = current_cost previous_cost = current_cost
trainer.train(self.mlp, X, Y) trainer.train(self.mlp, X, Y)
current_cost = trainer.cost(self.mlp, X, Y) current_cost = trainer.cost(self.mlp, X, Y)
n_iter += 1 n_iter += 1
logger.debug("Iteration {} -> cost = {} (previous = {})".format(n_iter, trainer.cost(self.mlp, X, Y), previous_cost)) logger.debug("Iteration {} -> cost = {} (previous = {}, max_iter = {})".format(n_iter, trainer.cost(self.mlp, X, Y), previous_cost, self.max_iter))
f = bob.io.base.HDF5File(projector_file, 'w') f = bob.io.base.HDF5File(projector_file, 'w')
self.mlp.save(f) self.mlp.save(f)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment