Commit 043d91c9 authored by Stefan Ziehe's avatar Stefan Ziehe
Browse files

* Fixed the case ignore_error == True for other ptychography algorithms

* Fixed the im2hsv conversion
parent 5c745a7a
......@@ -53,7 +53,7 @@ class PALM(Algorithm):
iters = 0;
current_change = tol+1;
if ignore_error = False:
if ignore_error == False:
change = zeros(maxiter+1);
num_custom_errors = len(self.custom_error.customerror(u,u))
custom_errors = zeros((num_custom_errors,maxiter+1));
......
......@@ -1371,17 +1371,16 @@ class Blocking_meta(Algorithm):
between_blocks_scheme = self.between_blocks_scheme;
iters = 0;
current_change = tol+1;
change = numpy.zeros(maxiter+1);
change[0] = 999;
num_custom_errors = len(self.custom_error.customerror(u,u))
custom_errors = numpy.zeros((num_custom_errors,maxiter+1));
custom_errors[:,0] = 999;
if ignore_error == False:
change = numpy.zeros(maxiter+1);
num_custom_errors = len(self.custom_error.customerror(u,u))
custom_errors = numpy.zeros((num_custom_errors,maxiter+1));
tmp_u = u.copy();
while iters < maxiter and (ignore_error or change[iters] >= tol):
while iters < maxiter and current_change > tol:
iters += 1;
if between_blocks_scheme == 'sequential':
......@@ -1406,14 +1405,16 @@ class Blocking_meta(Algorithm):
else:
raise NotImplementedError('NYI')
current_change = self.custom_error.change(u,tmp_u);
if ignore_error == False:
change[iters] = self.custom_error.change(u,tmp_u);
change[iters] = current_change;
custom_errors[:,iters] = self.custom_error.customerror(u,tmp_u);
u = tmp_u.copy();
change = change[1:iters+1];
custom_errors = custom_errors[:,1:iters+1];
change = current_change if ignore_error else change[1:iters+1];
custom_errors = numpy.empty((5,0)) if ignore_error else custom_errors[:,1:iters+1];
return u, u.copy(), iters, change, custom_errors;
......@@ -1421,7 +1422,7 @@ class Blocking_meta(Algorithm):
# More multiprocessing workarounds
def __getstate__(self):
"""
a multiprocessing workarounds
a multiprocessing workaround
"""
self_dict = self.__dict__.copy();
del self_dict['pool'];
......@@ -1429,7 +1430,7 @@ class Blocking_meta(Algorithm):
def __setstate__(self, state):
"""
a multiprocessing workarounds
a multiprocessing workaround
"""
self.__dict__.update(state);
......@@ -1489,31 +1490,34 @@ class PALM(Algorithm):
gap : array_like - Squared gap distance normalized by the magnitude constraint
"""
projs = self.projs;
ignore_error = self.ignore_error;
iters = 0;
change = numpy.zeros(maxiter+1);
change[0] = 999;
current_change = tol+1;
num_custom_errors = len(self.custom_error.customerror(u,u))
custom_errors = numpy.zeros((num_custom_errors,maxiter+1));
custom_errors[:,0] = 999;
if ignore_error == False:
change = numpy.zeros(maxiter+1);
num_custom_errors = len(self.custom_error.customerror(u,u))
custom_errors = numpy.zeros((num_custom_errors,maxiter+1));
tmp_u = u.copy();
tmp_u = u;
while iters < maxiter and (self.ignore_error or change[iters] >= tol):
while iters < maxiter and current_change > tol:
iters += 1;
for p in projs:
tmp_u = p.work(tmp_u);
current_change = self.custom_error.change(u,tmp_u);
if self.ignore_error == False:
change[iters] = self.custom_error.change(u,tmp_u);
change[iters] = current_change;
custom_errors[:,iters] = self.custom_error.customerror(u,tmp_u);
u = tmp_u.copy();
u = tmp_u;
change = change[1:iters+1];
custom_errors = custom_errors[:,1:iters+1];
change = current_change if ignore_error else change[1:iters+1];
custom_errors = numpy.empty((5,0)) if ignore_error else custom_errors[:,1:iters+1];
return tmp_u, tmp_u.copy(), iters, change, custom_errors;
......@@ -1582,19 +1586,20 @@ class RAAR_PALM(Algorithm):
change : array_like - The percentage change in the norm
custom_errors : array_like - Squared gap distance normalized by the magnitude constraint
"""
projs = self.projs
projs = self.projs;
ignore_error = self.ignore_error;
iters = 0
change = numpy.zeros(maxiter+1)
change[0] = 999
current_change = tol+1
num_custom_errors = len(self.custom_error.customerror(u,u,u))
custom_errors = numpy.zeros((num_custom_errors,maxiter+1))
custom_errors[:,0] = 999
if ignore_error == False:
change = numpy.zeros(maxiter+1)
num_custom_errors = len(self.custom_error.customerror(u,u,u))
custom_errors = numpy.zeros((num_custom_errors,maxiter+1))
tmp_u1 = projs[0].work(u)
while iters < maxiter and (self.ignore_error or change[iters] >= tol):
while iters < maxiter and current_change > tol:
iters += 1
tmp = exp((-iters/self.beta_switch)**3)
beta = (tmp*self.beta0) + ((1-tmp)*self.beta_max)
......@@ -1608,15 +1613,17 @@ class RAAR_PALM(Algorithm):
tmp_u2 = projs[0].work(tmp_u)
current_change = self.custom_error.change(tmp_u1,tmp_u2)
if self.ignore_error == False:
change[iters] = self.custom_error.change(tmp_u1,tmp_u2)
change[iters] = current_change
custom_errors[:,iters] = self.custom_error.customerror(tmp_u1,tmp_u2,tmp_u4)
u = tmp_u
tmp_u1 = tmp_u2
change = change[1:iters+1]
custom_errors = custom_errors[:,1:iters+1]
change = current_change if ignore_error else change[1:iters+1]
custom_errors = numpy.empty((5,0)) if ignore_error else custom_errors[:,1:iters+1]
return tmp_u1, tmp_u1.copy(), iters, change, custom_errors
......@@ -1848,12 +1855,10 @@ class Ptychography(Problem):
imhsv = numpy.zeros((im.shape[0],im.shape[1],3));
imhsv[:,:,0] = numpy.fmod(numpy.angle(im),2*numpy.pi);
imhsv[:,:,0] = numpy.remainder(numpy.angle(im),2*numpy.pi) / (2*numpy.pi);
imhsv[:,:,1] = 1;
tmp = 1.0+numpy.sign(abs_im-th)/2.0;
tmp = (abs_im - tmp*abs_im + tmp*th)/th;
tmp = numpy.min(tmp,1);
tmp = numpy.max(tmp,0);
tmp = (1.0 + numpy.sign(abs_im-th)) / 2.0;
tmp = numpy.clip((abs_im - tmp*abs_im + tmp*th) / th, 0, 1);
imhsv[:,:,2] = tmp;
return imhsv;
......@@ -2177,7 +2182,7 @@ class Ptychography(Problem):
if object_guess_type == 'exact':
object_guess = sample_plane.copy();
elif object_guess_type == 'ones':
object_guess = numpy.ones_like(sample_plane) / guess_value;
object_guess = numpy.ones_like(sample_plane);
elif object_guess_type == 'constant':
object_guess = numpy.ones_like(sample_plane) / guess_value;
elif object_guess_type == 'exact_perturbed':
......
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