summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
authorepapoutsellis <epapoutsellis@gmail.com>2019-04-29 16:59:31 +0100
committerepapoutsellis <epapoutsellis@gmail.com>2019-04-29 16:59:31 +0100
commit9a116a0203f64ecc91da9780c0c2006720303ab6 (patch)
treea46e792007492a10fdb43b3a476d9aaf19903ad3 /Wrappers
parent2eb83e4389c0a251aa218b200f1ccfb20e31b84a (diff)
parent05597b4428d85f5bf9a01f538f87ea5307740b54 (diff)
downloadframework-9a116a0203f64ecc91da9780c0c2006720303ab6.tar.gz
framework-9a116a0203f64ecc91da9780c0c2006720303ab6.tar.bz2
framework-9a116a0203f64ecc91da9780c0c2006720303ab6.tar.xz
framework-9a116a0203f64ecc91da9780c0c2006720303ab6.zip
fix demos
Diffstat (limited to 'Wrappers')
-rw-r--r--Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py26
-rw-r--r--Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py6
-rw-r--r--Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py120
3 files changed, 77 insertions, 75 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py b/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py
index 51a008f..b53f669 100644
--- a/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py
+++ b/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py
@@ -105,18 +105,20 @@ class KullbackLeibler(Function):
z = x + tau * self.bnoise
return 0.5*((z + 1) - ((z-1)**2 + 4 * tau * self.b).sqrt())
else:
- z = x + tau * self.bnoise
- out.fill( 0.5*((z + 1) - ((z-1)**2 + 4 * tau * self.b).sqrt()) )
- #z_m = x + tau * self.bnoise -1
- #self.b.multiply(4*tau, out=out)
- #z_m.multiply(z_m, out=z_m)
- #out += z_m
- #out.sqrt(out=out)
- #z_m.sqrt(out=z_m)
- #z_m += 2
- #out *= -1
- #out += z_m
- #out *= 0.5
+# z = x + tau * self.bnoise
+# out.fill( 0.5*((z + 1) - ((z-1)**2 + 4 * tau * self.b).sqrt()) )
+
+ tmp1 = x + tau * self.bnoise - 1
+ tmp2 = tmp1 + 2
+
+ self.b.multiply(4*tau, out=out)
+ tmp1.multiply(tmp1, out=tmp1)
+ out += tmp1
+ out.sqrt(out=out)
+
+ out *= -1
+ out += tmp2
+ out *= 0.5
diff --git a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py
index 1a3e0df..39bbb2c 100644
--- a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py
+++ b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py
@@ -32,7 +32,7 @@ from ccpi.optimisation.functions import ZeroFunction, L2NormSquared, \
from skimage.util import random_noise
# Create phantom for TV Gaussian denoising
-N = 300
+N = 100
data = np.zeros((N,N))
data[round(N/4):round(3*N/4),round(N/4):round(3*N/4)] = 0.5
@@ -46,9 +46,9 @@ n1 = random_noise(data.as_array(), mode = 'gaussian', mean=0, var = 0.05, seed=1
noisy_data = ImageData(n1)
# Regularisation Parameter
-alpha = 0.5
+alpha = 2
-method = '0'
+method = '1'
if method == '0':
diff --git a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py
index ccdabb2..4903c44 100644
--- a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py
+++ b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py
@@ -124,63 +124,63 @@ 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:
-#
-# ##Construct problem
-# u1 = Variable(ig.shape)
-# q = Variable()
-#
-# DY = SparseFiniteDiff(ig, direction=0, bnd_cond='Neumann')
-# DX = SparseFiniteDiff(ig, direction=1, bnd_cond='Neumann')
-#
-# # Define Total Variation as a regulariser
-# regulariser = alpha * sum(norm(vstack([DX.matrix() * vec(u1), DY.matrix() * vec(u1)]), 2, axis = 0))
-#
-# fidelity = sum( u1 - multiply(noisy_data.as_array(), log(u1)) )
-# constraints = [q>= fidelity, u1>=0]
-#
-# solver = ECOS
-# obj = Minimize( regulariser + q)
-# prob = Problem(obj, constraints)
-# result = prob.solve(verbose = True, solver = solver)
-#
-#
-# diff_cvx = numpy.abs( pdhg.get_output().as_array() - u1.value )
-#
-# plt.figure(figsize=(15,15))
-# plt.subplot(3,1,1)
-# plt.imshow(pdhg.get_output().as_array())
-# plt.title('PDHG solution')
-# plt.colorbar()
-# plt.subplot(3,1,2)
-# plt.imshow(u1.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().as_array()[int(N/2),:], label = 'PDHG')
-# plt.plot(np.linspace(0,N,N), u1.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]))
-#
-#
-#
-#
-#
+from ccpi.optimisation.operators import SparseFiniteDiff
+
+try:
+ from cvxpy import *
+ cvx_not_installable = True
+except ImportError:
+ cvx_not_installable = False
+
+
+if cvx_not_installable:
+
+ ##Construct problem
+ u1 = Variable(ig.shape)
+ q = Variable()
+
+ DY = SparseFiniteDiff(ig, direction=0, bnd_cond='Neumann')
+ DX = SparseFiniteDiff(ig, direction=1, bnd_cond='Neumann')
+
+ # Define Total Variation as a regulariser
+ regulariser = alpha * sum(norm(vstack([DX.matrix() * vec(u1), DY.matrix() * vec(u1)]), 2, axis = 0))
+
+ fidelity = sum( u1 - multiply(noisy_data.as_array(), log(u1)) )
+ constraints = [q>= fidelity, u1>=0]
+
+ solver = ECOS
+ obj = Minimize( regulariser + q)
+ prob = Problem(obj, constraints)
+ result = prob.solve(verbose = True, solver = solver)
+
+
+ diff_cvx = numpy.abs( pdhg.get_output().as_array() - u1.value )
+
+ plt.figure(figsize=(15,15))
+ plt.subplot(3,1,1)
+ plt.imshow(pdhg.get_output().as_array())
+ plt.title('PDHG solution')
+ plt.colorbar()
+ plt.subplot(3,1,2)
+ plt.imshow(u1.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().as_array()[int(N/2),:], label = 'PDHG')
+ plt.plot(np.linspace(0,N,N), u1.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]))
+
+
+
+
+