summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2019-05-23 16:04:50 +0100
committerEdoardo Pasca <edo.paskino@gmail.com>2019-05-23 16:04:50 +0100
commit6794aaaa388f622cc8cd18c56c7345dca016163b (patch)
tree6355e0bd30232dcfdad31411738e7bc4121e1411 /Wrappers
parent2f997e5ef8822d958f15571e3880578ea0419fd5 (diff)
downloadframework-6794aaaa388f622cc8cd18c56c7345dca016163b.tar.gz
framework-6794aaaa388f622cc8cd18c56c7345dca016163b.tar.bz2
framework-6794aaaa388f622cc8cd18c56c7345dca016163b.tar.xz
framework-6794aaaa388f622cc8cd18c56c7345dca016163b.zip
update pretty print
Diffstat (limited to 'Wrappers')
-rwxr-xr-xWrappers/Python/ccpi/optimisation/algorithms/Algorithm.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py b/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py
index e119a1c..0778838 100755
--- a/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py
+++ b/Wrappers/Python/ccpi/optimisation/algorithms/Algorithm.py
@@ -149,10 +149,7 @@ class Algorithm(object):
i = 0
if verbose:
- print ("{:>9} {:>10} {:>11} {:>20}".format('Iter',
- 'Max Iter',
- 's/Iter',
- 'Objective Value'))
+ print (self.verbose_header())
for _ in self:
if (self.iteration -1) % self.update_objective_interval == 0:
if verbose:
@@ -173,12 +170,39 @@ class Algorithm(object):
t = sum(timing)/len(timing)
el = [ self.iteration-1,
self.max_iteration,
- "{:.3f} s/it".format(t),
+ "{:.3f}".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)
+ string = self.objective_to_string()
+ out = "{:>9} {:>10} {:>13} {}".format(*el[:-1] , string)
return out
+
+ def objective_to_string(self):
+ el = self.get_last_objective()[0]
+ if type(el) == list:
+ string = functools.reduce(lambda x,y: x+' {:>13.5e}'.format(y), el[:-1],'')
+ string += '{:>15.5e}'.format(el[-1])
+ else:
+ string = "{:>20.5e}".format(el)
+ return string
+ def verbose_header(self):
+ el = 1
+ if type(el) == list:
+ out = "{:>9} {:>10} {:>13} {:>13} {:>13} {:>15}\n".format('Iter',
+ 'Max Iter',
+ 'Time/Iter',
+ 'Primal' , 'Dual', 'Primal-Dual')
+ out += "{:>9} {:>10} {:>13} {:>13} {:>13} {:>15}".format('',
+ '',
+ '[s]',
+ 'Objective' , 'Objective', 'Gap')
+ else:
+ out = "{:>9} {:>10} {:>13} {:>20}".format('Iter',
+ 'Max Iter',
+ 'Time/Iter',
+ 'Objective')
+ out += "{:>9} {:>10} {:>13} {:>20}".format('',
+ '',
+ '[s]',
+ '')
+ return out \ No newline at end of file