diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2019-07-01 17:50:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-01 17:50:58 +0100 |
commit | cd3b0afb72777389c63cc2ca037fd37884e47447 (patch) | |
tree | 14240c3824b7260daa6e70a241bcf83649fd99c1 | |
parent | d30584e78e5507839360278250c55280bbc2a18e (diff) | |
parent | 005c724ff52f34bda1fc7712d1f8ee7257f501de (diff) | |
download | framework-cd3b0afb72777389c63cc2ca037fd37884e47447.tar.gz framework-cd3b0afb72777389c63cc2ca037fd37884e47447.tar.bz2 framework-cd3b0afb72777389c63cc2ca037fd37884e47447.tar.xz framework-cd3b0afb72777389c63cc2ca037fd37884e47447.zip |
Merge pull request #338 from vais-ral/verbose_output
correct verbose output
-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 c62d0ea..f9f65b2 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''' @@ -89,6 +90,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: @@ -150,27 +155,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() |