FisherRaoElasticRegistration#

class skfda.preprocessing.registration.FisherRaoElasticRegistration(*, template=<function fisher_rao_karcher_mean>, penalty=0, output_points=None, grid_dim=7, derivative_method=None)[source]#

Align a FDatagrid using the SRSF framework.

Let \(f\) be a function of the functional data object wich will be aligned to the template \(g\). Calculates the warping wich minimises the Fisher-Rao distance between \(g\) and the registered function \(f^*(t)=f(\gamma^*(t))=f \circ \gamma^*\).

\[\gamma^* = argmin_{\gamma \in \Gamma} d_{\lambda}(f \circ \gamma, g)\]

Where \(d_{\lambda}\) denotes the extended Fisher-Rao distance with a penalty term, used to control the amount of warping.

\[d_{\lambda}^2(f \circ \gamma, g) = \| SRSF(f \circ \gamma) \sqrt{\gamma'} - SRSF(g)\|_{\mathbb{L}^2}^2 + \lambda \mathcal{R}(\gamma)\]

In the implementation it is used as penalty term

\[\mathcal{R}(\gamma) = \|\sqrt{\gamma'}- 1 \|_{\mathbb{L}^2}^2\]

Wich restrict the amount of elasticity employed in the alignment.

The registered function \(f^*(t)\) can be calculated using the composition \(f^*(t)=f(\gamma^*(t))\).

If the template is not specified it is used the Karcher mean of the set of functions under the elastic metric to perform the alignment, also known as elastic mean, wich is the local minimum of the sum of squares of elastic distances. See elastic_mean().

In [1] are described extensively the algorithms employed and the SRSF framework.

Parameters:
  • template (Union[FDataGrid, _MeanType]) – Template to align the curves. Can contain 1 sample to align all the curves to it or the same number of samples than the fdatagrid. By default elastic mean, in which case elastic_mean() is called.

  • penalty_term – Controls the amount of elasticity. Defaults to 0.

  • output_points (Optional[ArrayLike]) – Set of points where the functions are evaluated, by default uses the sample points of the fdatagrid which will be transformed.

  • grid_dim (int) – Dimension of the grid used in the DP alignment algorithm. Defaults 7.

  • derivative_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.

  • penalty (float) –

Attributes:
  • template_ – Template learned during fitting, used for alignment in transform().

  • warping_ – Warping applied during the last transformation.

References

Examples

Elastic registration of with train/test sets.

>>> from skfda.preprocessing.registration import (
...     FisherRaoElasticRegistration,
... )
>>> from skfda.datasets import make_multimodal_samples
>>> X_train = make_multimodal_samples(n_samples=15, random_state=0)
>>> X_test = make_multimodal_samples(n_samples=3, random_state=1)

Fit the transformer, which learns the elastic mean of the train set as template.

>>> elastic_registration = FisherRaoElasticRegistration()
>>> elastic_registration.fit(X_train)
FisherRaoElasticRegistration(...)

Registration of the test set.

>>> elastic_registration.transform(X_test)
FDataGrid(...)

Methods

fit(X[, y])

Fit the registration model.

fit_transform(X[, y])

Fit the registration model and return the registered data.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

inverse_transform(X[, y])

Reverse the registration procedure previosly applied.

score(X[, y])

Return the percentage of total variation removed.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

transform(X[, y])

Register new data.

fit(X, y=None)[source]#

Fit the registration model.

Parameters:
  • X (FDataGrid) – Original (unregistered) training data.

  • y (object) – Ignored.

  • self (SelfType) –

Returns:

Returns the instance itself.

Return type:

SelfType

fit_transform(X, y=None, **fit_params)[source]#

Fit the registration model and return the registered data.

Parameters:
  • X (Input) – Original (unregistered) training data.

  • y (object) – Ignored.

  • fit_params (Any) – Additional fit parameters.

Returns:

Registered training data.

Return type:

Output

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

inverse_transform(X, y=None)[source]#

Reverse the registration procedure previosly applied.

Let \(gamma(t)\) the warping applied to construct a registered functional datum \(f^*(t)=f(\gamma(t))\).

Given a functional datum \(f^*(t) it is computed :math:\)gamma^{-1}(t)` to reverse the registration procedure \(f(t)=f^*(\gamma^{-1}(t))\).

Parameters:
  • X (FDataGrid) – Functional data to apply the reverse transform.

  • y (object) – Present for API conventions.

Returns:

Functional data compose by the inverse warping.

Raises:

ValueError – If the warpings \(\gamma\) were not build via transform() or if the number of samples of X is different than the number of samples of the dataset previously transformed.

Return type:

FDataGrid

Examples

Center the datasets taking into account the misalignment.

>>> from skfda.preprocessing.registration import (
...     FisherRaoElasticRegistration,
... )
>>> from skfda.datasets import make_multimodal_samples
>>> X = make_multimodal_samples(random_state=0)

Registration of the dataset.

>>> elastic_registration = FisherRaoElasticRegistration()
>>> X = elastic_registration.fit_transform(X)

Substract the elastic mean build as template during the registration and reverse the transformation.

>>> X = X - elastic_registration.template_
>>> X_center = elastic_registration.inverse_transform(X)
>>> X_center
FDataGrid(...)

See also

invert_warping()

score(X, y=None)[source]#

Return the percentage of total variation removed.

Computes the squared multiple correlation index of the proportion of the total variation due to phase, defined as:

\[R^2 = \frac{\text{MSE}_{phase}}{\text{MSE}_{total}},\]

where \(\text{MSE}_{total}\) is the mean squared error and \(\text{MSE}_{phase}\) is the mean squared error due to the phase explained by the registration procedure. See AmplitudePhaseDecomposition for a detailed explanation.

Parameters:
  • X (Input) – Functional data to be registered

  • y (object) – Ignored, only for API conventions.

Returns:

Registration score.

Return type:

float

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]#

Register new data.

Parameters:
Returns:

Registered data.

Return type:

FDataGrid

Examples using skfda.preprocessing.registration.FisherRaoElasticRegistration#

Elastic registration

Elastic registration

Pairwise alignment

Pairwise alignment

Voice signals: smoothing, registration, and classification

Voice signals: smoothing, registration, and classification