Package parsimony :: Module estimators :: Class LinearRegressionL2SmoothedL1TV
[hide private]
[frames] | no frames]

Class LinearRegressionL2SmoothedL1TV

source code

     object --+        
              |        
  BaseEstimator --+    
                  |    
RegressionEstimator --+
                      |
                     LinearRegressionL2SmoothedL1TV

Linear regression with L2 and simultaneously smoothed L1 and TV
penalties:

    f(beta, X, y) = (1 / (2 * n)) * ||Xbeta - y||²_2
                    + (l2 / 2) * ||beta||²_2
                    + L1TV(beta),

where L1TV is l1 * L1(beta) + tv * TV(beta) smoothed together by Nesterov's
smoothing.

Parameters
----------
l2 : Non-negative float. The Lagrange multiplier, or regularisation
        constant, for the ridge (L2) penalty.

l1 : Non-negative float. The Lagrange multiplier, or regularisation
        constant, for the L1 penalty.

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

A : A list or tuple with 4 elements of (usually sparse) arrays. The linear
        operator for the smoothed L1+TV. The first element must be the
        linear operator for L1 and the following three for TV. May not be
        None.

algorithm : ExplicitAlgorithm. The algorithm that should be applied.
        Should be one of:
            1. ExcessiveGapMethod(...)

        Default is ExcessiveGapMethod(...).

algorithm_params : A dict. The dictionary algorithm_params contains
        parameters that should be set in the algorithm. Passing
        algorithm=ExcessiveGapMethod(**params) is equivalent to passing
        algorithm=ExcessiveGapMethod() and algorithm_params=params. Default
        is an empty dictionary.

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.

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

Examples
--------
>>> import numpy as np
>>> import parsimony.estimators as estimators
>>> import parsimony.algorithms.primaldual as primaldual
>>> import parsimony.functions.nesterov.l1tv as l1tv
>>> shape = (1, 4, 4)
>>> n = 10
>>> p = shape[0] * shape[1] * shape[2]
>>>
>>> np.random.seed(42)
>>> X = np.random.rand(n, p)
>>> y = np.random.rand(n, 1)
>>> l1 = 0.1  # L1 coefficient
>>> l2 = 0.9  # Ridge coefficient
>>> tv = 1.0  # TV coefficient
>>> A = l1tv.linear_operator_from_shape(shape, p, penalty_start=0)
>>> lr = estimators.LinearRegressionL2SmoothedL1TV(l2, l1, tv, A,
...                 algorithm=primaldual.ExcessiveGapMethod(),
...                 algorithm_params=dict(max_iter=1000),
...                 mean=False)
>>> res = lr.fit(X, y)
>>> error = lr.score(X, y)
>>> round(error, 14)
0.06837304969156

Instance Methods [hide private]
 
__init__(self, l2, l1, tv, A=None, algorithm=None, algorithm_params={}, penalty_start=0, mean=True)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
get_params(self)
Returns a dictionary containing all the estimator's parameters.
source code
 
fit(self, X, y, beta=None)
Fit the estimator to the data.
source code
 
score(self, X, y)
Return the mean squared error of the estimator.
source code

Inherited from RegressionEstimator: predict

Inherited from BaseEstimator: get_info, parameters, 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 RegressionEstimator: __metaclass__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, l2, l1, tv, A=None, algorithm=None, algorithm_params={}, penalty_start=0, mean=True)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

get_params(self)

source code 

Returns a dictionary containing all the estimator's parameters.

Overrides: BaseEstimator.get_params

fit(self, X, y, beta=None)

source code 

Fit the estimator to the data.

Overrides: BaseEstimator.fit

score(self, X, y)

source code 

Return the mean squared error of the estimator.

Overrides: BaseEstimator.score