From 2c0744b55d69e3755d1d99ea164b5eaedb382b6d Mon Sep 17 00:00:00 2001 From: epapoutsellis Date: Thu, 23 May 2019 17:39:28 +0100 Subject: delete cvx sol --- .../demos/PDHG_examples/PDHG_TGV_Denoising.py | 74 +--------------------- 1 file changed, 2 insertions(+), 72 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/demos/PDHG_examples/PDHG_TGV_Denoising.py b/Wrappers/Python/demos/PDHG_examples/PDHG_TGV_Denoising.py index 761c025..4d6da00 100755 --- a/Wrappers/Python/demos/PDHG_examples/PDHG_TGV_Denoising.py +++ b/Wrappers/Python/demos/PDHG_examples/PDHG_TGV_Denoising.py @@ -30,8 +30,8 @@ Problem: min_{x} \alpha * ||\nabla x - w||_{2,1} + where fidelity can be as follows depending on the noise characteristics of the data: * Norm2Squared \frac{1}{2} * || x - g ||_{2}^{2} - * KullbackLeibler - * L1Norm + * KullbackLeibler \int u - g * log(u) + Id_{u>0} + * L1Norm ||u - g||_{1} \alpha: Regularization parameter \beta: Regularization parameter @@ -219,73 +219,3 @@ plt.title('Middle Line Profiles') plt.show() -#%% Check with CVX solution - -from ccpi.optimisation.operators import SparseFiniteDiff - -try: - from cvxpy import * - cvx_not_installable = True -except ImportError: - cvx_not_installable = False - -if cvx_not_installable: - - u = Variable(ig.shape) - w1 = Variable((N, N)) - w2 = Variable((N, N)) - - # create TGV regulariser - DY = SparseFiniteDiff(ig, direction=0, bnd_cond='Neumann') - DX = SparseFiniteDiff(ig, direction=1, bnd_cond='Neumann') - - regulariser = alpha * sum(norm(vstack([DX.matrix() * vec(u) - vec(w1), \ - DY.matrix() * vec(u) - vec(w2)]), 2, axis = 0)) + \ - beta * sum(norm(vstack([ DX.matrix().transpose() * vec(w1), DY.matrix().transpose() * vec(w2), \ - 0.5 * ( DX.matrix().transpose() * vec(w2) + DY.matrix().transpose() * vec(w1) ), \ - 0.5 * ( DX.matrix().transpose() * vec(w2) + DY.matrix().transpose() * vec(w1) ) ]), 2, axis = 0 ) ) - - constraints = [] - fidelity = pnorm(u - noisy_data.as_array(),1) - solver = MOSEK - - # choose solver - if 'MOSEK' in installed_solvers(): - solver = MOSEK - else: - solver = SCS - - obj = Minimize( regulariser + fidelity) - prob = Problem(obj) - result = prob.solve(verbose = True, solver = solver) - - diff_cvx = numpy.abs( pdhg.get_output()[0].as_array() - u.value ) - - plt.figure(figsize=(15,15)) - plt.subplot(3,1,1) - plt.imshow(pdhg.get_output()[0].as_array()) - plt.title('PDHG solution') - plt.colorbar() - plt.subplot(3,1,2) - plt.imshow(u.value) - plt.title('CVX solution') - plt.colorbar() - plt.subplot(3,1,3) - plt.imshow(diff_cvx) - plt.title('Difference') - plt.colorbar() - plt.show() - - plt.plot(np.linspace(0,N,N), pdhg.get_output()[0].as_array()[int(N/2),:], label = 'PDHG') - plt.plot(np.linspace(0,N,N), u.value[int(N/2),:], label = 'CVX') - plt.legend() - plt.title('Middle Line Profiles') - plt.show() - - print('Primal Objective (CVX) {} '.format(obj.value)) - print('Primal Objective (PDHG) {} '.format(pdhg.objective[-1][0])) - - - - - -- cgit v1.2.3