From 0e0220921f8b1b0b3b7179a10de1dd8af56758e7 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Fri, 5 Dec 2014 11:13:18 +0000 Subject: [PATCH] [html repr] included css styling for html print outs --- GPy/core/model.py | 6 +++++- GPy/core/parameterization/param.py | 18 ++++++++++++------ GPy/core/parameterization/parameterized.py | 22 +++++++++++++++------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/GPy/core/model.py b/GPy/core/model.py index 67adecc6..4b569f98 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -400,7 +400,11 @@ class Model(Parameterized): ['Log-likelihood', '{}
'.format(float(self.log_likelihood()))], ["Number of Parameters", '{}
'.format(self.size)]] from operator import itemgetter - to_print = [""] + ["{}: {}".format(name, detail) for name, detail in model_details] + ["
Parameters:"] + to_print = ["""\n"""] + ["

"] + ["{}: {}".format(name, detail) for name, detail in model_details] + ["

"] to_print.append(super(Model, self)._repr_html_()) return "\n".join(to_print) diff --git a/GPy/core/parameterization/param.py b/GPy/core/parameterization/param.py index c7d6be5d..78bc4fa2 100644 --- a/GPy/core/parameterization/param.py +++ b/GPy/core/parameterization/param.py @@ -264,15 +264,21 @@ class Param(Parameterizable, ObsAr): ties = [' '.join(map(lambda x: x, t)) for t in ties] header_format = """ - {i} - {x} - {c} - {p} - {t} + {i} + {x} + {c} + {p} + {t} """ header = header_format.format(x=self.hierarchy_name(), c=__constraints_name__, i=__index_name__, t=__tie_name__, p=__priors_name__) # nice header for printing if not ties: ties = itertools.cycle(['']) - return "\n".join([''] + [header] + ["".format(x=x, c=" ".join(map(str, c)), p=" ".join(map(str, p)), t=(t or ''), i=i) for i, x, c, t, p in itertools.izip(indices, vals, constr_matrix, ties, prirs)] + ["
{i}{x}{c}{p}{t}
"]) + return "\n".join([""""""] + [''] + [header] + ["".format(x=x, c=" ".join(map(str, c)), p=" ".join(map(str, p)), t=(t or ''), i=i) for i, x, c, t, p in itertools.izip(indices, vals, constr_matrix, ties, prirs)] + ["
{i}{x}{c}{p}{t}
"]) def __str__(self, constr_matrix=None, indices=None, prirs=None, ties=None, lc=None, lx=None, li=None, lp=None, lt=None, only_name=False): filter_ = self._current_slice_ diff --git a/GPy/core/parameterization/parameterized.py b/GPy/core/parameterization/parameterized.py index 897c53e3..ef44cfa9 100644 --- a/GPy/core/parameterization/parameterized.py +++ b/GPy/core/parameterization/parameterized.py @@ -377,7 +377,7 @@ class Parameterized(Parameterizable): cl = max([len(str(x)) if x else 0 for x in constrs + ["Constraint"]]) tl = max([len(str(x)) if x else 0 for x in ts + ["Tied to"]]) pl = max([len(str(x)) if x else 0 for x in prirs + ["Prior"]]) - format_spec = "{{name:<{0}s}}{{desc:>{1}s}}{{const:^{2}s}}{{pri:^{3}s}}{{t:^{4}s}}".format(nl, sl, cl, pl, tl) + format_spec = "{{name:<{0}s}}{{desc:>{1}s}}{{const:^{2}s}}{{pri:^{3}s}}{{t:^{4}s}}".format(nl, sl, cl, pl, tl) to_print = [] for n, d, c, t, p in itertools.izip(names, desc, constrs, ts, prirs): to_print.append(format_spec.format(name=n, desc=d, const=c, t=t, pri=p)) @@ -385,13 +385,21 @@ class Parameterized(Parameterizable): if header: header = """ - {name} - Value - Constraint - Prior - Tied to""".format(name=name) + {name} + Value + Constraint + Prior + Tied to +""".format(name=name) to_print.insert(0, header) - return '' + '\n'.format(sep).join(to_print) + '\n
' + style = """""" + return style + '\n' + '' + '\n'.format(sep).join(to_print) + '\n
' def __str__(self, header=True): name = adjust_name_for_printing(self.name) + "."