Commit 262f00de authored by s.gretchko's avatar s.gretchko
Browse files

Added all Sparse2 demos

parent fc1f1f87
......@@ -4,3 +4,5 @@ docs/Manual/autotoc/
_build
build
dist
.vscode/launch.json
.vscode/settings.json
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CDRl', lambda_0=1.0, lambda_max=1.0, TOL=5e-4)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CDRl', TOL=5e-4)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CP', debug=False)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CP', cutoff=20)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CP', cutoff=25)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CP', cutoff=3)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='CP', cutoff=5)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='DRl', TOL=5e-4)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='AvP', accelerator_name='GenericAccelerator')
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='QNAvP')
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='QNAvP', cutoff=15)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='QNAvP', cutoff=25)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='QNAvP', cutoff=3)
Sparse2.run()
Sparse2.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Sparse2_Experiment import Sparse2_Experiment
Sparse2 = Sparse2_Experiment(algorithm='QNAvP', cutoff=5)
Sparse2.run()
Sparse2.show()
......@@ -161,7 +161,7 @@ class FeasibilityIterateMonitor(IterateMonitor):
tmp_gap = tmp_gap + (norm(self.u_monitor[j] - self.u_monitor[j-1])/normM)**2
if self.truth is not None:
# convert u1 to an array if necessary
# TODO need to simplify this...
# TODO need to simplify this...
if isCell(u1):
z = u1[len(u1)-1]
if self.truth_dim[0] == 1:
......@@ -181,7 +181,10 @@ class FeasibilityIterateMonitor(IterateMonitor):
z = u1[:,0]
z = reshape(z, (len(z),1)) # we want a true matrix not just a vector
else:
z = u1[:,:,0]
if u1.ndim == 3:
z = u1[:,:,0]
else:
z = u1
"""
# TODO deal properly with the following code which
# is experiment-dependent
......
from proxtoolbox.experiments.phase.phaseExperiment import PhaseExperiment
from proxtoolbox.utils.mypoissonrnd import mypoissonrnd
from proxtoolbox.utils.gaussian import gaussian
from proxtoolbox.utils.cell import Cell, isCell
from proxtoolbox.utils.graphics import addColorbar
......
......@@ -63,35 +63,19 @@ class Sparse2_Experiment(PhaseExperiment):
def loadData(self):
"""
Load Sparse2 dataset. Create the initial iterate.
Notes
-----
This experiment seems to be very sensitive to numerical precision.
The consequence is that the number of iterations needed to solve
the problem will vary compared to Matlab. This is due to the fact
that Python and Matlab does not use the exact same algorithms for
computing fft2, iff2.
"""
#make sure input data can be found, otherwise download it
GetData.getData('Phase')
debug_M = None
debug_u0 = None
debug_g = None
debug_truth = None
if self.debug:
if self.cutoff:
M_dict = loadMatFile('../InputData/Phase/Sparse2_M.mat')
debug_M = M_dict['M']
u0_dict = loadMatFile('../InputData/Phase/Sparse2_u0.mat')
debug_u0 = u0_dict['u_0']
g_dict = loadMatFile('../InputData/Phase/Sparse2_g.mat')
debug_g = g_dict['g']
truth_dict = loadMatFile('../InputData/Phase/Sparse2_truth.mat')
debug_truth = truth_dict['truth']
M_dict = loadMatFile('../InputData/Phase/Sparse2_M.mat')
debug_M_tmp = M_dict['M']
u0_dict = loadMatFile('../InputData/Phase/Sparse2_u0.mat')
debug_u0_tmp = u0_dict['u_0']
g_dict = loadMatFile('../InputData/Phase/Sparse2_g.mat')
debug_g_tmp = g_dict['g']
truth_dict = loadMatFile('../InputData/Phase/Sparse2_truth.mat')
debug_truth_tmp = truth_dict['truth']
n = self.Nx * self.Ny
rt_n = sqrt(n)
Sparsity = self.Sparsity
......@@ -112,21 +96,11 @@ class Sparse2_Experiment(PhaseExperiment):
tmp_shifted[len(tmp_shifted)-1] = support_idx[0]+n
self.truth_supp_diff = tmp_shifted - support_idx
if debug_g is None:
#g = gaussian(self.Ny, [Sparsity], [ceil(rt_n/2), ceil(rt_n/2)])
g = debug_g_tmp
else:
g = debug_g
g_orig = gaussian(self.Ny, [Sparsity], [ceil(rt_n/2), ceil(rt_n/2)])
g = gaussian(self.Ny, [Sparsity], [ceil(rt_n/2), ceil(rt_n/2)])
self.truth = np.real(fftshift(ifft2(fft2(g)*fft2(self.truth))))
flat_truth = self.truth.flatten('F')
u_scale = np.min(flat_truth[support_idx])
self.truth = self.truth / u_scale
if debug_truth is not None:
self.truth = debug_truth
self.truth = debug_truth_tmp # for tests - when using truth from Matlab we have same behavior
# - slight numerical differences have an impact on number of iterations
support_idx = np.where(self.truth < 1)
self.truth[support_idx] = 0
self.norm_truth = norm(self.truth, ord=2)
......@@ -139,10 +113,7 @@ class Sparse2_Experiment(PhaseExperiment):
self.true_sparsity = n - np.sum(np.sum(tmp_supp_index))
self.sparsity_parameter = np.ceil(1.2*self.true_sparsity)
if debug_M is None:
M = (np.abs(fft2(self.truth)))**2/n # note: modulus squared, not modulus
else:
M = debug_M
M = (np.abs(fft2(self.truth)))**2/n # note: modulus squared, not modulus
if self.noise:
snr = self.snr
......@@ -169,12 +140,8 @@ class Sparse2_Experiment(PhaseExperiment):
self.sets = 2
# initial guess
if debug_u0 is None:
self.u0 = ifft2(self.rt_data[0] + 10*(np.random.rand(self.Nx, self.Ny)).T)
else:
self.u0 = debug_u0
self.u0 = ifft2(self.rt_data[0] + 10*(np.random.rand(self.Nx, self.Ny)).T)
aaa = 1
def setupProxOperators(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment