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

Class RidgeSquaredError

source code

              object --+        
                       |        
     properties.Function --+    
                           |    
properties.CompositeFunction --+
                               |
                  object --+   |
                           |   |
         properties.Gradient --+
                               |
                  object --+   |
                           |   |
   properties.StronglyConvex --+
                               |
                  object --+   |
                           |   |
          properties.Penalty --+
                               |
                  object --+   |
                           |   |
 properties.ProximalOperator --+
                               |
                              RidgeSquaredError

Represents a ridge squared error penalty, i.e. a representation of

    f(x) = l.((1 / (2 * n)) * ||Xb - y||²_2 + (k / 2) * ||b||²_2),

where ||.||²_2 is the L2 norm.

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

X : Numpy array (n-by-p). The regressor matrix.

y : Numpy array (n-by-1). The regressand vector.

k : Non-negative float. The ridge parameter.

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

mean : Boolean. Whether to compute the squared loss or the mean
        squared loss. Default is True, the mean squared loss.

Instance Methods [hide private]
 
__init__(self, X, y, k, l=1.0, penalty_start=0, mean=True)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
reset(self)
Free any cached computations from previous use of this Function.
source code
 
f(self, x)
Function value.
source code
 
grad(self, x)
Gradient of the function at beta.
source code
 
L(self)
Lipschitz constant of the gradient.
source code
 
parameter(self)
Returns the strongly convex parameter for the function.
source code
 
prox(self, x, factor=1.0, eps=5e-08, max_iter=100)
The proximal operator associated to this function.
source code

Inherited from properties.Function: get_params, set_params

Inherited from properties.Gradient: approx_grad

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.CompositeFunction: __metaclass__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, X, y, k, l=1.0, penalty_start=0, mean=True)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

reset(self)

source code 

Free any cached computations from previous use of this Function.

From the interface "Function".

Overrides: properties.Function.reset

f(self, x)

source code 
Function value.

From the interface "Function".

Parameters
----------
x : Numpy array. Regression coefficient vector. The point at which to
        evaluate the function.

Overrides: properties.Function.f

grad(self, x)

source code 
Gradient of the function at beta.

From the interface "Gradient".

Parameters
----------
x : Numpy array. The point at which to evaluate the gradient.

Examples
--------
>>> import numpy as np
>>> from parsimony.functions.losses import RidgeRegression
>>>
>>> np.random.seed(42)
>>> X = np.random.rand(100, 150)
>>> y = np.random.rand(100, 1)
>>> rr = RidgeRegression(X=X, y=y, k=3.14159265)
>>> beta = np.random.rand(150, 1)
>>> round(np.linalg.norm(rr.grad(beta)
...       - rr.approx_grad(beta, eps=1e-4)), 9)
1.3e-08

Overrides: properties.Gradient.grad

L(self)

source code 

Lipschitz constant of the gradient.

From the interface "LipschitzContinuousGradient".

parameter(self)

source code 

Returns the strongly convex parameter for the function.

From the interface "StronglyConvex".

Overrides: properties.StronglyConvex.parameter

prox(self, x, factor=1.0, eps=5e-08, max_iter=100)

source code 
The proximal operator associated to this function.

Parameters
----------
x : Numpy array (p-by-1). The point at which to apply the proximal
        operator.

factor : Positive float. A factor by which the Lagrange multiplier is
        scaled. This is usually the step size.

eps : Positive float. This is the stopping criterion for inexact
        proximal methods, where the proximal operator is approximated
        numerically.

max_iter : Positive integer. This is the maximum number of iterations
        for inexact proximal methods, where the proximal operator is
        approximated numerically.

index : Non-negative integer. For multivariate functions, this
        identifies the variable for which the proximal operator is
        associated.

From the interface "ProximalOperator".

Overrides: properties.ProximalOperator.prox