def show_list(exprs, name): names = ['%s_%i' % (name, i + 1) for i in range(len(exprs))] assert len(exprs) == len(names) body = r'\\'.join([ mk_expr(expr.simplify(), name, True) for expr, name in zip(exprs, names) ]) return disp.Math(mk_align(body))
def evidence_report(self, sdigits=4): if misc.is_notebook(): ipd.display(ipd.Markdown("**Evidence report:**")) out = r"\log\mathcal{{ Z }} = " out += q2tex(self.log_evidence, self.log_evidence_err) ipd.display(ipd.Math(out)) else: print('Evidence report') print('logZ =', self.log_evidence, '±', self.log_evidence_err)
def _print_plain_override_for_ndarray(arg, p, cycle): """caller for pretty, for use in IPython 0.11""" import IPython.display as d if isinstance(arg, numpy.ndarray): if hasattr(arg.dtype, 'fields') and arg.dtype.fields is not None: mkd = 'structured array with fields: ' + ', '.join( [j[0] for j in arg.dtype.descr]) else: mkd = "array" if any(numpy.array(arg.shape) > 20): print("Matrix is too large (" + 'x'.join([str(j) for j in arg.shape]) + ") -- using text numpy print") print(arg) elif len(arg.shape) == 2: math_str = render_matrix(arg) d.display( d.Markdown("**numpy 2D " + mkd + "** represented as a matrix:")) d.display(d.Math(math_str)) elif len(arg.shape) == 1: d.display( d.Markdown("**numpy 1D " + mkd + "** represented as a row vector:")) d.display(d.Math(render_matrix(arg.reshape(1, -1)))) elif len(arg.shape) == 3: d.display( d.Markdown("***numpy 3D " + mkd + ",*** represented as a series of matrices:")) math_str = r'\begin{bmatrix}' + '\n' for j in range(arg.shape[0]): math_str += '\\text{Select slice with outermost dimension set to %d}' % j math_str += r'\\' + '\n' math_str += render_matrix(arg[j, :, :]) math_str += r'\\' + '\n' math_str += r'\end{bmatrix}' + '\n' d.display(d.Math(math_str)) elif len(arg.shape) > 3: d.display( d.Markdown( "***numpy ND array*** $N>3$ dimensions ($" + r'\times'.join(map(str, arg.shape)) + "$), so I'm just giving the text representation:")) d.display(str(arg))
def posterior_report(self, sdigits=2, **kwargs): """ Displays the best fit values and 1-sigma errors for each active parameter. Also produces a corner plot of the samples, which is saved to the run directory. If running on a jupyter-notebook, a nice LaTeX display is used, and the plot is shown. Parameters ---------- sdigits : int The number of significant digits to be used """ out = '' for param, pdict in self.posterior_summary.items(): if misc.is_notebook(): # Extracts LaTeX representation from astropy unit object out += r"\\ \text{{ {0}: }}\; ".format(param) out += q2tex(*map(pdict.get, ['median', 'errup', 'errlo']), sdigits=sdigits) out += r"\\" else: out += r"{0}: ".format(param) md, errlo, errup = map(pdict.get, ['median', 'errlo', 'errup']) if isinstance(md, apu.Quantity): unit = str(md.unit) md, errlo, errup = map(lambda x: x.value, [md, errlo, errup]) else: unit = "" v, l, u = misc.adjust_error_intervals(md, errlo, errup, sdigits=sdigits) out += r'{0} (-{1})/(+{2}) {3}\n'.format(v, l, u, unit) fig = self.corner_plot(**kwargs) fig.savefig(os.path.join(self._run_directory, 'corner_plot.pdf')) if misc.is_notebook(): ipd.display(ipd.Markdown("\n**Posterior report:**")) plt.show() ipd.display(ipd.Math(out)) else: # Restores linebreaks and prints print('Posterior report') print(out.replace(r'\n', '\n'))
def printsp(x, n): return disp.Math('%s = %s' % (n, sp.latex(x)))
def show(expr, name): return disp.Math(name + '=' + sp.latex(expr))
def show_list(exprs, names): assert len(exprs) == len(names) body = r'\\'.join( [mk_expr(expr, name, True) for expr, name in zip(exprs, names)]) return disp.Math(mk_align(body))
def show_add(exprs, name): body = name + '=&' + r'\\ &+ '.join([sp.latex(expr) for expr in exprs]) return disp.Math(mk_align(body))
def show(expr, name): return disp.Math(mk_expr(expr, name))
def disp(latex_string): IPd.display(IPd.Math(latex_string))