def perform_inversion(data, init, sigma, vel): op = LymanAlphaHydrogen(domain, parameters_inversion, redshift, redshift, hubble, hubble, vel_pec=vel, codomain=codomain) setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=L2) richardson = RLHydrogen(op) richardson_lucy = Richardson_Lucy(setting, data, init, richardson, m=3) energy = EnergyNorm(sigma) stoprule = (rules.CombineRules( (rules.CountIterations(300), rules.Discrepancy(energy.norm, data, noiselevel=np.sqrt(N_spect), tau=1), rules.RelativeChangeData(energy.norm, data, 0.0001)))) return richardson_lucy.run(stoprule)
def perform_inversion(Probability_data, init): descent = Gradient_Descent(setting, Probability_data, np.log(init), stepsize=0.5, alpha=0.2, penalty=penalty) stoprule = (rules.CombineRules( (rules.CountIterations(500), rules.RelativeChangeData(setting.Hcodomain.norm, Probability_data, 0)))) return descent.run(stoprule)
def perform_inversion(data, init, sigma, vel): C_D = sigma op = LymanAlphaBar(domain, parameters_inversion, redshift, redshift, hubble, hubble, vel, gamma=True, codomain=codomain) setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=L2) solver = IRGN(setting, data, init, C_0, M_0, C_D**2, maxit=15, tol=1e-3, restart=10) energy = EnergyNorm(sigma) stoprule = (rules.CombineRules( (rules.CountIterations(10), rules.Discrepancy(energy.norm, data, noiselevel=np.sqrt(N_spect), tau=1), rules.RelativeChangeData(energy.norm, data, 0.1)))) return solver.run(stoprule)
gfu_noise = ngs.GridFunction(fes_codomain) gfu_noise.Set(gfu_noise_order1) noise = gfu_noise.vec.FV().NumPy() data = exact_data + noise init = 1 + ngs.x**2 init_gfu = ngs.GridFunction(op.fes_domain) init_gfu.Set(init) init_solution = init_gfu.vec.FV().NumPy().copy() init_data = op(init_solution) setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=Sobolev) landweber = Landweber(setting, data, init_solution, stepsize=1) stoprule = (rules.CountIterations(1000) + rules.Discrepancy(setting.Hcodomain.norm, data, noiselevel=setting.Hcodomain.norm(noise), tau=1.1)) reco, reco_data = landweber.run(stoprule) ngs.Draw(exact_solution_coeff, op.fes_domain.mesh, "exact") ngs.Draw(init, op.fes_domain.mesh, "init") # Draw recondtructed solution gfu_reco = ngs.GridFunction(op.fes_domain) gfu_reco.vec.FV().NumPy()[:] = reco coeff_reco = ngs.CoefficientFunction(gfu_reco)
grid = UniformGrid(np.linspace(0, 2 * np.pi, 200)) op = Volterra(grid, exponent=3) exact_solution = np.sin(grid.coords[0]) exact_data = op(exact_solution) noise = 0.03 * op.domain.randn() data = exact_data + noise init = op.domain.ones() setting = HilbertSpaceSetting(op=op, Hdomain=Sobolev, Hcodomain=L2) landweber = Landweber(setting, data, init, stepsize=0.01) stoprule = ( # Landweber is slow, so need to use large number of iterations rules.CountIterations(max_iterations=100000) + rules.Discrepancy( setting.Hcodomain.norm, data, noiselevel=setting.Hcodomain.norm(noise), tau=1.1 ) ) reco, reco_data = landweber.run(stoprule) plt.plot(grid.coords[0], exact_solution.T, label='exact solution') plt.plot(grid.coords[0], reco, label='reco') plt.plot(grid.coords[0], exact_data, label='exact data') plt.plot(grid.coords[0], data, label='data') plt.plot(grid.coords[0], reco_data, label='reco data') plt.legend()
Hdomain=HilbertPullBack(Sobolev(index=2), embedding, inverse='cholesky'), Hcodomain=L2 ) solver = IrgnmCG( setting, data, regpar=1, regpar_step=0.8, init=init, cgpars=dict( tol=1e-8, reltolx=1e-8, reltoly=1e-8 ) ) stoprule = ( rules.CountIterations(100) + rules.Discrepancy( setting.Hcodomain.norm, data, noiselevel=setting.Hcodomain.norm(noise), tau=1.1 ) ) plt.ion() fig, axes = plt.subplots(ncols=3, nrows=2, constrained_layout=True) bars = np.vectorize(lambda ax: cbar.make_axes(ax)[0], otypes=[object])(axes) axes[0, 0].set_title('exact contrast') axes[1, 0].set_title('exact data') axes[0, 1].set_title('reco contrast') axes[1, 1].set_title('reco data')
data = op(exact_solution) + noise plotmeshes(codomain, data=codomain.to_ngs(data))['data'] # --- setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=L2) reco, reco_data = IrgnmCG( setting, data, init=domain.from_ngs(1 + ngs.x + 5 * ngs.x * (1 - ngs.x) * ngs.y * (1 - ngs.y)), regpar=0.1, regpar_step=2 / 3, cgstop=100, ).run( rules.CountIterations(20) + rules.Discrepancy(setting.Hcodomain.norm, data, noiselevel=setting.Hcodomain.norm(noise), tau=1.01)) gfu_reco = op.domain.to_ngs(reco) plots = plotmeshes(domain, reco=gfu_reco, error=cfu_exact_solution - gfu_reco) plots['reco'] # --- plots['error']
level=logging.INFO, format='%(asctime)s %(levelname)s %(name)-20s :: %(message)s') grid = UniformGrid(np.linspace(0, 2 * np.pi, 200)) op = Volterra(grid, exponent=3) exact_solution = np.sin(grid.coords[0]) exact_data = op(exact_solution) noise = 0.03 * op.domain.randn() data = exact_data + noise init = op.domain.ones() setting = HilbertSpaceSetting(op=op, Hdomain=Sobolev(index=2), Hcodomain=L2) solver = IrgnmCG(setting, data, regpar=1, regpar_step=0.9, init=init) stoprule = (rules.CountIterations(max_iterations=100) + rules.Discrepancy(setting.Hcodomain.norm, data, noiselevel=setting.Hcodomain.norm(noise), tau=1.1)) reco, reco_data = solver.run(stoprule) plt.plot(grid.coords[0], exact_solution.T, label='exact solution') plt.plot(grid.coords[0], reco, label='reco') plt.plot(grid.coords[0], exact_data, label='exact data') plt.plot(grid.coords[0], data, label='data') plt.plot(grid.coords[0], reco_data, label='reco data') plt.legend() plt.show()