Commit 9b51b096 authored by Martin Reinecke's avatar Martin Reinecke

make third demo work

parent 08e0ae66
...@@ -40,13 +40,14 @@ if __name__ == '__main__': ...@@ -40,13 +40,14 @@ if __name__ == '__main__':
power_space = A.target[0] power_space = A.target[0]
power_distributor = ift.PowerDistributor(harmonic_space, power_space) power_distributor = ift.PowerDistributor(harmonic_space, power_space)
dummy = ift.Field.from_random('normal', harmonic_space) dummy = ift.Field.from_random('normal', harmonic_space)
domain = ift.MultiDomain.union((A.domain, ift.MultiDomain.make({'xi': harmonic_space})))
correlated_field = lambda inp: ht(power_distributor(A(inp))*inp["xi"]) correlated_field = ht.chain(power_distributor.chain(A)*ift.FieldAdapter(domain, "xi"))
# alternatively to the block above one can do: # alternatively to the block above one can do:
#correlated_field = ift.CorrelatedField(position_space, A) #correlated_field = ift.CorrelatedField(position_space, A)
# apply some nonlinearity # apply some nonlinearity
signal = lambda inp: correlated_field(inp).positive_tanh() signal = correlated_field.positive_tanh()
# Building the Line of Sight response # Building the Line of Sight response
LOS_starts, LOS_ends = get_random_LOS(100) LOS_starts, LOS_ends = get_random_LOS(100)
...@@ -60,7 +61,6 @@ if __name__ == '__main__': ...@@ -60,7 +61,6 @@ if __name__ == '__main__':
N = ift.ScalingOperator(noise, data_space) N = ift.ScalingOperator(noise, data_space)
# generate mock data # generate mock data
domain = ift.MultiDomain.union((A.domain, ift.MultiDomain.make({'xi': harmonic_space})))
MOCK_POSITION = ift.from_random('normal', domain) MOCK_POSITION = ift.from_random('normal', domain)
data = signal_response(MOCK_POSITION) + N.draw_sample() data = signal_response(MOCK_POSITION) + N.draw_sample()
......
...@@ -124,6 +124,7 @@ class AmplitudeModel(Operator): ...@@ -124,6 +124,7 @@ class AmplitudeModel(Operator):
self._domain = MultiDomain.make({keys[0]: dof_space, self._domain = MultiDomain.make({keys[0]: dof_space,
keys[1]: param_space}) keys[1]: param_space})
self._target = self._exp_transform.target
kern = lambda k: _ceps_kernel(dof_space, k, ceps_a, ceps_k) kern = lambda k: _ceps_kernel(dof_space, k, ceps_a, ceps_k)
cepstrum = create_cepstrum_amplitude_field(dof_space, kern) cepstrum = create_cepstrum_amplitude_field(dof_space, kern)
...@@ -138,11 +139,3 @@ class AmplitudeModel(Operator): ...@@ -138,11 +139,3 @@ class AmplitudeModel(Operator):
linear_spec = self._slope(phi) linear_spec = self._slope(phi)
loglog_spec = smooth_spec + linear_spec loglog_spec = smooth_spec + linear_spec
return self._exp_transform((0.5*loglog_spec).exp()) return self._exp_transform((0.5*loglog_spec).exp())
@property
def domain(self):
return self._domain
@property
def target(self):
return self._exp_transform.target
...@@ -43,8 +43,7 @@ class Linearization(object): ...@@ -43,8 +43,7 @@ class Linearization(object):
def __getitem__(self, name): def __getitem__(self, name):
from .operators.field_adapter import FieldAdapter from .operators.field_adapter import FieldAdapter
dom = self._val[name].domain return Linearization(self._val[name], FieldAdapter(self.domain, name))
return Linearization(self._val[name], FieldAdapter(dom, name))
def __neg__(self): def __neg__(self):
return Linearization( return Linearization(
......
...@@ -8,16 +8,10 @@ from ..multi.multi_field import MultiField ...@@ -8,16 +8,10 @@ from ..multi.multi_field import MultiField
class FieldAdapter(LinearOperator): class FieldAdapter(LinearOperator):
def __init__(self, dom, name_dom): def __init__(self, dom, name_dom):
self._domain = MultiDomain.make({name_dom: dom}) self._domain = MultiDomain.make(dom)
self._target = dom self._smalldom = MultiDomain.make({name_dom: self._domain[name_dom]})
self._name = name_dom
@property self._target = dom[name_dom]
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property @property
def capability(self): def capability(self):
...@@ -27,5 +21,6 @@ class FieldAdapter(LinearOperator): ...@@ -27,5 +21,6 @@ class FieldAdapter(LinearOperator):
self._check_input(x, mode) self._check_input(x, mode)
if mode == self.TIMES: if mode == self.TIMES:
return x.values()[0] return x[self._name]
return MultiField(self._domain, (x,)) tmp = MultiField(self._smalldom, (x,))
return tmp.unite(MultiField.full(self._domain, 0.))
...@@ -10,12 +10,14 @@ class Operator(NiftyMetaBase()): ...@@ -10,12 +10,14 @@ class Operator(NiftyMetaBase()):
domain, and can also provide the Jacobian. domain, and can also provide the Jacobian.
""" """
@property
def domain(self): def domain(self):
"""DomainTuple or MultiDomain : the operator's input domain """DomainTuple or MultiDomain : the operator's input domain
The domain on which the Operator's input Field lives.""" The domain on which the Operator's input Field lives."""
return self._domain return self._domain
@property
def target(self): def target(self):
"""DomainTuple or MultiDomain : the operator's output domain """DomainTuple or MultiDomain : the operator's output domain
...@@ -27,6 +29,11 @@ class Operator(NiftyMetaBase()): ...@@ -27,6 +29,11 @@ class Operator(NiftyMetaBase()):
return NotImplemented return NotImplemented
return _OpChain.make((self, x)) return _OpChain.make((self, x))
def __mul__(self, x):
if not isinstance(x, Operator):
return NotImplemented
return _OpProd.make((self, x))
def chain(self, x): def chain(self, x):
res = self.__matmul__(x) res = self.__matmul__(x)
if res == NotImplemented: if res == NotImplemented:
...@@ -110,7 +117,8 @@ class _OpProd(_CombinedOperator): ...@@ -110,7 +117,8 @@ class _OpProd(_CombinedOperator):
self._target = self._ops[0].target self._target = self._ops[0].target
def __call__(self, x): def __call__(self, x):
return my_prod(map(lambda op: op(x) for op in self._ops)) from ..utilities import my_product
return my_product(map(lambda op: op(x), self._ops))
class _OpSum(_CombinedOperator): class _OpSum(_CombinedOperator):
......
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