Commit 38c6bd82 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

improve demo; variance sampling still disabled

parent 911a5f88
Pipeline #19503 passed with stage
in 4 minutes and 48 seconds
...@@ -55,9 +55,10 @@ if __name__ == "__main__": ...@@ -55,9 +55,10 @@ if __name__ == "__main__":
ss = fft.adjoint_times(sh) ss = fft.adjoint_times(sh)
# Choosing the measurement instrument # Choosing the measurement instrument
# Instrument = SmoothingOperator(s_space, sigma=0.05) #Instrument = ift.FFTSmoothingOperator(s_space, sigma=0.05)
Instrument = ift.DiagonalOperator(ift.Field.ones(s_space)) diag = ift.Field.ones(s_space)
# Instrument._diagonal.val[200:400, 200:400] = 0 #diag.val[20:80, 20:80] = 0
Instrument = ift.DiagonalOperator(diag.weight(-1))
# Adding a harmonic transformation to the instrument # Adding a harmonic transformation to the instrument
R = AdjointFFTResponse(fft, Instrument) R = AdjointFFTResponse(fft, Instrument)
...@@ -77,6 +78,8 @@ if __name__ == "__main__": ...@@ -77,6 +78,8 @@ if __name__ == "__main__":
ctrl = ift.GradientNormController(verbose=True,tol_abs_gradnorm=0.1) ctrl = ift.GradientNormController(verbose=True,tol_abs_gradnorm=0.1)
inverter = ift.ConjugateGradient(controller=ctrl) inverter = ift.ConjugateGradient(controller=ctrl)
controller = ift.GradientNormController(verbose=True,tol_abs_gradnorm=0.1)
minimizer = ift.RelaxedNewton(controller=controller)
# Setting starting position # Setting starting position
m0 = ift.Field.zeros(h_space) m0 = ift.Field.zeros(h_space)
...@@ -85,16 +88,18 @@ if __name__ == "__main__": ...@@ -85,16 +88,18 @@ if __name__ == "__main__":
inverter=inverter) inverter=inverter)
D0 = energy.curvature D0 = energy.curvature
# Solving the problem analytically m = minimizer(energy)[0].position
m0 = D0.inverse_times(j) ift.plotting.plot(ss, name="signal.pdf", colormap="Planck-like")
ift.plotting.plot(fft.inverse_times(m), name="m.pdf", colormap="Planck-like")
sample_variance = ift.Field.zeros(sh.domain)
sample_mean = ift.Field.zeros(sh.domain)
# sampling the uncertainty map # sampling the uncertainty map
n_samples = 50 #sample_variance = ift.Field.zeros(sh.domain)
for i in range(n_samples): #sample_mean = ift.Field.zeros(sh.domain)
sample = fft(ift.sugar.generate_posterior_sample(0., D0))
sample_variance += sample**2 #n_samples = 50
sample_mean += sample #for i in range(n_samples):
variance = (sample_variance - sample_mean**2)/n_samples # sample = ift.sugar.generate_posterior_sample(0., D0)
# sample_variance += sample**2
# sample_mean += sample
#variance = sample_variance/n_samples - (sample_mean/n_samples)**2
#ift.plotting.plot(fft.inverse_times(variance), name="variance.pdf", colormap="Planck-like")
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