Commit 2547e3d0 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'nicer_plots_demo3' into 'NIFTy_5'

Nicer plots demo3

See merge request ift/nifty-dev!93
parents 63789fe6 77c928e1
...@@ -41,11 +41,12 @@ if __name__ == '__main__': ...@@ -41,11 +41,12 @@ 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( domain = ift.MultiDomain.union((A.domain,
(A.domain, ift.MultiDomain.make({'xi': harmonic_space}))) ift.MultiDomain.make({
'xi': harmonic_space
})))
correlated_field = ht( correlated_field = ht(power_distributor(A)*ift.FieldAdapter(domain, "xi"))
power_distributor(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)
...@@ -54,8 +55,7 @@ if __name__ == '__main__': ...@@ -54,8 +55,7 @@ if __name__ == '__main__':
# 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)
R = ift.LOSResponse(position_space, starts=LOS_starts, R = ift.LOSResponse(position_space, starts=LOS_starts, ends=LOS_ends)
ends=LOS_ends)
# build signal response model and model likelihood # build signal response model and model likelihood
signal_response = R(signal) signal_response = R(signal)
# specify noise # specify noise
...@@ -68,8 +68,7 @@ if __name__ == '__main__': ...@@ -68,8 +68,7 @@ if __name__ == '__main__':
data = signal_response(MOCK_POSITION) + N.draw_sample() data = signal_response(MOCK_POSITION) + N.draw_sample()
# set up model likelihood # set up model likelihood
likelihood = ift.GaussianEnergy( likelihood = ift.GaussianEnergy(mean=data, covariance=N)(signal_response)
mean=data, covariance=N)(signal_response)
# set up minimization and inversion schemes # set up minimization and inversion schemes
ic_sampling = ift.GradientNormController(iteration_limit=100) ic_sampling = ift.GradientNormController(iteration_limit=100)
...@@ -83,17 +82,18 @@ if __name__ == '__main__': ...@@ -83,17 +82,18 @@ if __name__ == '__main__':
INITIAL_POSITION = ift.from_random('normal', domain) INITIAL_POSITION = ift.from_random('normal', domain)
position = INITIAL_POSITION position = INITIAL_POSITION
ift.plot(signal(MOCK_POSITION), title='ground truth') ift.plot(signal(MOCK_POSITION), title='Ground Truth')
ift.plot(R.adjoint_times(data), title='data') ift.plot(R.adjoint_times(data), title='Data')
ift.plot([A(MOCK_POSITION)], title='power') ift.plot([A(MOCK_POSITION)], title='Power Spectrum')
ift.plot_finish(nx=3, xsize=16, ysize=5, title="setup", name="setup.png") ift.plot_finish(ny=1, nx=3, xsize=24, ysize=6, name="setup.png")
# number of samples used to estimate the KL # number of samples used to estimate the KL
N_samples = 20 N_samples = 20
for i in range(2): for i in range(2):
metric = H(ift.Linearization.make_var(position)).metric metric = H(ift.Linearization.make_var(position)).metric
samples = [metric.draw_sample(from_inverse=True) samples = [
for _ in range(N_samples)] metric.draw_sample(from_inverse=True) for _ in range(N_samples)
]
KL = ift.SampledKullbachLeiblerDivergence(H, samples) KL = ift.SampledKullbachLeiblerDivergence(H, samples)
KL = ift.EnergyAdapter(position, KL) KL = ift.EnergyAdapter(position, KL)
...@@ -102,15 +102,16 @@ if __name__ == '__main__': ...@@ -102,15 +102,16 @@ if __name__ == '__main__':
ift.plot(signal(position), title="reconstruction") ift.plot(signal(position), title="reconstruction")
ift.plot([A(position), A(MOCK_POSITION)], title="power") ift.plot([A(position), A(MOCK_POSITION)], title="power")
ift.plot_finish(nx=2, xsize=12, ysize=6, title="loop", name="loop.png") ift.plot_finish(ny=1, ysize=6, xsize=16, name="loop.png")
sc = ift.StatCalculator() sc = ift.StatCalculator()
for sample in samples: for sample in samples:
sc.add(signal(sample+position)) sc.add(signal(sample + position))
ift.plot(sc.mean, title="mean") ift.plot(sc.mean, title="Posterior Mean")
ift.plot(ift.sqrt(sc.var), title="std deviation") ift.plot(ift.sqrt(sc.var), title="Posterior Standard Deviation")
powers = [A(s+position) for s in samples] powers = [A(s + position) for s in samples]
ift.plot([A(position), A(MOCK_POSITION)]+powers, title="power") ift.plot(
ift.plot_finish(nx=3, xsize=16, ysize=5, title="results", [A(position), A(MOCK_POSITION)] + powers,
name="results.png") title="Sampled Posterior Power Spectrum")
ift.plot_finish(ny=1, nx=3, xsize=24, ysize=6, name="results.png")
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