From 7e0ed0c5fef0382d6b6903d8132fd06a2c4d2967 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Wed, 20 Feb 2019 15:05:36 +0000 Subject: add run method --- Wrappers/Python/ccpi/optimisation/Algorithms.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Wrappers/Python/ccpi/optimisation/Algorithms.py b/Wrappers/Python/ccpi/optimisation/Algorithms.py index 9115e6e..0a5cac6 100644 --- a/Wrappers/Python/ccpi/optimisation/Algorithms.py +++ b/Wrappers/Python/ccpi/optimisation/Algorithms.py @@ -84,6 +84,12 @@ class Algorithm(object): def max_iteration(self, value): assert isinstance(value, int) self.__max_iteration = value + def run(self, iterations, callback=None): + '''run n iterations and update the user with the callback if specified''' + self.max_iteration += iterations + for _ in self: + if callback is not None: + callback(self.iteration, self.get_current_loss()) class GradientDescent(Algorithm): '''Implementation of a simple Gradient Descent algorithm -- cgit v1.2.3