diff options
Diffstat (limited to 'Wrappers')
-rwxr-xr-x | Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py b/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py index a14378c..0ba2c55 100755 --- a/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py +++ b/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py @@ -16,7 +16,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import time +import time, functools from numbers import Integral class Algorithm(object): @@ -148,14 +148,36 @@ class Algorithm(object): print ("Stop cryterion has been reached.") i = 0 + if verbose: + print ("{:>9} {:>10} {:>11} {:>20}".format('Iter', + 'Max Iter', + 's/Iter', + 'Objective Value')) for _ in self: if (self.iteration -1) % self.update_objective_interval == 0: if verbose: - print ("Iteration {}/{}, = {}".format(self.iteration-1, - self.max_iteration, self.get_last_objective()) ) + print (self.verbose_output()) if callback is not None: callback(self.iteration -1, self.get_last_objective(), self.x) i += 1 if i == iterations: break - + + def verbose_output(self): + '''Creates a nice tabulated output''' + timing = self.timing[-self.update_objective_interval-1:-1] + if len (timing) == 0: + t = 0 + else: + t = sum(timing)/len(timing) + el = [ self.iteration-1, + self.max_iteration, + "{:.3f} s/it".format(t), + self.get_last_objective() ] + + if type(el[-1] ) == list: + string = functools.reduce(lambda x,y: x+' {:>15.5e}'.format(y), el[-1],'') + out = "{:>9} {:>10} {:>11} {}".format(*el[:-1] , string) + else: + out = "{:>9} {:>10} {:>11} {:>20.5e}".format(*el) + return out |