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

Class L2Squared

source code

                        object --+        
                                 |        
               properties.Function --+    
                                     |    
             properties.AtomicFunction --+
                                         |
                            object --+   |
                                     |   |
                   properties.Gradient --+
                                         |
                            object --+   |
                                     |   |
properties.LipschitzContinuousGradient --+
                                         |
                            object --+   |
                                     |   |
                    properties.Penalty --+
                                         |
                            object --+   |
                                     |   |
                 properties.Constraint --+
                                         |
                            object --+   |
                                     |   |
           properties.ProximalOperator --+
                                         |
                            object --+   |
                                     |   |
         properties.ProjectionOperator --+
                                         |
                                        L2Squared

The proximal operator of the squared L2 function with a penalty
formulation

    f(eta) = l * (0.5 * ||eta||²_2 - c),

where ||eta||²_2 is the squared L2 loss function. The constrained
version has the form

    0.5 * ||eta||²_2 <= c.

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
        0.5 * ||eta||²_2 <= c. The default value is c=0, i.e. the
        default is a regularised 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, beta)
Function value.
source code
 
grad(self, beta)
Gradient of the function.
source code
 
L(self)
Lipschitz constant of the gradient.
source code
 
prox(self, beta, factor=1.0, **kwargs)
The corresponding proximal operator.
source code
 
proj(self, beta, **kwargs)
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 properties.Gradient: approx_grad

Inherited from properties.LipschitzContinuousGradient: approx_L

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, beta)

source code 

Function value.

From the interface "Function".

Overrides: properties.Function.f

grad(self, beta)

source code 
Gradient of the function.

From the interface "Gradient".

Example
-------
>>> import numpy as np
>>> from parsimony.functions.penalties import L2Squared
>>>
>>> np.random.seed(42)
>>> beta = np.random.rand(100, 1)
>>> l2 = L2Squared(l=3.14159, c=2.71828)
>>> np.linalg.norm(l2.grad(beta)
...                - l2.approx_grad(beta, eps=1e-4)) < 5e-10
True
>>>
>>> l2 = L2Squared(l=3.14159, c=2.71828, penalty_start=5)
>>> np.linalg.norm(l2.grad(beta)
...                - l2.approx_grad(beta, eps=1e-4)) < 5e-10
True

Overrides: properties.Gradient.grad

L(self)

source code 

Lipschitz constant of the gradient.

Overrides: properties.LipschitzContinuousGradient.L

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

source code 

The corresponding proximal operator.

From the interface "ProximalOperator".

Overrides: properties.ProximalOperator.prox

proj(self, beta, **kwargs)

source code 
The corresponding projection operator.

From the interface "ProjectionOperator".

Examples
--------
>>> import numpy as np
>>> from parsimony.functions.penalties import L2Squared
>>> np.random.seed(42)
>>> l2 = L2Squared(c=0.3183098861837907)
>>> y1 = l2.proj(np.random.rand(100, 1) * 2.0 - 1.0)
>>> round(0.5 * np.linalg.norm(y1) ** 2.0, 15)
0.318309886183791
>>> y2 = np.random.rand(100, 1) * 2.0 - 1.0
>>> l2.feasible(y2)
False
>>> l2.feasible(l2.proj(y2))
True

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 L2Squared
>>> np.random.seed(42)
>>> l2 = L2Squared(c=0.3183098861837907)
>>> y1 = 0.1 * (np.random.rand(50, 1) * 2.0 - 1.0)
>>> l2.feasible(y1)
True
>>> y2 = 10.0 * (np.random.rand(50, 1) * 2.0 - 1.0)
>>> l2.feasible(y2)
False
>>> y3 = l2.proj(50.0 * np.random.rand(100, 1) * 2.0 - 1.0)
>>> l2.feasible(y3)
True

Overrides: properties.Constraint.feasible