Commit 5b5d5094 authored by alexander.dornheim's avatar alexander.dornheim
Browse files

Updated sudoku.py to work with nwer version of ProxPython.

Some keys of config had to be renamed.
Grahpic stays open now.
Output of algortihm is now a dictionary.

Found and fixed some bugs in SimpleAlgortihm

Updated keys of ProxOperator P_parallel
parent b9896819
......@@ -75,6 +75,7 @@ class SimpleAlgorithm:
else:
p = u.shape[2]
q = u.shape[3]
print(u.shape)
change = zeros(maxiter+1,dtype=u.dtype)
change[0] = 999
......@@ -146,13 +147,15 @@ class SimpleAlgorithm:
Relerrs[iter] = norm(self.truth - exp(-1j*angle(trace(self.truth.T*z))) * z, 'fro')/self.norm_truth
else:
Relerrs[iter] = 0
if 'diagnostic' in self.config:
if hasattr(self, 'truth'):
Relerrs[iter] = 0
for j in range(self.product_space_dimension):
for k in range(Nz):
for k in range(self.Nz):
tmp_change= tmp_change+ (norm(u[:,:,k,j]-u_new[:,:,k,j], 'fro')/norm_data)**2
if 'diagnostic' in self.config:
# compute (||P_Sx-P_Mx||/norm_data)^2:
tmp_gap = tmp_gap+(norm(u1[:,:,k,j]-u22[:,:,k,j],'fro')/(norm_data))**2
tmp_gap = tmp_gap+(norm(u1[:,:,k,j]-u2[:,:,k,j],'fro')/(norm_data))**2
tmp_shadow = tmp_shadow+(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
......
......@@ -188,7 +188,7 @@ class Sudoku(Problem):
# P_parallel requires a sequence of projectors
'projectors':('ProjRow','ProjColumn','ProjSquare','ProjGiven'),
# Relaxation parameters for RAAR/HPR
'beta0':1,
'beta_0':1,
'beta_max':1,
'beta_switch':1,
# Any algorithm requires these
......@@ -199,7 +199,7 @@ class Sudoku(Problem):
'Nx':9,
'Ny':9,
'Nz':9,
'dim':4,
'product_space_dimension':4,
'norm_data':81,
# Just a random Sudoku. Not too easy, but no challenge for
# the mighty ProxToolbox!
......@@ -211,7 +211,8 @@ class Sudoku(Problem):
(0,0,5,0,0,3,0,0,7),
(0,0,0,0,0,0,0,0,0),
(1,0,0,0,0,7,4,9,0),
(0,2,4,1,0,0,0,0,0))
(0,2,4,1,0,0,0,0,0)),
'diagnostic': True
}
def __init__(self, new_config={}):
......@@ -268,8 +269,7 @@ class Sudoku(Problem):
"""
# algorithm = self.config['algorithm'](self.config)
self.u1,self.u2,self.iters,self.change,self.gap = \
self.algorithm.run(self.u,self.config['tol'],self.config['maxiter'])
self.output = self.algorithm.run(self.u,self.config['tol'],self.config['maxiter'])
def _postsolve(self):
......@@ -277,7 +277,7 @@ class Sudoku(Problem):
Processes the solution and generates the output
"""
solution = zeros_like(self.config['sudoku'])
A = self.u1[:,:,:,0]
A = self.output['u1'][:,:,:,0]
for x in range(9):
for y in range(9):
......@@ -322,13 +322,13 @@ class Sudoku(Problem):
ax = pyplot.subplot(2,2,3)
ax.xaxis.label.set_text('Iterations')
ax.yaxis.label.set_text('Change')
pyplot.semilogy(self.change)
pyplot.semilogy(self.output['change'])
# plot the gap
ax = pyplot.subplot(2,2,4)
ax.xaxis.label.set_text('Iterations')
ax.yaxis.label.set_text('Gap')
pyplot.semilogy(self.gap)
pyplot.semilogy(self.output['gap'])
fig.tight_layout()
fig.show()
pyplot.show()
......@@ -183,7 +183,7 @@ class P_parallel(ProxOperator):
self.n = config['Nx']
self.m = config['Ny']
self.p = config['Nz']
self.K = config['dim']
self.K = config['product_space_dimension']
self.proj = []
for p in config['projectors']:
self.proj.append(p(config))
......
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