Commit e7df2052 authored by Martin Reinecke's avatar Martin Reinecke

cleanup

parent 9b51b096
......@@ -81,9 +81,6 @@ if __name__ == '__main__':
d_space = R.target[0]
lamb = R.chain(sky)
mock_position = ift.from_random('normal', domain)
#ift.extra.check_value_gradient_consistency2(lamb, mock_position)
#testl = GaussianEnergy2(None, M)
#ift.extra.check_value_gradient_metric_consistency2(testl, sky(mock_position))
data = lamb(mock_position)
data = np.random.poisson(data.to_global_data().astype(np.float64))
data = ift.Field.from_global_data(d_space, data)
......@@ -98,7 +95,6 @@ if __name__ == '__main__':
# Minimize the Hamiltonian
H = ift.Hamiltonian(likelihood)
H = ift.EnergyAdapter(position, H)
#ift.extra.check_value_gradient_consistency(H)
H = H.make_invertible(ic_cg)
H, convergence = minimizer(H)
......
......@@ -25,6 +25,7 @@ def get_random_LOS(n_los):
ends = list(np.random.uniform(0, 1, (n_los, 2)).T)
return starts, ends
if __name__ == '__main__':
# FIXME description of the tutorial
np.random.seed(42)
......@@ -40,11 +41,13 @@ if __name__ == '__main__':
power_space = A.target[0]
power_distributor = ift.PowerDistributor(harmonic_space, power_space)
dummy = ift.Field.from_random('normal', harmonic_space)
domain = ift.MultiDomain.union((A.domain, ift.MultiDomain.make({'xi': harmonic_space})))
domain = ift.MultiDomain.union(
(A.domain, ift.MultiDomain.make({'xi': harmonic_space})))
correlated_field = ht.chain(power_distributor.chain(A)*ift.FieldAdapter(domain, "xi"))
correlated_field = ht.chain(
power_distributor.chain(A)*ift.FieldAdapter(domain, "xi"))
# 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
signal = correlated_field.positive_tanh()
......@@ -65,7 +68,8 @@ if __name__ == '__main__':
data = signal_response(MOCK_POSITION) + N.draw_sample()
# set up model likelihood
likelihood = ift.GaussianEnergy(mean=data, covariance=N).chain(signal_response)
likelihood = ift.GaussianEnergy(
mean=data, covariance=N).chain(signal_response)
# set up minimization and inversion schemes
ic_cg = ift.GradientNormController(iteration_limit=10)
......
......@@ -127,6 +127,5 @@ class _OpSum(_CombinedOperator):
self._domain = domain_union([op.domain for op in self._ops])
self._target = domain_union([op.target for op in self._ops])
def __call__(self, x):
raise NotImplementedError
......@@ -54,19 +54,20 @@ class Energy_Tests(unittest.TestCase):
s = ht(ift.makeOp(A)(xi0_var))
R = ift.ScalingOperator(10., space)
def d_model(inp):
def d_model():
if nonlinearity == "":
return R(ht(ift.makeOp(A)(inp)))
return R.chain(ht.chain(ift.makeOp(A)))
else:
tmp = ht(ift.makeOp(A)(inp))
nonlin = getattr(tmp, nonlinearity)
return R(nonlin())
d = d_model(xi0) + n
tmp = ht.chain(ift.makeOp(A))
nonlin = getattr(tmp, nonlinearity)()
return R.chain(nonlin)
d = d_model()(xi0) + n
if noise == 1:
N = None
energy = lambda inp: ift.GaussianEnergy(d, N)(d_model(inp))
energy = ift.GaussianEnergy(d, N).chain(d_model())
if nonlinearity == "":
ift.extra.check_value_gradient_metric_consistency(
energy, xi0, ntries=10)
......
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