Commit 606523c0 authored by Philipp Arras's avatar Philipp Arras Committed by Martin Reinecke
Browse files

Add some reprs

parent 30df8975
...@@ -73,3 +73,7 @@ class KL_Energy(Energy): ...@@ -73,3 +73,7 @@ class KL_Energy(Energy):
@property @property
def samples(self): def samples(self):
return self._samples return self._samples
def __repr__(self):
return 'KL ({} samples):\n'.format(len(
self._samples)) + utilities.indent(self._ham.__repr__())
...@@ -168,6 +168,11 @@ class Hamiltonian(EnergyOperator): ...@@ -168,6 +168,11 @@ class Hamiltonian(EnergyOperator):
self._ic_samp, prx.metric.inverse) self._ic_samp, prx.metric.inverse)
return (lhx+prx).add_metric(mtr) 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): class SampledKullbachLeiblerDivergence(EnergyOperator):
def __init__(self, h, res_samples): def __init__(self, h, res_samples):
......
...@@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function ...@@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function
import numpy as np import numpy as np
from ..compat import * from ..compat import *
from ..utilities import NiftyMetaBase from ..utilities import NiftyMetaBase, indent
class Operator(NiftyMetaBase()): class Operator(NiftyMetaBase()):
...@@ -177,6 +177,11 @@ class _OpChain(_CombinedOperator): ...@@ -177,6 +177,11 @@ class _OpChain(_CombinedOperator):
return x return x
def __repr__(self):
subs = "\n".join(sub.__repr__() for sub in self._ops)
return "_OpChain:\n" + indent(subs)
class _OpProd(Operator): class _OpProd(Operator):
def __init__(self, op1, op2): def __init__(self, op1, op2):
from ..sugar import domain_union from ..sugar import domain_union
...@@ -205,6 +210,11 @@ class _OpProd(Operator): ...@@ -205,6 +210,11 @@ class _OpProd(Operator):
return lin1.new(lin1._val*lin2._val, op(x.jac)) 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): class _OpSum(Operator):
def __init__(self, op1, op2): def __init__(self, op1, op2):
from ..sugar import domain_union from ..sugar import domain_union
...@@ -231,3 +241,7 @@ class _OpSum(Operator): ...@@ -231,3 +241,7 @@ class _OpSum(Operator):
if lin1._metric is not None and lin2._metric is not None: if lin1._metric is not None and lin2._metric is not None:
res = res.add_metric(lin1._metric + lin2._metric) res = res.add_metric(lin1._metric + lin2._metric)
return res return res
def __repr__(self):
subs = "\n".join(sub.__repr__() for sub in (self._op1, self._op2))
return "_OpSum:\n"+indent(subs)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment