def test_compare_with_PDHG(self): # Load an image from the CIL gallery. data = dataexample.SHAPES.get() ig = data.geometry # Add gaussian noise noisy_data = applynoise.gaussian(data, seed=10, var=0.005) # TV regularisation parameter alpha = 1 # fidelity = 0.5 * L2NormSquared(b=noisy_data) # fidelity = L1Norm(b=noisy_data) fidelity = KullbackLeibler(b=noisy_data, use_numba=False) # Setup and run the PDHG algorithm F = BlockFunction(alpha * MixedL21Norm(), fidelity) G = ZeroFunction() K = BlockOperator(GradientOperator(ig), IdentityOperator(ig)) # Compute operator Norm normK = K.norm() # Primal & dual stepsizes sigma = 1. / normK tau = 1. / normK pdhg = PDHG(f=F, g=G, operator=K, tau=tau, sigma=sigma, max_iteration=100, update_objective_interval=10) pdhg.run(verbose=0) sigma = 1 tau = sigma / normK**2 admm = LADMM(f=G, g=F, operator=K, tau=tau, sigma=sigma, max_iteration=100, update_objective_interval=10) admm.run(verbose=0) from cil.utilities.quality_measures import psnr if debug_print: print("PSNR", psnr(admm.solution, pdhg.solution)) np.testing.assert_almost_equal(psnr(admm.solution, pdhg.solution), 84.46678222768597, decimal=4)
def do_test_with_fidelity(self, fidelity): alpha = self.alpha # F = BlockFunction(alpha * MixedL21Norm(),fidelity) G = fidelity K = self.K F = self.F admm = LADMM(f=G, g=F, operator=K, tau=self.tau, sigma=self.sigma, max_iteration=100, update_objective_interval=10) admm.run(1, verbose=0) admm_noaxpby = LADMM(f=G, g=F, operator=K, tau=self.tau, sigma=self.sigma, max_iteration=100, update_objective_interval=10, use_axpby=False) admm_noaxpby.run(1, verbose=0) np.testing.assert_array_almost_equal(admm.solution.as_array(), admm_noaxpby.solution.as_array())
def test_exception_initial_LADMM(self): ig = ImageGeometry(10, 10) # K = Identity(ig) # b = ig.allocate(0) # f = LeastSquares(K, b) # g = IndicatorBox(lower=0) initial = ig.allocate(1) try: algo = LADMM(initial=initial, x_init=initial) assert False except ValueError as ve: assert True