Commit 949f352d authored by jansen31's avatar jansen31
Browse files

refactor

parent 21aa619a
......@@ -213,8 +213,3 @@ class Algorithm:
s = exp(a)
lmbda = s*self.lambda_0 + (1-s)*self.lambda_max
return lmbda
@staticmethod
def phase_offset_compensated_norm(arr1, arr2, norm_factor=1, norm_type='fro'):
phase_offset = angle(sum(arr1 * arr2.conj()))
return norm(arr1 - arr2 * exp(1j * phase_offset), norm_type) / norm_factor
......@@ -192,7 +192,7 @@ class PlanarMolecule(OrbitalTomographyExperiment):
bx4.set_ylabel('Gap')
f.tight_layout()
h, ax = plt.subplots(1, 3, figsize=(9,3))
h, ax = plt.subplots(1, 3, figsize=(9, 3))
ax[0].imshow(self.data)
ax[0].set_title("Measured data")
prop = self.propagator(self)
......
......@@ -19,9 +19,10 @@ class P_Sparsity(ProxOperator):
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mappings:
'sparsity_parameter' : int
experiment : class with the attribute 'sparsity_parameter', which should be an integer
indicating the number of pixels allowed by the projection
"""
super(P_Sparsity, self).__init__(experiment)
self.sparsity_parameter = experiment.sparsity_parameter
if hasattr(experiment, 'use_sparsity_with_support') and experiment.use_sparsity_with_support:
......@@ -46,7 +47,6 @@ class P_Sparsity(ProxOperator):
self.value_selection = value_selection
def eval(self, u, prox_idx=None):
"""
Parameters
......@@ -150,6 +150,7 @@ class P_nonneg_sparsity(ProxOperator):
"""
def __init__(self, experiment):
super().__init__(experiment)
self.sparsity_parameter = experiment.sparsity_parameter
def eval(self, u, prox_idx=None):
......
from proxtoolbox.proxoperators.proxoperator import ProxOperator
from proxtoolbox import proxoperators
import numpy as np
# Prox operators used by Sudoku experiment
class SudokuProx(ProxOperator):
"""
Projection onto the given entries in a Sudoku problem
"""
def __init__(self, experiment):
self.given = experiment.sudoku.copy()
self.Nx = experiment.Nx
......@@ -21,12 +21,11 @@ class ProjGiven(SudokuProx):
"""
Projection onto the given entries in a Sudoku problem
"""
def __init__(self, experiment):
super(ProjGiven, self).__init__(experiment)
self.given = experiment.sudoku.copy()
def eval(self, u, prox_idx=None):
"""
Applies the prox operator to the input data
......@@ -43,27 +42,27 @@ class ProjGiven(SudokuProx):
A : array-like
The projection.
"""
A = np.zeros((self.Nx,self.Ny,self.Nz),dtype=u.dtype)
A = np.zeros((self.Nx, self.Ny, self.Nz), dtype=u.dtype)
for x in range(self.Nx):
for y in range(self.Ny):
z = int(self.given[x,y])
z = int(self.given[x, y])
if z > 0:
A[x,y,z-1] = 1
A[x, y, z - 1] = 1
else:
A[x,y,np.argmax(u[x,y,:])] = 1
A[x, y, np.argmax(u[x, y, :])] = 1
return A
class ProjSquare(SudokuProx):
"""
Projection onto the given entries in a Sudoku problem
"""
def __init__(self, experiment):
super(ProjSquare, self).__init__(experiment)
def eval(self, u, prox_idx=None):
"""
Applies the prox operator to the input data
......@@ -80,25 +79,25 @@ class ProjSquare(SudokuProx):
Q : array-like
The projection.
"""
Q = np.zeros((self.Nx,self.Ny,self.Nz), dtype=u.dtype)
Q = np.zeros((self.Nx, self.Ny, self.Nz), dtype=u.dtype)
for z in range(self.Nz):
for x in range(0,9,3):
for y in range(0,9,3):
v = np.argmax(u[x:(x+3),y:(y+3),z],axis=0)
w = np.argmax(np.amax(u[x:(x+3),y:(y+3),z],axis=0))
Q[x+v[w],y+w,z] = 1
for x in range(0, 9, 3):
for y in range(0, 9, 3):
v = np.argmax(u[x:(x + 3), y:(y + 3), z], axis=0)
w = np.argmax(np.amax(u[x:(x + 3), y:(y + 3), z], axis=0))
Q[x + v[w], y + w, z] = 1
return Q
class ProjColumn(SudokuProx):
"""
Projection onto the given entries in a Sudoku problem
"""
def __init__(self, experiment):
super(ProjColumn, self).__init__(experiment)
def eval(self, u, prox_idx=None):
"""
Applies the prox operator to the input data
......@@ -115,22 +114,22 @@ class ProjColumn(SudokuProx):
C : array-like
The projection.
"""
C = np.zeros((self.Nx,self.Ny,self.Nz), dtype=u.dtype)
C = np.zeros((self.Nx, self.Ny, self.Nz), dtype=u.dtype)
for x in range(self.Nx):
for z in range(self.Nz):
y = np.argmax(u[x,:,z])
C[x,y,z] = 1
y = np.argmax(u[x, :, z])
C[x, y, z] = 1
return C
class ProjRow(SudokuProx):
"""
Projection onto the given entries in a Sudoku problem
"""
def __init__(self, experiment):
super(ProjRow, self).__init__(experiment)
def eval(self, u, prox_idx=None):
"""
Applies the prox operator to the input data
......@@ -147,9 +146,9 @@ class ProjRow(SudokuProx):
C : array-like
The projection.
"""
R = np.zeros((self.Nx,self.Ny,self.Nz), dtype=u.dtype)
R = np.zeros((self.Nx, self.Ny, self.Nz), dtype=u.dtype)
for y in range(self.Ny):
for z in range(self.Nz):
x = np.argmax(u[:,y,z])
R[x,y,z] = 1
x = np.argmax(u[:, y, z])
R[x, y, z] = 1
return R
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