diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2019-07-01 18:15:21 +0100 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2019-07-01 18:15:21 +0100 |
commit | f8486df1d4cb59be72c1ca35fe281e27fd29b75c (patch) | |
tree | 76e819081addc215aab898c74db5dfd96969c12b /Wrappers | |
parent | 62ae90eff4ef83c2384dcf856b593b1d117c7e49 (diff) | |
parent | cd3b0afb72777389c63cc2ca037fd37884e47447 (diff) | |
download | framework-f8486df1d4cb59be72c1ca35fe281e27fd29b75c.tar.gz framework-f8486df1d4cb59be72c1ca35fe281e27fd29b75c.tar.bz2 framework-f8486df1d4cb59be72c1ca35fe281e27fd29b75c.tar.xz framework-f8486df1d4cb59be72c1ca35fe281e27fd29b75c.zip |
Merge branch 'master' into cgls_fix
Diffstat (limited to 'Wrappers')
-rwxr-xr-x | Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py b/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py index bf851d7..84a440a 100755 --- a/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py +++ b/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py @@ -53,6 +53,7 @@ class Algorithm(object): self.memopt = False self.configured = False self.timing = [] + self._iteration = [] self.update_objective_interval = kwargs.get('update_objective_interval', 1) def set_up(self, *args, **kwargs): '''Set up the algorithm''' @@ -91,6 +92,10 @@ class Algorithm(object): time0 = time.time() if not self.configured: raise ValueError('Algorithm not configured correctly. Please run set_up.') + if self.iteration == 0: + self.update_objective() + self._iteration.append(self.iteration) + self.update() self.timing.append( time.time() - time0 ) if self.iteration % self.update_objective_interval == 0: @@ -152,27 +157,35 @@ class Algorithm(object): if self.should_stop(): print ("Stop cryterion has been reached.") i = 0 + if verbose: + print (self.verbose_header()) + if self.iteration == 0: + if verbose: + print(self.verbose_output()) for _ in self: - if i == 0 and verbose: - print (self.verbose_header()) - if (self.iteration -1) % self.update_objective_interval == 0: + if (self.iteration) % self.update_objective_interval == 0: if verbose: print (self.verbose_output()) if callback is not None: - callback(self.iteration -1, self.get_last_objective(), self.x) + callback(self.iteration, self.get_last_objective(), self.x) i += 1 if i == iterations: + if self.iteration != self._iteration[-1]: + self.update_objective() + if verbose: + print (self.verbose_output()) break def verbose_output(self): '''Creates a nice tabulated output''' timing = self.timing[-self.update_objective_interval-1:-1] + self._iteration.append(self.iteration) if len (timing) == 0: t = 0 else: t = sum(timing)/len(timing) out = "{:>9} {:>10} {:>13} {}".format( - self.iteration-1, + self.iteration, self.max_iteration, "{:.3f}".format(t), self.objective_to_string() |