L2Regularization#

class skfda.misc.regularization.L2Regularization(linear_operator=None, *, regularization_parameter=1)[source]#

Implements \(L_2\) (Tikhonov) regularization.

The penalization term in this type of regularization is the square of the \(L_2\) (Euclidean) norm of a linear operator applied to the function or vector

\[\lambda \| \Gamma x \|_2^2\]

where \(\Gamma\) is the so called Tikhonov operator (matrix for finite vectors) and \(\lambda\) is a positive real number.

This linear operator can be an arbitrary Python callable that correspond to a linear transformation. However, the operators module provides several common linear operators.

Parameters:
  • linear_operator (Optional[Operator[OperatorInput, Any]]) – Linear operator used for regularization. By default the second derivative, which is related with the function curvature, is penalized.

  • regularization_parameter (float) – Scaling parameter (\(\lambda\)) of the penalization.

Examples

Construct a regularization that penalizes the second derivative, which is a measure of the curvature of the function.

>>> from skfda.misc.regularization import L2Regularization
>>> from skfda.misc.operators import LinearDifferentialOperator
>>>
>>> regularization = L2Regularization(
...                     LinearDifferentialOperator(2),
... )

By default the regularization penalizes the identity operator:

>>> regularization = L2Regularization()

Construct a regularization that penalizes the difference between the points \(f(1)\) and \(f(0)\) of a function \(f\).

>>> regularization = L2Regularization(lambda x: x(1) - x(0))

Construct a regularization that penalizes the harmonic acceleration operator \(Lf = \omega^2 D f + D^3 f\), that, when the regularization parameter is large, forces the function to be \(f(t) = c_1 + c_2 \sin \omega t + c_3 \cos \omega t\), where \(\omega\) is the angular frequency. This is useful for some periodic functions.

>>> import numpy as np
>>>
>>> period = 1
>>> w = 2 * np.pi / period
>>> regularization = L2Regularization(
...                     LinearDifferentialOperator([0, w**2, 0, 1]),
... )

Methods

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

penalty_matrix(basis)

Return a penalty matrix for ordinary least squares.

set_params(**params)

Set the parameters of this estimator.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)#

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

penalty_matrix(basis)[source]#

Return a penalty matrix for ordinary least squares.

Parameters:

basis (OperatorInput) –

Return type:

ndarray[Any, dtype[float64]]

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance