Commit 1eff1f4f authored by jansen31's avatar jansen31
Browse files

reformat code

parent 1c19c852
import numpy as np
from .proxoperators import ProxOperator
#original matlab comment
# original matlab comment
# P_Sparsity.m
# written on August 20, 2012 by
# Russell Luke
......@@ -15,37 +17,34 @@ from .proxoperators import ProxOperator
# OUTPUT: p_Sparsity = the projection
#
# USAGE: p_Sparsity = P_Sparsity(input,u)
class P_Sparsity(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:
'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 = 0*u
I = np.argsort(abs(u)) #gives indices of sorted array in ascending order
I = np.flip(I, axis=0) #reverses the array so that I gives the indices of sorted array in descending order
p_Sparsity[I[0:sparsity_parameter]] = u[I[0:sparsity_parameter]]
return p_Sparsity
p_Sparsity : array_like
"""
sparsity_parameter = self.sparsity_parameter
p_Sparsity = 0 * u
I = np.argsort(abs(u)) # gives indices of sorted array in ascending order
I = np.flip(I, axis=0) # reverses the array so that I gives the indices of sorted array in descending order
p_Sparsity[I[0:sparsity_parameter]] = u[I[0:sparsity_parameter]]
return p_Sparsity
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