Commit aab45f79 authored by jansen31's avatar jansen31
Browse files

first try for 3d compatibility, ignoring the case where the product space is higher-dimensional

parent 98cad1a1
...@@ -80,7 +80,10 @@ class SimpleAlgorithm: ...@@ -80,7 +80,10 @@ class SimpleAlgorithm:
norm_data = self.norm_data norm_data = self.norm_data
iter = self.iter iter = self.iter
if u.ndim < 3:
# TODO: select the right case also for a 3d problem.
# This could involve using the parameter self.product_space_dimension
if u.ndim < 3: # temp note: as used in (e.g.) 2d CDI, or orbital tomography
p = 1 p = 1
q = 1 q = 1
elif u.ndim == 3: elif u.ndim == 3:
...@@ -128,20 +131,15 @@ class SimpleAlgorithm: ...@@ -128,20 +131,15 @@ class SimpleAlgorithm:
tmp_gap = 0 tmp_gap = 0
tmp_shadow = 0 tmp_shadow = 0
if p == 1 and q == 1: # the simple case, where everything can be calculated in one difference
# tmp_change = (norm(u - u_new, 'fro') / norm_data) ** 2 if self.product_space_dimension == 1 or (p == 1 and q == 1):
tmp_change = phase_offset_compensated_norm(u, u_new, norm_type='fro', norm_factor=norm_data) ** 2 tmp_change = phase_offset_compensated_norm(u, u_new, norm_type='fro', norm_factor=norm_data) ** 2
if self.diagnostic: if self.diagnostic:
# For Douglas-Rachford,in general it is appropriate to monitor the # For Douglas-Rachford,in general it is appropriate to monitor the SHADOWS of the iterates,
# SHADOWS of the iterates, since in the convex case these converge # since in the convex case these converge even for beta=1. (see Bauschke-Combettes-Luke,
# even for beta=1. # J. Approx. Theory, 2004)
# (see Bauschke-Combettes-Luke, J. Approx. Theory, 2004)
# tmp_shadow = (norm(u2 - shadow, 'fro') / norm_data) ** 2
# tmp_gap = (norm(u1 - u2, 'fro') / norm_data) ** 2
tmp_shadow = phase_offset_compensated_norm(u2, shadow, norm_factor=norm_data, norm_type='fro') ** 2 tmp_shadow = phase_offset_compensated_norm(u2, shadow, norm_factor=norm_data, norm_type='fro') ** 2
tmp_gap = phase_offset_compensated_norm(u1, u2, norm_factor=norm_data, norm_type='fro') ** 2 tmp_gap = phase_offset_compensated_norm(u1, u2, norm_factor=norm_data, norm_type='fro') ** 2
if hasattr(self, 'truth'): if hasattr(self, 'truth'):
if self.truth_dim[0] == 1: if self.truth_dim[0] == 1:
z = u1[0, :] z = u1[0, :]
...@@ -149,12 +147,10 @@ class SimpleAlgorithm: ...@@ -149,12 +147,10 @@ class SimpleAlgorithm:
z = u1[:, 0] z = u1[:, 0]
else: else:
z = u1 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') norm_type='fro')
elif q == 1: elif q == 1: # more complex: loop over product space dimension
for j in range(self.product_space_dimension): for j in range(self.product_space_dimension):
tmp_change = tmp_change + (norm(u[:, :, j] - u_new[:, :, j], 'fro') / norm_data) ** 2 tmp_change = tmp_change + (norm(u[:, :, j] - u_new[:, :, j], 'fro') / norm_data) ** 2
if self.diagnostic: if self.diagnostic:
...@@ -164,10 +160,10 @@ class SimpleAlgorithm: ...@@ -164,10 +160,10 @@ class SimpleAlgorithm:
if self.diagnostic: if self.diagnostic:
if hasattr(self, 'truth'): if hasattr(self, 'truth'):
z = u1[:, :, 0] z = u1[:, :, 0]
Relerrs[iter] = norm((self.truth - exp(-1j * angle(trace(self.truth.T.transpose() * z))) * z),
'fro') / self.norm_truth
Relerrs[iter] = norm((self.truth - exp(-1j * angle(trace(self.truth.T.transpose() * z))) * z),'fro') / self.norm_truth else: # loop over product space dimension as well as additional z dimension
else:
if self.diagnostic: if self.diagnostic:
if hasattr(self, 'truth'): if hasattr(self, 'truth'):
Relerrs[iter] = 0 Relerrs[iter] = 0
...@@ -184,22 +180,20 @@ class SimpleAlgorithm: ...@@ -184,22 +180,20 @@ class SimpleAlgorithm:
self.truth - exp(-1j * angle(trace(self.truth.T * u1[:, :, k, 1]))) * u1[:, :, k, 1], self.truth - exp(-1j * angle(trace(self.truth.T * u1[:, :, k, 1]))) * u1[:, :, k, 1],
'fro') / self.norm_Truth 'fro') / self.norm_Truth
# Add values to the list of change, gap and shadow_change
change[iter] = sqrt(tmp_change) change[iter] = sqrt(tmp_change)
if self.diagnostic: if self.diagnostic:
gap[iter] = sqrt(tmp_gap) gap[iter] = sqrt(tmp_gap)
shadow_change[iter] = sqrt(tmp_shadow) # this is the Euclidean norm of the gap to shadow_change[iter] = sqrt(tmp_shadow) # this is the Euclidean norm of the gap to
# the unregularized set. To monitor the Euclidean norm of the gap to the # the unregularized set. To monitor the Euclidean norm of the gap to the regularized set is
# regularized set is expensive to calculate, so we use this surrogate. # expensive to calculate, so we use this surrogate. Since the stopping criteria is on the change
# Since the stopping criteria is on the change in the iterates, this # in the iterates, this does not matter.
# does not matter.
# graphics
# update # update iterate
u = u_new u = u_new
if self.diagnostic: if self.diagnostic:
# For Douglas-Rachford,in general it is appropriate to monitor the # For Douglas-Rachford,in general it is appropriate to monitor the SHADOWS of the iterates, since in
# SHADOWS of the iterates, since in the convex case these converge # the convex case these converge even for beta=1.
# even for beta=1.
# (see Bauschke-Combettes-Luke, J. Approx. Theory, 2004) # (see Bauschke-Combettes-Luke, J. Approx. Theory, 2004)
shadow = u2 shadow = u2
......
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