diff --git a/nifty5/minimization/kl_energy.py b/nifty5/minimization/kl_energy.py index 0e8155f9e3d4bd36c40433bdb94a61459117010e..7d4abecb3edbab3b077c8a4e4e96c0d6f4251d19 100644 --- a/nifty5/minimization/kl_energy.py +++ b/nifty5/minimization/kl_energy.py @@ -73,3 +73,7 @@ class KL_Energy(Energy): @property def samples(self): return self._samples + + def __repr__(self): + return 'KL ({} samples):\n'.format(len( + self._samples)) + utilities.indent(self._ham.__repr__()) diff --git a/nifty5/operators/energy_operators.py b/nifty5/operators/energy_operators.py index 9653aa94ebd1e8720b768864175baf879df1c4ac..3b2e6cb55df82edbdb673c65f5404e64f7a83045 100644 --- a/nifty5/operators/energy_operators.py +++ b/nifty5/operators/energy_operators.py @@ -168,6 +168,11 @@ class Hamiltonian(EnergyOperator): self._ic_samp, prx.metric.inverse) return (lhx+prx).add_metric(mtr) + def __repr__(self): + subs = 'Likelihood:\n{}'.format(utilities.indent(self._lh.__repr__())) + subs += '\nPrior: Quadratic{}'.format(self._lh.domain.keys()) + return 'Hamiltonian:\n' + utilities.indent(subs) + class SampledKullbachLeiblerDivergence(EnergyOperator): def __init__(self, h, res_samples): diff --git a/nifty5/operators/operator.py b/nifty5/operators/operator.py index efb36e79f6f490564a524e721533ef9b52f724ea..4a11dfb50a34fbe037cc8e34f828fef9528f2349 100644 --- a/nifty5/operators/operator.py +++ b/nifty5/operators/operator.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function import numpy as np from ..compat import * -from ..utilities import NiftyMetaBase +from ..utilities import NiftyMetaBase, indent class Operator(NiftyMetaBase()): @@ -177,6 +177,11 @@ class _OpChain(_CombinedOperator): return x + def __repr__(self): + subs = "\n".join(sub.__repr__() for sub in self._ops) + return "_OpChain:\n" + indent(subs) + + class _OpProd(Operator): def __init__(self, op1, op2): from ..sugar import domain_union @@ -205,6 +210,11 @@ class _OpProd(Operator): return lin1.new(lin1._val*lin2._val, op(x.jac)) + def __repr__(self): + subs = "\n".join(sub.__repr__() for sub in (self._op1, self._op2)) + return "_OpProd:\n"+indent(subs) + + class _OpSum(Operator): def __init__(self, op1, op2): from ..sugar import domain_union @@ -231,3 +241,7 @@ class _OpSum(Operator): if lin1._metric is not None and lin2._metric is not None: res = res.add_metric(lin1._metric + lin2._metric) return res + + def __repr__(self): + subs = "\n".join(sub.__repr__() for sub in (self._op1, self._op2)) + return "_OpSum:\n"+indent(subs)