Commit 47c6e1d9 authored by markus.meier01's avatar markus.meier01
Browse files

Changed a lot of small things in everything for CDP

parent 4b71000c
......@@ -5,10 +5,12 @@ Created on Mon Dec 14 13:08:06 2015
@author: rebecca
"""
from math import sqrt
from numpy import zeros
from math import sqrt, exp
from numpy import zeros, angle
from numpy import all as a
from scipy.linalg import norm
from .algorithms import Algorithm
from trace import Trace
class AP_expert(Algorithm):
"""
......@@ -51,9 +53,10 @@ class AP_expert(Algorithm):
self.iters = 0
if 'truth' in config:
self.truth = config['truth']
self.truth_dim = config['truth_dim']
self.norm_truth = config['norm_truth']
self.Truth = config['truth']
self.Truth_dim = config['truth_dim']
self.norm_Truth = config['norm_truth']
def run(self, u, tol, maxiter):
"""
......@@ -91,18 +94,18 @@ class AP_expert(Algorithm):
tmp1 = prox2.work(tmp_u);
tmp_change = 0; tmp_gap = 0;
if p==1 and q==1:
tmp_change= (norm(u-tmp_u, 'fro')/norm_data)**2
tmp_gap = (norm(tmp1-tmp_u,'fro')/norm_data)**2
if hasattr(self, 'truth'):
if self.truth_dim[0] == 1:
if self.Truth_dim[0] == 1:
z=tmp_u[0,:]
elif self.truth_dim[1]==1:
elif self.Truth_dim[1]==1:
z=tmp_u[:,0]
else:
z=tmp_u
Relerrs[iter] = norm(self.truth - exp(-1j*angle(trace(self.truth.T*z))) * z, 'fro')/self.norm_truth
Relerrs[iter] = norm(self.Truth - exp(-1j*angle(Trace(self.Truth.T*z))) * z, 'fro')/self.norm_Truth
elif q==1:
for j in range(self.product_space_dimension):
......
......@@ -53,9 +53,9 @@ class SimpleAlgorithm:
self.config = config
if 'truth' in config:
self.truth = config['truth']
self.truth_dim = config['truth_dim']
self.norm_truth = config['norm_truth']
self.Truth = config['truth']
self.Truth_dim = config['truth_dim']
self.norm_Truth = config['norm_truth']
if 'diagnostic' in config:
self.diagnostic = True
......@@ -143,15 +143,15 @@ class SimpleAlgorithm:
tmp_gap = phase_offset_compensated_norm(u1, u2, norm_factor=norm_data, norm_type='fro') ** 2
if hasattr(self, 'truth'):
if self.truth_dim[0] == 1:
if self.Truth_dim[0] == 1:
z = u1[0, :]
elif self.truth_dim[1] == 1:
elif self.Truth_dim[1] == 1:
z = u1[:, 0]
else:
z = u1
# Relerrs[iter] = norm(self.truth - exp(-1j * angle(trace(self.truth.T * z))) * z,
# 'fro') / self.norm_truth
Relerrs[iter] = phase_offset_compensated_norm(self.truth, z, norm_factor=self.norm_truth,
Relerrs[iter] = phase_offset_compensated_norm(self.Truth, z, norm_factor=self.norm_Truth,
norm_type='fro')
elif q == 1:
......@@ -164,8 +164,9 @@ class SimpleAlgorithm:
if 'diagnostic' in self.config:
if hasattr(self, 'truth'):
z = u1[:, :, 0]
Relerrs[iter] = norm(self.truth - exp(-1j * angle(trace(self.truth.T * z))) * z,
'fro') / self.norm_truth
print(z.shape)
print(self.Truth.T.shape)
Relerrs[iter] = norm((self.Truth - exp(-1j * angle(trace(self.Truth.T * z))) * z),'fro') / self.norm_Truth
else:
if 'diagnostic' in self.config:
......@@ -181,8 +182,8 @@ class SimpleAlgorithm:
norm(u2[:, :, k, j] - shadow[:, :, k, j], 'fro') / (norm_data)) ** 2
if hasattr(self, 'truth') and (j == 0):
Relerrs[iter] = Relerrs[iter] + norm(
self.truth - exp(-1j * angle(trace(self.truth.T * u1[:, :, k, 1]))) * u1[:, :, k, 1],
'fro') / self.norm_truth
self.Truth - exp(-1j * angle(trace(self.truth.T * u1[:, :, k, 1]))) * u1[:, :, k, 1],
'fro') / self.norm_Truth
change[iter] = sqrt(tmp_change)
if 'diagnostic' in self.config:
......
......@@ -20,7 +20,7 @@ new_config = {
'warmup_iter' : 0,
'method' : 'AP_expert',
'algorithm' : 'AP_expert',
'numruns' : 100,
'keep_log' : 1,
......
......@@ -18,7 +18,7 @@ new_config = {
# 'Problem Parameter'
#::::::::::::::::::::::::::::::::::::::
# 'What is the name of data file'?
'Data_Filename' : 'CDP_Processor',
'data_filename' : 'CDP_processor',
# What type of object are we working with?
......@@ -28,13 +28,13 @@ new_config = {
# What type of constraints do we have?
# Options are: 'support only', 'real and support', 'nonnegative and support',
# 'amplitude only', 'sparse real', 'sparse complex', and 'hybrid'
'Constraint' : 'Hybride',
'constraint' : 'Hybride',
# What type of measurements are we working with?
# Options are: 'single diffraction', 'JWST', 'CDP',
# 'ptychography', and 'complex'
'Experiment' : 'CDP',
'experiment' : 'CDP',
# The input data are coded diffraction patterns about a random complex
......@@ -46,7 +46,7 @@ new_config = {
'Nz':1, # images are 1 or 2D
# Make masks and linear sampling operators
'Product_space_dimension' : 10, # 6 for 1D signals % Number of masks
'product_space_dimension' : 10, # 6 for 1D signals % Number of masks
# Are the measurements in the far field or near field?
# Options are: 'far field' or 'near field',
......@@ -64,7 +64,7 @@ new_config = {
# able to control ('without too much damage')
# 'Algorithm':
'Method' : 'AP',#'Accelerated_AP_product_space',
'algorithm' : 'AP',#'Accelerated_AP_product_space',
'numruns':100,# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......@@ -95,7 +95,7 @@ new_config = {
# 'Parameter for the data regularization
# need to discuss how/whether the user should
# put in information about the noise
'Input.data_ball' : 1e-15,
'data_ball' : 1e-15,
# the above is the percentage of the gap
# between the measured data and the
# initial guess satisfying the
......
......@@ -60,7 +60,7 @@ new_config = {
# able to control (without too much damage)
# 'Algorithm':
'method' : 'DRAP',#'Accelerated_AP_product_space',
'algorithm' : 'DRAP',#'Accelerated_AP_product_space',
'numruns':100, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......
......@@ -60,7 +60,7 @@ new_config = {
# able to control (without too much damage)
# Algorithm:
'method' : 'QNAP', # 'Accelerated_AP_product_space',
'algorithm' : 'QNAP', # 'Accelerated_AP_product_space',
'numruns' : 100, # the only this parameter will be different than 1
# is when we are benchmarking...not something a normal user would be doing
'keep_log' : 1,
......
......@@ -57,7 +57,7 @@ new_config = {
# able to control (without too much damage)
# 'Algorithm':
'method' : 'RAAR',#'Accelerated_AP_product_space',
'algorithm' : 'RAAR',#'Accelerated_AP_product_space',
'numruns':100, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......
......@@ -39,9 +39,9 @@ new_config = {
# 'Valued image'.
# 'Make image'
'ny' : 128,
'nx' : 1, # 1 for 1D signals
'nz':1, # images are 1 or 2D
'Ny' : 128,
'Nx' : 1, # 1 for 1D signals
'Nz':1, # images are 1 or 2D
# 'Make masks and linear sampling operators'
'product_space_dimension' :10, # 6 for 1D signals % Number of masks
......
......@@ -56,7 +56,7 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'method' : 'AP', #'Accelerated_AP_product_space';
'algorithm' : 'AP', #'Accelerated_AP_product_space';
'numruns' : 100, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......
......@@ -56,7 +56,7 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'method' : 'DRAP', #'Accelerated_AP_product_space';
'algorithm' : 'DRAP', #'Accelerated_AP_product_space';
'numruns' : 100, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......
......@@ -56,7 +56,7 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'method' : 'QNAP', #'Accelerated_AP_product_space';
'algorithm' : 'QNAP', #'Accelerated_AP_product_space';
'numruns' : 100, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......
......@@ -56,7 +56,10 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'method' : 'Wirtinger', #'Accelerated_AP_product_space';
## IMPORTANT: algorithm used to be Wirtinger, not sure if AP also works
'algorithm' : 'AP', #'Accelerated_AP_product_space';
'numruns' : 100, # the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
......
......@@ -38,6 +38,11 @@ def Phase_graphics(config, output):
#beta0 = config['beta_0']
#beta_max = config['beta_max']
u_0 = config['u_0']
u = output['u1']
print(u.shape)
if output['u1'].ndim == 2:
u = output['u1']
u2 = output['u2']
......
......@@ -127,7 +127,6 @@ class P_diag(ProxOperator):
m = self.m;
p = self.p;
K = self.K;
print(u.shape)
if m == 1:
tmp = sum(u, axis=0, dtype=u.dtype)
......@@ -137,9 +136,8 @@ class P_diag(ProxOperator):
tmp = zeros((m,n), dtype=u.dtype)
for k in range(K):
tmp += u[:, :, k]
print(tmp)
else:
tmp = zeros((m, n, p), dtype=u.dtype)
tmp = zeros((m,n, p), dtype=u.dtype)
for k in range(K):
tmp += u[:, :, :, k]
......@@ -153,10 +151,9 @@ class P_diag(ProxOperator):
u_diag = empty((m,n, K), dtype=u.dtype)
for k in range(K):
u_diag[:, :, k] = tmp
print(u_diag.shape)
return u_diag
else:
u_diag = empty((n, m, p, K), dtype=u.dtype)
u_diag = empty((m,n, p, K), dtype=u.dtype)
for k in range(K):
u_diag[:, :, :, k] = tmp
return u_diag
......
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