Commit 330498b8 authored by robin.requadt's avatar robin.requadt
Browse files

tabs to spaces

parent fa894918
import numpy as np
from proxoperators import ProxOperator
from .proxoperators import ProxOperator
"""
#original matlab comment
% P_S_real.m
......@@ -23,31 +23,31 @@ from proxoperators import ProxOperator
"""
class P_S_real(ProxOperator):
def __init__(self,config):
"""
Initialization
def __init__(self,config):
"""
Initialization
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
'support_idx' : array_like
"""
self.support_idx = config['support_idx']
'support_idx' : array_like
"""
self.support_idx = config['support_idx']
def work(self,u):
"""
Parameters
def work(self,u):
"""
Parameters
----------
u : array_like - Input
Returns
-------
p_S : array_like
"""
support_idx = self.support_idx
p_S = np.zeros(u.shape, dtype=u.dtype)
p_S[support_idx] = np.real(u[support_idx])
return p_S
p_S : array_like
"""
support_idx = self.support_idx
p_S = np.zeros(u.shape, dtype=u.dtype)
p_S[support_idx] = np.real(u[support_idx])
return p_S
......
import numpy as np
from proxoperators import ProxOperator
#original Matlab comment
#Projects onto the intersection of hyperplanes via sequential
# projections onto the individual hyperplanes.
# For use with the ART method
# for tomographic recostruction of a
# density profile.
from .proxoperators import ProxOperator
# Russell Luke
# Universitaet Goettingen
# May 29, 2012
class P_sequential_hyperplane(ProxOperator):
"""
Projects onto the intersection of hyperplanes via sequential projections onto the individual hyperplanes.
For use with the ART method for tomographic recostruction of a density profile.
"""
def __init__(self,config):
"""
Initialization
def __init__(self,config):
"""
Initialization
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mappings:
'prox_idx' : int
'iter' : int
'MAXIT': int
'TOL' : float
'A' : array_like - list containing array_like(matrix/2d-array)
'inner_MAXIT' : int
'inner_TOL' : float
'aaT' : array_like - list containing array_like(vector/array)
'b' : array_like -list containing array_like (vector/array)
"""
self.prox_idx = config['prox_idx']
self.iter = config['iter']
self.MAXIT = config['MAXIT']
self.TOL = config['TOL']
self.A = config['A']
self.aaT = config['aaT']
self.b = config['b']
'prox_idx' : int
'iter' : int
'MAXIT': int
'TOL' : float
'A' : array_like - list containing array_like(matrix/2d-array)
'inner_MAXIT' : int
'inner_TOL' : float
'aaT' : array_like - list containing array_like(vector/array)
'b' : array_like -list containing array_like (vector/array)
"""
self.prox_idx = config['prox_idx']
self.iter = config['iter']
self.MAXIT = config['MAXIT']
self.TOL = config['TOL']
self.A = config['A']
self.aaT = config['aaT']
self.b = config['b']
if 'inner_MAXIT' in config:
self.inner_MAXIT = config['inner_MAXIT']
self.inner_TOL = config['inner_TOL']
else:
self.inner_MAXIT=10
self.inner_TOL=1e-15*((self.A)[self.prox_idx].shape)[1] #1e-15*n
if 'inner_MAXIT' in config:
self.inner_MAXIT = config['inner_MAXIT']
self.inner_TOL = config['inner_TOL']
else:
self.inner_MAXIT=10
self.inner_TOL=1e-15*((self.A)[self.prox_idx].shape)[1] #1e-15*n
def work(self,u0):
"""
Parameters
def work(self,u0):
"""
Parameters
----------
u0 : array_like - Input
......@@ -54,29 +49,28 @@ class P_sequential_hyperplane(ProxOperator):
-------
v0 : array_like - the projection IN THE PHYSICAL (time) DOMAIN onto 0 or 1.
"""
A = self.A
aaT = self.aaT
b = self.b
k = self.prox_idx
inner_MAXIT = self.inner_MAXIT
inner_TOL = self.inner_TOL
[m,n] = A[k].shape
inner_iter = 0
step = 999
while (step>inner_TOL) and (inner_iter < inner_MAXIT):
v0=u0.copy()
inner_iter +=1
for j in range(m):
a=(A[k])[j,:]
v=a*u0 / (aaT[k])[j]
u0 = u0+ np.dot(a,((b[k])[j] - v))
step=np.linalg.norm(v0-u0)
#if the hyperplanes are not orthogonal, then the above
#should be iterated in order to compute the PROJECTION of u0
#onto the affine subspace corresponding to the block. If
#the hyperplanes are orthogonal, one sweep should suffice.
return v0
A = self.A
aaT = self.aaT
b = self.b
k = self.prox_idx
inner_MAXIT = self.inner_MAXIT
inner_TOL = self.inner_TOL
[m,n] = A[k].shape
inner_iter = 0
step = 999
while (step>inner_TOL) and (inner_iter < inner_MAXIT):
v0=u0.copy()
inner_iter +=1
for j in range(m):
a=(A[k])[j,:]
v=a*u0 / (aaT[k])[j]
u0 = u0+ np.dot(a,((b[k])[j] - v))
step=np.linalg.norm(v0-u0)
#if the hyperplanes are not orthogonal, then the above
#should be iterated in order to compute the PROJECTION of u0
#onto the affine subspace corresponding to the block. If
#the hyperplanes are orthogonal, one sweep should suffice.
return v0
import numpy as np
from proxoperators import ProxOperator
# Prox_l1.m
# written on August 20, 2012 by
# Russell Luke
# Inst. Fuer Numerische und Angewandte Mathematik
# Universitaet Gottingen
#
# DESCRIPTION: Subroutine for coomputing the soft threshold (shrikage)
#
# INPUT: input = data structure with .supp_ampl a vector of indeces of the nonzero elements of the array.
#
# u = array to be projected
#
# OUTPUT: p_Sparsity = the soft thresholded result
#
# USAGE: p_Sparsity = Prox_l1(input,u)
class Prox_l1(ProxOperator):
from .proxoperators import ProxOperator
def __init__(self,config):
"""
Initialization
class Prox_l1(ProxOperator):
"""
Subroutine for coomputing the soft threshold (shrikage)
"""
def __init__(self,config):
"""
Initialization
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
'sparsity_parameter' : int
"""
self.sparsity_parameter = config['sparsity_parameter']
'sparsity_parameter' : int
"""
self.sparsity_parameter = config['sparsity_parameter']
def work(self,u):
"""
Parameters
def work(self,u):
"""
Parameters
----------
u : array_like - Input
Returns
-------
p_Sparsity : array_like
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity=u
I=u>0
I = I.astype(int) #convert boolean to int
p_Sparsity[I]=np.maximum(0,u[I]-sparsity_paramter)
I=u<0
I = I.astype(int)
p_Sparsity[I]=np.minimum(0,u[I]+sparsity_paramter)
return p_Sparsity
p_Sparsity : array_like - the soft thresholded result
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity=u
I=u>0
I = I.astype(int) #convert boolean to int
p_Sparsity[I]=np.maximum(0,u[I]-sparsity_paramter)
I=u<0
I = I.astype(int)
p_Sparsity[I]=np.minimum(0,u[I]+sparsity_paramter)
return p_Sparsity
import numpy as np
from proxoperators import ProxOperator
#original matlab comment
# Prox_nonneg_l0.m
# written on March 20, 2018 by
# Russell Luke
# Inst. Fuer Numerische und Angewandte Mathematik
# Universitaet Gottingen
#
# DESCRIPTION: Subroutine for computing the prox of the l0 function,
# i.e. hard thresholding
#
# INPUT: input = data structure with .supp_ampl a vector of indeces of the nonzero elements of the array.
#
# u = array to be projected
#
# OUTPUT: p_Sparsity = the hard thresholded result
#
# USAGE: p_Sparsity = Prox_l0_nonneg(input,u)
from .proxoperators import ProxOperator
class Prox_nonneg_l0(ProxOperator):
def __init__(self,config):
"""
Initialization
"""
Subroutine for computing the prox of the l0 function, i.e. hard thresholding
"""
def __init__(self,config):
"""
Initialization
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
'sparsity_parameter' : int
"""
self.sparsity_parameter = config['sparsity_parameter']
'sparsity_parameter' : int
"""
self.sparsity_parameter = config['sparsity_parameter']
def work(self,u):
"""
Parameters
def work(self,u):
"""
Parameters
----------
u : array_like - Input
Returns
-------
p_Sparsity : array_like
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity = np.real(u)
I = p_Sparity <= sparsity_parameter
I = I.astype(int) #convert True to 1 and False to 0
p_Sparsity[I] = 0
return p_Sparsity
p_Sparsity : array_like - the hard thresholded result
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity = np.real(u)
I = p_Sparity <= sparsity_parameter
I = I.astype(int) #convert True to 1 and False to 0
p_Sparsity[I] = 0
return p_Sparsity
......
import numpy as np
from proxoperators import ProxOperator
#original matlab comment
# Prox_nonneg_l1.m
# written on August 20, 2012 by
# Russell Luke
# Inst. Fuer Numerische und Angewandte Mathematik
# Universitaet Gottingen
#
# DESCRIPTION: Subroutine for coomputing the soft threshold (shrikage)
#
# INPUT: input = data structure with .supp_ampl a vector of indeces of the nonzero elements of the array.
#
# u = array to be projected
#
# OUTPUT: p_Sparsity = the soft thresholded result
#
# USAGE: p_Sparsity = Prox_l1(input,u)
#
# Nonstandard Matlab function calls:
from .proxoperators import ProxOperator
class Prox_nonneg_l1(ProxOperator):
def __init__(self,config):
"""
Initialization
"""
Subroutine for coomputing the soft threshold (shrikage)
"""
def __init__(self,config):
"""
Initialization
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
'sparsity_parameter' : int
"""
self.sparsity_parameter = config['sparsity_parameter']
'sparsity_parameter' : int
"""
self.sparsity_parameter = config['sparsity_parameter']
def work(self,u):
"""
Parameters
def work(self,u):
"""
Parameters
----------
u : array_like - Input
Returns
-------
p_Sparsity : array_like
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity = np.real(u)
p_Sparsity = np.maximum(0,p_Sparsity-sparsity_parameter)
return p_Sparsity
p_Sparsity : array_like - the soft thresholded result
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity = np.real(u)
p_Sparsity = np.maximum(0,p_Sparsity-sparsity_parameter)
return p_Sparsity
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