Commit cbe5dd89 authored by s.gretchko's avatar s.gretchko
Browse files

Added all phasepack demos

parent efd86dfb
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='AvP', formulation='cyclic', MAXIT=2000)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='CDRl', formulation='cyclic',
MAXIT=2000, lambda_0=1.0, lambda_max=1.0)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='CDRl', formulation='cyclic',
MAXIT=200, lambda_0=0.75, lambda_max=0.75)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='CP', formulation='cyclic')
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='DRl', formulation='cyclic',
MAXIT=2000, lambda_0=1.0, lambda_max=1.0)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='DRAP', formulation='cyclic',
MAXIT=2000, lambda_0=0.02, lambda_max=0.02)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='DRl', formulation='cyclic',
MAXIT=2000, lambda_0=0.7, lambda_max=0.7)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='DyRePr', formulation='cyclic',
MAXIT=2000, lambda_0=1.0, lambda_max=1.0)
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='QNAvP', formulation='cyclic')
phasepack.run()
phasepack.show()
import SetProxPythonPath
from proxtoolbox.experiments.phase.Phasepack_Experiment import Phasepack_Experiment
phasepack = Phasepack_Experiment(algorithm='Wirtinger', formulation='cyclic')
phasepack.run()
phasepack.show()
......@@ -88,14 +88,19 @@ class Wirt_IterateMonitor(IterateMonitor):
if self.diagnostic:
tmp_gap = sum(abs(tmp1 - tmp_u)**2)/normM**2
if self.truth is not None:
if self.truth_dim[0] == 1:
z = u[0,:]
z = reshape(z, (1,len(z))) # we want a true matrix not just a vector
elif self.truth_dim[1] == 1:
z = u[:,0]
if u.ndim == 1:
# u is a vector
z = u
z = reshape(z, (len(z),1)) # we want a true matrix not just a vector
else:
z = u[:,:,0]
else: # u is a multidimensional array
if self.truth_dim[0] == 1:
z = u[0,:]
z = reshape(z, (1,len(z))) # we want a true matrix not just a vector
elif self.truth_dim[1] == 1:
z = u[:,0]
z = reshape(z, (len(z),1)) # we want a true matrix not just a vector
else:
z = u[:,:,0]
if self.diagnostic and self.truth is not None:
rel_error = norm(self.truth - exp(-1j*angle(trace(self.truth.T.conj() @ z))) * z) / self.norm_truth
......
......@@ -23,12 +23,19 @@ class Wirtinger(Algorithm):
def __init__(self, experiment, iterateMonitor, accelerator):
super(Wirtinger, self).__init__(experiment, iterateMonitor, accelerator)
self.masks = experiment.masks
if hasattr(experiment, 'masks_conj'):
self.masks_conj = experiment.masks_conj
else:
self.masks_conj = conj(self.masks)
self.data_sq = experiment.data_sq
if experiment.experiment_name == 'Phasepack':
self.isPhasepack = True
self.data = experiment.data
self.phasepack_A = experiment.phasepack_A
self.phasepack_Apinv = experiment.phasepack_Apinv
else:
self.isPhasepack = False
self.masks = experiment.masks
if hasattr(experiment, 'masks_conj'):
self.masks_conj = experiment.masks_conj
else:
self.masks_conj = conj(self.masks)
self.data_sq = experiment.data_sq
self.tau0 = 330
self.mu = lambda t: min(1-exp(-t/self.tau0), 0.4)
......@@ -47,6 +54,9 @@ class Wirtinger(Algorithm):
u_new : ndarray
The new iterate (same type as input parameter `u`).
"""
if self.isPhasepack:
return self.evaluatePhasePack(u)
L = self.product_space_dimension
get, set, data_shape = accessors(u, self.Nx, self.Ny, L)
......@@ -86,4 +96,15 @@ class Wirtinger(Algorithm):
return grad
def evaluatePhasePack(self, u):
u_new = np.empty(u.shape, dtype=np.complex128)
Bz = self.phasepack_A @ u
C = (abs(Bz)**2 - self.data) * Bz
grad = self.phasepack_Apinv @ C
self.step = self.mu(self.iter+1)/self.norm_data**2 * grad
u_new = u - self.step
return u_new
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