Commit 38f9bb40 authored by jansen31's avatar jansen31
Browse files

building a sparsity constraint

parent f91e1f67
import numpy as np
from proxoperators import ProxOperator
from .proxoperators import ProxOperator
#original matlab comment
# P_Sparsity.m
# written on August 20, 2012 by
......@@ -10,10 +10,8 @@ from proxoperators import ProxOperator
# DESCRIPTION: Projection subroutine for projecting onto
# support constraints
#
# INPUT: input = data structure with .supp_ampl a vector of indeces of the nonzero elements of the array.
#
# INPUT: input = data structure with .supp_ampl a vector of indices of the nonzero elements of the array.
# u = array to be projected
'
# OUTPUT: p_Sparsity = the projection
#
# USAGE: p_Sparsity = P_Sparsity(input,u)
......@@ -29,7 +27,9 @@ class P_Sparsity(ProxOperator):
config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
'sparsity_parameter' : int
"""
self.sparsity_parameter = confg['sparsity_parameter']
self.sparsity_parameter = config['sparsity_parameter']
def work(self,u):
"""
Parameters
......@@ -43,7 +43,7 @@ class P_Sparsity(ProxOperator):
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
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