Commit ed1c005c authored by alexander.dornheim's avatar alexander.dornheim
Browse files

Fixed various errors in HAAR

parent 39ad1057
......@@ -100,7 +100,7 @@ class HAAR(Algorithm):
Runs the algorithm for the specified input data
"""
prox1 = self.prox1; prox2 = self.prox2;
normM = self.normM
y0 = self.y0
......@@ -165,33 +165,33 @@ class HAAR(Algorithm):
y_new = self.Q_Heau.work(y0,tmp_y,(1-self.mu)*tmp_y+self.mu*Ty)
if dim_number == 2 and (n!=1) and (m!=1):
y_new = y_new.reshape((m,n))
if dim_number == 2 and (s[0]!=1) and (s[1]!=1):
y_new = y_new.reshape((s[0],s[1]))
elif dim_number == 3:
tmpy = zeros((m,n,p))
tmpy = zeros((s[0],s[1],s[2]))
for j in range(p):
tmpy[:,:,j]= y_new[n*m*j:m*n*(j+1)].reshape((m,n))
tmpy[:,:,j]= y_new[s[0]*s[1]*j:s[0]*s[1]*(j+1)].reshape((s[0],s[1]))
y_new=tmpy
elif dim_number == 4:
print('not ready for 4D arrays')
if 'diagnostic' in self.config:
if self.diagnostic == True:
# the next prox operations only gets used in the computation of
# the size of the gap. This extra step is not
# required in alternating projections, which makes RAAR
# and special cases thereof more expensive to monitor.
# compute the normalized change in successive iterates:
tmp = prox2.evaluate(y_new)
tmp2 = prox1.evaluate(tmp)
tmp = prox2.work(y_new)
tmp2 = prox1.work(tmp)
# compute the normalized change in successive iterates:
# change(iter) = sum(sum((feval('P_M',M,u)-tmp).^2))/normM;
tmp_change=0; tmp_gap=0; tmp_shadow=0;
if p==1 and q==1:
tmp_change= (norm(u-u_new, 'fro')/normM)**2
if 'diagnostic' in self.config:
if dim_number <= 2:
tmp_change= (norm(y-y_new, 'fro')/normM)**2
if self.diagnostic == True:
# For Douglas-Rachford,in general it is appropriate to monitor the
# SHADOWS of the iterates, since in the convex case these converge
# even for beta=1.
......@@ -211,18 +211,18 @@ class HAAR(Algorithm):
elif q==1:
for j in range(self.product_space_dimension):
tmp_change= tmp_change+ (norm(y[:,:,j]-y_new[:,:,j], 'fro')/normM)**2
if 'diagnostic' in self.config:
if self.diagnostic == True:
# compute (||P_SP_Mx-P_Mx||/normM)^2:
tmp_gap = tmp_gap+(norm(tmp[:,:,j]-tmp2[:,:,j],'fro')/normM)**2
tmp_shadow = tmp_shadow+(norm(tmp[:,:,j]-shadow[:,:,j],'fro')/normM)**2
if 'diagnostic' in self.config:
if self.diagnostic == True:
if hasattr(self, 'truth'):
z=tmp[:,:,0]
Relerrs[iter] = norm(self.truth - exp(-1j*angle(trace(self.truth.T*z))) * z, 'fro')/self.norm_truth
change[iter] = sqrt(tmp_change)
if 'diagnostic' in self.config:
if self.diagnostic == True:
gap[iter] = sqrt(tmp_gap)
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
......@@ -234,7 +234,7 @@ class HAAR(Algorithm):
y=y_new
self.T_config['u_0']=y
if 'diagnostic' in self.config:
if self.diagnostic == True:
# For Douglas-Rachford,in general it is appropriate to monitor the
# SHADOWS of the iterates, since in the convex case these converge
# even for beta=1.
......@@ -262,7 +262,7 @@ class HAAR(Algorithm):
output = {'u' : u, 'u1': u1, 'u2': u2, 'iter': iter, 'change': change}
if 'diagnostic' in self.config:
if self.diagnostic == True:
gap = gap[1:iter+1]
shadow_change = shadow_change[1:iter+1]
output['gap']=gap
......
Supports Markdown
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