mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-10 04:22:38 +02:00
[html repr] included css styling for html print outs
This commit is contained in:
parent
4fc006f45d
commit
0e0220921f
3 changed files with 32 additions and 14 deletions
|
|
@ -400,7 +400,11 @@ class Model(Parameterized):
|
||||||
['<b>Log-likelihood</b>', '{}<br>'.format(float(self.log_likelihood()))],
|
['<b>Log-likelihood</b>', '{}<br>'.format(float(self.log_likelihood()))],
|
||||||
["<b>Number of Parameters</b>", '{}<br>'.format(self.size)]]
|
["<b>Number of Parameters</b>", '{}<br>'.format(self.size)]]
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
to_print = [""] + ["{}: {}".format(name, detail) for name, detail in model_details] + ["<br><b>Parameters</b>:"]
|
to_print = ["""<style type="text/css">
|
||||||
|
.pd{
|
||||||
|
font-family:"Courier New", Courier, monospace !important;
|
||||||
|
}
|
||||||
|
</style>\n"""] + ["<p class=pd>"] + ["{}: {}".format(name, detail) for name, detail in model_details] + ["</p>"]
|
||||||
to_print.append(super(Model, self)._repr_html_())
|
to_print.append(super(Model, self)._repr_html_())
|
||||||
return "\n".join(to_print)
|
return "\n".join(to_print)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,15 +264,21 @@ class Param(Parameterizable, ObsAr):
|
||||||
ties = [' '.join(map(lambda x: x, t)) for t in ties]
|
ties = [' '.join(map(lambda x: x, t)) for t in ties]
|
||||||
header_format = """
|
header_format = """
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>{i}</b></td>
|
<th><b>{i}</b></th>
|
||||||
<td><b>{x}</b></td>
|
<th><b>{x}</b></th>
|
||||||
<td><b>{c}</b></td>
|
<th><b>{c}</b></th>
|
||||||
<td><b>{p}</b></td>
|
<th><b>{p}</b></th>
|
||||||
<td><b>{t}</b></td>
|
<th><b>{t}</b></th>
|
||||||
</tr>"""
|
</tr>"""
|
||||||
header = header_format.format(x=self.hierarchy_name(), c=__constraints_name__, i=__index_name__, t=__tie_name__, p=__priors_name__) # nice header for printing
|
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([''])
|
if not ties: ties = itertools.cycle([''])
|
||||||
return "\n".join(['<table>'] + [header] + ["<tr><td>{i}</td><td align=\"right\">{x}</td><td>{c}</td><td>{p}</td><td>{t}</td></tr>".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)] + ["</table>"])
|
return "\n".join(["""<style type="text/css">
|
||||||
|
.tg {border-collapse:collapse;border-spacing:0;border-color:#999;}
|
||||||
|
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:2px 3px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#444;background-color:#F7FDFA;}
|
||||||
|
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:2px 3px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#fff;background-color:#26ADE4;}
|
||||||
|
.tg .tg-left{font-family:"Courier New", Courier, monospace !important;;text-align:left}
|
||||||
|
.tg .tg-right{font-family:"Courier New", Courier, monospace !important;;text-align:right}
|
||||||
|
</style>"""] + ['<table class="tg">'] + [header] + ["<tr><td class=tg-left>{i}</td><td class=tg-right>{x}</td><td class=tg-left>{c}</td><td class=tg-left>{p}</td><td class=tg-left>{t}</td></tr>".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)] + ["</table>"])
|
||||||
|
|
||||||
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):
|
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_
|
filter_ = self._current_slice_
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,7 @@ class Parameterized(Parameterizable):
|
||||||
cl = max([len(str(x)) if x else 0 for x in constrs + ["Constraint"]])
|
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"]])
|
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"]])
|
pl = max([len(str(x)) if x else 0 for x in prirs + ["Prior"]])
|
||||||
format_spec = "<tr><td>{{name:<{0}s}}</td><td align=\"right\">{{desc:>{1}s}}</td><td>{{const:^{2}s}}</td><td>{{pri:^{3}s}}</td><td>{{t:^{4}s}}</td></tr>".format(nl, sl, cl, pl, tl)
|
format_spec = "<tr><td class=tg-left>{{name:<{0}s}}</td><td class=tg-right>{{desc:>{1}s}}</td><td class=tg-left>{{const:^{2}s}}</td><td class=tg-left>{{pri:^{3}s}}</td><td class=tg-left>{{t:^{4}s}}</td></tr>".format(nl, sl, cl, pl, tl)
|
||||||
to_print = []
|
to_print = []
|
||||||
for n, d, c, t, p in itertools.izip(names, desc, constrs, ts, prirs):
|
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))
|
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:
|
if header:
|
||||||
header = """
|
header = """
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>{name}</b>
|
<th><b>{name}</b></th>
|
||||||
<td><b>Value</b></td>
|
<th><b>Value</b></th>
|
||||||
<td><b>Constraint</b></td>
|
<th><b>Constraint</b></th>
|
||||||
<td><b>Prior</b></td>
|
<th><b>Prior</b></th>
|
||||||
<td><b>Tied to</b></td>""".format(name=name)
|
<th><b>Tied to</b></th>
|
||||||
|
</tr>""".format(name=name)
|
||||||
to_print.insert(0, header)
|
to_print.insert(0, header)
|
||||||
return '<table>' + '\n'.format(sep).join(to_print) + '\n</table>'
|
style = """<style type="text/css">
|
||||||
|
.tg {border-collapse:collapse;border-spacing:0;border-color:#999;}
|
||||||
|
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:2px 3px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#444;background-color:#F7FDFA;}
|
||||||
|
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:2px 3px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#fff;background-color:#26ADE4;}
|
||||||
|
.tg .tg-left{font-family:"Courier New", Courier, monospace !important;;text-align:left}
|
||||||
|
.tg .tg-right{font-family:"Courier New", Courier, monospace !important;;text-align:right}
|
||||||
|
</style>"""
|
||||||
|
return style + '\n' + '<table class="tg">' + '\n'.format(sep).join(to_print) + '\n</table>'
|
||||||
|
|
||||||
def __str__(self, header=True):
|
def __str__(self, header=True):
|
||||||
name = adjust_name_for_printing(self.name) + "."
|
name = adjust_name_for_printing(self.name) + "."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue