SRSF#
- class skfda.misc.operators.SRSF(*, output_points=None, initial_value=None, method=None)[source]#
Square-Root Slope Function (SRSF) transform.
Let \(f : [a,b] \rightarrow \mathbb{R}\) be an absolutely continuous function, the SRSF transform is defined as
\[SRSF(f(t)) = sgn(f'(t)) \sqrt{|f'(t)|} = q(t)\]This representation it is used to compute the extended non-parametric Fisher-Rao distance between functions, wich under the SRSF representation becomes the usual \(\mathbb{L}^2\) distance between functions. See [1].
The inverse SRSF transform is defined as
\[f(t) = f(a) + \int_{a}^t q(t)|q(t)|dt .\]This transformation is a mapping up to constant. Given the SRSF and the initial value \(f(a)\) the original function can be obtained, for this reason it is necessary to store the value \(f(a)\) during the fit, which is dropped due to derivation. If it is applied the inverse transformation without fit the estimator it is assumed that \(f(a)=0\).
- Parameters:
eval_points – (array_like, optional): Set of points where the functions are evaluated, by default uses the sample points of the
FDataGrid
transformed.initial_value (float, optional) – Initial value to apply in the inverse transformation. If None there are stored the initial values of the functions during the transformation to apply during the inverse transformation. Defaults None.
method (Optional[Basis]) – Method to use to compute the derivative. If
None
(the default), finite differences are used. In a basis object is passed the grid is converted to a basis representation and the derivative is evaluated using that representation.output_points (Optional[ArrayLike]) –
- Attributes:
eval_points – Set of points where the functions are evaluated, by default uses the grid points of the fdatagrid.
initial_value – Initial value to apply in the inverse transformation. If None there are stored the initial values of the functions during the transformation to apply during the inverse transformation. Defaults None.
Note
Due to the use of derivatives it is recommended that the samples are sufficiently smooth, or have passed a smoothing preprocessing before, in order to achieve good results.
References
Examples
Create a toy dataset and apply the transformation and its inverse.
>>> from skfda.datasets import make_sinusoidal_process >>> from skfda.misc.operators import SRSF >>> fd = make_sinusoidal_process(error_std=0, random_state=0) >>> srsf = SRSF() >>> srsf SRSF(...)
Fits the estimator (to apply the inverse transform) and apply the SRSF
>>> q = srsf.fit_transform(fd)
Apply the inverse transform.
>>> fd_pull_back = srsf.inverse_transform(q)
The original and the pull back fd are almost equal
>>> zero = fd - fd_pull_back >>> zero.data_matrix.flatten().round(3) array([ 0., 0., 0., ..., -0., -0., -0.])
Methods
fit
(X[, y])Return self.
fit_transform
(X[, y])Fit to data, then transform it.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
inverse_transform
(X[, y])Compute the inverse SRSF transform.
set_output
(*[, transform])Set output container.
set_params
(**params)Set the parameters of this estimator.
transform
(X[, y])Compute the square-root slope function (SRSF) transform.
- fit_transform(X, y=None, **fit_params)[source]#
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).
**fit_params (dict) – Additional fit parameters.
- Returns:
X_new – Transformed array.
- Return type:
ndarray array of shape (n_samples, n_features_new)
- 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.
- inverse_transform(X, y=None)[source]#
Compute the inverse SRSF transform.
Given the srsf and the initial value the original function can be obtained as [1]:
\[f(t) = f(a) + \int_{a}^t q(t)|q(t)|dt\]where \(q(t)=SRSF(f(t))\).
If it is applied this inverse transformation without fitting the estimator it is assumed that \(f(a)=0\).
- Parameters:
X (FDataGrid) – SRSF to be transformed.
y (None) – Present for API conventions.
- Returns:
Functions in the original space.
- Raises:
ValueError – If functions are multidimensional.
- Return type:
- set_output(*, transform=None)#
Set output container.
See Introducing the set_output API for an example on how to use the API.
- Parameters:
transform ({"default", "pandas"}, default=None) –
Configure output of transform and fit_transform.
”default”: Default output format of a transformer
”pandas”: DataFrame output
”polars”: Polars output
None: Transform configuration is unchanged
New in version 1.4: “polars” option was added.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- 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
- transform(X, y=None)[source]#
Compute the square-root slope function (SRSF) transform.
Let \(f : [a,b] \rightarrow \mathbb{R}\) be an absolutely continuous function, the SRSF transform is defined as [1]:
\[SRSF(f(t)) = sgn(f'(t)) \sqrt{f'(t)|} = q(t)\]- Parameters:
- Returns:
SRSF functions.
- Raises:
ValueError – If functions are not univariate.
- Return type: