summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2019-04-12 15:57:58 +0100
committerEdoardo Pasca <edo.paskino@gmail.com>2019-04-12 15:57:58 +0100
commit3a24350a3c3e617434885728c0afed8c1891d3c4 (patch)
tree005df4d5595dc50cdae90ae41cfe9f13677e1276
parent168f8b09c56b06ab21f09e0ff2906e4ac18bf9d6 (diff)
downloadframework-3a24350a3c3e617434885728c0afed8c1891d3c4.tar.gz
framework-3a24350a3c3e617434885728c0afed8c1891d3c4.tar.bz2
framework-3a24350a3c3e617434885728c0afed8c1891d3c4.tar.xz
framework-3a24350a3c3e617434885728c0afed8c1891d3c4.zip
use PDHG class
-rwxr-xr-xWrappers/Python/wip/pdhg_TV_denoising.py52
1 files changed, 41 insertions, 11 deletions
diff --git a/Wrappers/Python/wip/pdhg_TV_denoising.py b/Wrappers/Python/wip/pdhg_TV_denoising.py
index f276b46..9bd5221 100755
--- a/Wrappers/Python/wip/pdhg_TV_denoising.py
+++ b/Wrappers/Python/wip/pdhg_TV_denoising.py
@@ -93,28 +93,58 @@ tau = 1/(sigma*normK**2)
opt = {'niter':1000}
opt1 = {'niter':1000, 'memopt': True}
-t1 = timer()
-res, time, primal, dual, pdgap = PDHG_old(f, g, operator, tau = tau, sigma = sigma, opt = opt)
-print(timer()-t1)
+#t1 = timer()
+#res, time, primal, dual, pdgap = PDHG_old(f, g, operator, tau = tau, sigma = sigma, opt = opt)
+#print(timer()-t1)
+#
+#print("with memopt \n")
+#
+#t2 = timer()
+#res1, time1, primal1, dual1, pdgap1 = PDHG_old(f, g, operator, tau = tau, sigma = sigma, opt = opt1)
+#print(timer()-t2)
+
+pdhg = PDHG(f=f,g=g,operator=operator, tau=tau, sigma=sigma)
+pdhg.max_iteration = 2000
+pdhg.update_objective_interval = 100
+
+
+pdhgo = PDHG(f=f,g=g,operator=operator, tau=tau, sigma=sigma, memopt=True)
+pdhgo.max_iteration = 2000
+pdhgo.update_objective_interval = 100
+
+steps = [timer()]
+pdhgo.run(2000)
+steps.append(timer())
+t1 = dt(steps)
+
+pdhg.run(2000)
+steps.append(timer())
+t2 = dt(steps)
-print("with memopt \n")
+print ("Time difference {}s {}s {}s Speedup {:.2f}".format(t1,t2,t2-t1, t2/t1))
+res = pdhg.get_output()
+res1 = pdhgo.get_output()
+
+diff = (res-res1)
+print ("diff norm {} max {}".format(diff.norm(), diff.abs().as_array().max()))
+print ("Sum ( abs(diff) ) {}".format(diff.abs().sum()))
-t2 = timer()
-res1, time1, primal1, dual1, pdgap1 = PDHG_old(f, g, operator, tau = tau, sigma = sigma, opt = opt1)
-print(timer()-t2)
plt.figure(figsize=(5,5))
+plt.subplot(1,3,1)
plt.imshow(res.as_array())
plt.colorbar()
-plt.show()
+#plt.show()
-plt.figure(figsize=(5,5))
+#plt.figure(figsize=(5,5))
+plt.subplot(1,3,2)
plt.imshow(res1.as_array())
plt.colorbar()
-plt.show()
+#plt.show()
-plt.figure(figsize=(5,5))
+#plt.figure(figsize=(5,5))
+plt.subplot(1,3,3)
plt.imshow(np.abs(res1.as_array()-res.as_array()))
plt.colorbar()
plt.show()