Package parsimony :: Package functions :: Module penalties :: Class L0
[hide private]
[frames] | no frames]

Class L0

source code

               object --+        
                        |        
      properties.Function --+    
                            |    
    properties.AtomicFunction --+
                                |
                   object --+   |
                            |   |
           properties.Penalty --+
                                |
                   object --+   |
                            |   |
        properties.Constraint --+
                                |
                   object --+   |
                            |   |
  properties.ProximalOperator --+
                                |
                   object --+   |
                            |   |
properties.ProjectionOperator --+
                                |
                               L0

The proximal operator of the "pseudo" L0 function

    f(x) = l * (||x||_0 - c),

where ||x||_0 is the L0 loss function. The constrainted version has the
form

    ||x||_0 <= c.

Warning: Note that this function is not convex, and the regular assumptions
when using it in e.g. ISTA or FISTA will not apply. Nevertheless, it will
still converge to a local minimum if we can guarantee that we obtain a
reduction of the smooth part in each step. See e.g.:

    http://eprints.soton.ac.uk/142499/1/BD_NIHT09.pdf
    http://people.ee.duke.edu/~lcarin/blumensath.pdf

Parameters
----------
l : Non-negative float. The Lagrange multiplier, or regularisation
        constant, of the function.

c : Float. The limit of the constraint. The function is feasible if
        ||x||_0 <= c. The default value is c=0, i.e. the default is a
        regularisation formulation.

penalty_start : Non-negative integer. The number of columns, variables
        etc., to be exempt from penalisation. Equivalently, the first index
        to be penalised. Default is 0, all columns are included.

Instance Methods [hide private]
 
__init__(self, l=1.0, c=0.0, penalty_start=0)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
f(self, x)
Function value.
source code
 
prox(self, x, factor=1.0, **kwargs)
The corresponding proximal operator.
source code
 
proj(self, x)
The corresponding projection operator.
source code
 
feasible(self, beta)
Feasibility of the constraint.
source code

Inherited from properties.Function: get_params, reset, set_params

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __abstractmethods__ = frozenset([])

Inherited from properties.AtomicFunction: __metaclass__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, l=1.0, c=0.0, penalty_start=0)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

f(self, x)

source code 
Function value.

From the interface "Function".

Example
-------
>>> import numpy as np
>>> from parsimony.functions.penalties import L0
>>> import parsimony.utils.maths as maths
>>>
>>> np.random.seed(42)
>>> x = np.random.rand(10, 1)
>>> l0 = L0(l=0.5)
>>> maths.norm0(x)
10
>>> l0.f(x) - 0.5 * maths.norm0(x)
0.0
>>> x[0, 0] = 0.0
>>> maths.norm0(x)
9
>>> l0.f(x) - 0.5 * maths.norm0(x)
0.0

Overrides: properties.Function.f

prox(self, x, factor=1.0, **kwargs)

source code 
The corresponding proximal operator.

From the interface "ProximalOperator".

Example
-------
>>> import numpy as np
>>> from parsimony.functions.penalties import L0
>>> import parsimony.utils.maths as maths
>>>
>>> np.random.seed(42)
>>> x = np.random.rand(10, 1)
>>> l0 = L0(l=0.5)
>>> maths.norm0(x)
10
>>> l0.prox(x)
array([[ 0.        ],
       [ 0.95071431],
       [ 0.73199394],
       [ 0.59865848],
       [ 0.        ],
       [ 0.        ],
       [ 0.        ],
       [ 0.86617615],
       [ 0.60111501],
       [ 0.70807258]])
>>> l0.f(l0.prox(x))
3.0
>>> 0.5 * maths.norm0(l0.prox(x))
3.0

Overrides: properties.ProximalOperator.prox

proj(self, x)

source code 
The corresponding projection operator.

From the interface "ProjectionOperator".

Examples
--------
>>> import numpy as np
>>> from parsimony.functions.penalties import L0
>>>
>>> np.random.seed(42)
>>> x = np.random.rand(10, 1) * 2.0 - 1.0
>>> l0 = L0(c=5.0)
>>> l0.proj(x)
array([[ 0.        ],
       [ 0.90142861],
       [ 0.        ],
       [ 0.        ],
       [-0.68796272],
       [-0.68801096],
       [-0.88383278],
       [ 0.73235229],
       [ 0.        ],
       [ 0.        ]])

Overrides: properties.ProjectionOperator.proj

feasible(self, beta)

source code 
Feasibility of the constraint.

From the interface "Constraint".

Parameters
----------
beta : Numpy array. The variable to check for feasibility.

Examples
--------
>>> import numpy as np
>>> from parsimony.functions.penalties import L0
>>>
>>> np.random.seed(42)
>>> x = np.random.rand(10, 1) * 2.0 - 1.0
>>> l0 = L0(c=5.0)
>>> l0.feasible(x)
False
>>> l0.feasible(l0.proj(x))
True

Overrides: properties.Constraint.feasible