Commit 635b2015 authored by s.gretchko's avatar s.gretchko
Browse files

Updated P_M and P_Sparsity prox with common eval() signature

parent f6128c29
......@@ -22,7 +22,7 @@ class P_M(ProxOperator):
self.prop = experiment.propagator(experiment)
self.invprop = experiment.inverse_propagator(experiment)
def eval(self, u, **kwargs):
def eval(self, u, prox_idx=None):
"""
Applies the proxoperator P_M
......@@ -35,8 +35,6 @@ class P_M(ProxOperator):
array_like - [p_M,phat_M] ,where p_M = the projection IN THE PHYSICAL (time) DOMAIN
and phat_M = projection IN THE FOURIER DOMAIN
"""
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
m = self.data
a = self.prop.eval(u)
b = magproj(a, m)
......@@ -59,7 +57,7 @@ class P_M_masked(P_M):
super(P_M_masked, self).__init__(experiment)
self.mask = experiment.fmask == 0
def eval(self, u, **kwargs):
def eval(self, u, prox_idx=None):
"""
Applies the proxoperator P_M_masked
......@@ -71,8 +69,6 @@ class P_M_masked(P_M):
-------
array_like - p_M: the projection IN THE PHYSICAL (time) DOMAIN
"""
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
fourier_space_iterate = self.prop.eval(u)
constrained = magproj(fourier_space_iterate.copy(), self.data)
update = where(self.mask, fourier_space_iterate, constrained)
......@@ -87,9 +83,7 @@ class Approx_P_M(P_M):
self.data_ball = experiment.data_ball
self.TOL2 = experiment.TOL2
def eval(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
def eval(self, u, prox_idx=None):
u_hat = self.prop.eval(u)
u_hat_sq = abs(u_hat)**2
......@@ -117,9 +111,7 @@ class Approx_P_M_masked(P_M_masked):
self.data_ball = experiment.data_ball
self.TOL2 = experiment.TOL2
def eval(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
def eval(self, u, prox_idx=None):
u_hat = self.prop.eval(u)
u_hat_sq = abs(u_hat) ** 2
tmp = u_hat_sq / self.data_sq
......
......@@ -11,8 +11,6 @@ __all__ = ['P_Sparsity', 'P_Sparsity_real', 'P_Sparsity_Symmetric', 'P_Sparsity_
class P_Sparsity(ProxOperator):
"""
Projection subroutine for projecting onto a sparsity constraint
USAGE: p_Sparsity = P_Sparsity(config)
p_Sparsity.work(u)
"""
def __init__(self, experiment):
......@@ -48,10 +46,8 @@ class P_Sparsity(ProxOperator):
self.value_selection = value_selection
def eval(self, *args, **kwargs):
return self.work(*args, **kwargs)
def work(self, u, **kwargs):
def eval(self, u, prox_idx=None):
"""
Parameters
----------
......@@ -61,8 +57,6 @@ class P_Sparsity(ProxOperator):
-------
p_Sparsity : array_like, the projection
"""
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
u *= self.support # apply support (simple 1 if no support)
p_sparse = 0 * u
sorting = np.argsort(abs(u), axis=None) # gives indices of sorted array in ascending order
......@@ -79,10 +73,8 @@ class P_Sparsity_real(P_Sparsity):
order: realness, sparsity
"""
def work(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
return super(P_Sparsity_real, self).work(u.real)
def eval(self, u, prox_idx=None):
return super(P_Sparsity_real, self).eval(u.real, prox_idx)
class P_Sparsity_Symmetric(P_Sparsity):
......@@ -97,15 +89,13 @@ class P_Sparsity_Symmetric(P_Sparsity):
self.symmetry = experiment.symmetry_type # antisymmetric = -1, symmetric = 1
self.symmetry_axis = experiment.symmetry_axis # -1 for last, 0 for first, 'both', 'all' or None for full flip
def work(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
def eval(self, u, prox_idx=None):
if self.symmetry_axis in ['both', 'all']:
mirror = np.flip(u, axis=None)
else:
mirror = np.flip(u, axis=self.symmetry_axis)
inp = (u + self.symmetry * mirror) / 2
out = super(P_Sparsity_Symmetric, self).work(inp)
out = super(P_Sparsity_Symmetric, self).eval(inp, prox_idx)
return out
......@@ -116,10 +106,8 @@ class P_Sparsity_Symmetric_real(P_Sparsity_Symmetric):
order: realness, symmetry, sparsity
"""
def work(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
out = super(P_Sparsity_Symmetric_real, self).work(u.real)
def eval(self, u, prox_idx=None):
out = super(P_Sparsity_Symmetric_real, self).eval(u.real, prox_idx)
return out
......@@ -141,11 +129,9 @@ class P_Sparsity_Superpixel(P_Sparsity):
assert test_shape == experiment.u0.shape, 'Given array size does not allow for binning'
# TODO: allow for padding, then cut of the remainder after tile_array
def work(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
def eval(self, u, prox_idx=None):
binned = bin_array(abs(u), self.superpixel_size)
sparse_array = super(P_Sparsity_Superpixel, self).work(binned)
sparse_array = super(P_Sparsity_Superpixel, self).eval(binned, prox_idx)
mask = tile_array(sparse_array, self.superpixel_size, normalize=True) > 0
return np.where(mask, u, 0)
......@@ -154,8 +140,6 @@ class P_Sparsity_Superpixel_real(P_Sparsity_Superpixel):
"""
Apply real-valued sparsity on superpixels, i.e. on the binned array
"""
def work(self, u, **kwargs):
if kwargs:
raise NotImplementedError("Handling of keyword arguments is not yet supported")
return super(P_Sparsity_Superpixel_real, self).work(u.real)
def eval(self, u, prox_idx=None):
return super(P_Sparsity_Superpixel_real, self).eval(u.real, prox_idx)
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