AmplitudePhaseDecomposition#

class skfda.preprocessing.registration.validation.AmplitudePhaseDecomposition[source]#

Compute mean square error measures for amplitude and phase variation.

Once the registration has taken place, this function computes two mean squared error measures, one for amplitude variation, and the other for phase variation and returns a squared multiple correlation index of the amount of variation in the unregistered functions is due to phase.

Let \(x_i(t),y_i(t)\) be the unregistered and registered functions respectively. The total mean square error measure (see [RGS09-8-5]) is defined as

\[\text{MSE}_{total}= \frac{1}{N}\sum_{i=1}^{N}\int[x_i(t)-\overline x(t)]^2dt\]

The measures of amplitude and phase mean square error are

\[\text{MSE}_{amp} = C_R \frac{1}{N} \sum_{i=1}^{N} \int \left [ y_i(t) - \overline{y}(t) \right ]^2 dt\]
\[\text{MSE}_{phase}= C_R \int \overline{y}^2(t) dt - \int \overline{x}^2(t) dt\]

where the constant \(C_R\) is defined as

\[C_R = \frac{\frac{1}{N}\sum_{i=1}^{N}\int[x_i(t)-\overline x(t)]^2dt }{\frac{1}{N}\sum_{i=1}^{N}\int[y_i(t)-\overline y(t)]^2dt}\]

whose structure is related to the covariation between the deformation functions \(Dh_i(t)\) and the squared registered functions \(y_i^2(t)\). When these two sets of functions are independents \(C_R=1\), as in the case of shift registration.

The total mean square error is decomposed in the two sources of variability.

\[\text{MSE}_{total} = \text{MSE}_{amp} + \text{MSE}_{phase}\]

The squared multiple correlation index of the proportion of the total variation due to phase is defined as:

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

See [KR08-3] for a detailed explanation.

Attributes:
  • return_stats (boolean, optional) – If true returns a named tuple with four values: \(R^2\), \(MSE_{amp}\), \(MSE_{pha}\) and \(C_R\). Otherwise the squared correlation index \(R^2\) is returned. Default False.

  • eval_points (array_like, optional) – Set of points where the functions are evaluated to obtain a discrete representation and perform the calculation.

Parameters:
  • estimator (RegistrationTransformer) – Registration transformer.

  • X (FData) – Unregistered functions.

  • y (FData, optional) – Target data, generally the same as X. By default ‘None’, which uses X as target.

Returns:

squared correlation index \(R^2\) if return_stats is False. Otherwise a named tuple containing:

  • r_squared: Squared correlation index \(R^2\).

  • mse_amp: Mean square error of amplitude \(\text{MSE}_{amp}\).

  • mse_pha: Mean square error of phase \(\text{MSE}_{pha}\).

  • c_r: Constant \(C_R\).

Return type:

(float or NamedTuple)

Raises:

ValueError – If the functional data is not univariate.

References

[KR08-3]

Kneip, Alois & Ramsay, James. (2008). Quantifying amplitude and phase variation. In Combining Registration and Fitting for Functional Models (pp. 14-15). Journal of the American Statistical Association.

[RGS09-8-5]

Ramsay J.O., Giles Hooker & Spencer Graves (2009). In Functional Data Analysis with R and Matlab (pp. 125-126). Springer.

Examples

Calculate the score of the shift registration of a sinusoidal process synthetically generated.

>>> from skfda.preprocessing.registration.validation import \
...                                         AmplitudePhaseDecomposition
>>> from skfda.preprocessing.registration import (
...     LeastSquaresShiftRegistration,
... )
>>> from skfda.datasets import make_sinusoidal_process
>>> X = make_sinusoidal_process(error_std=0, random_state=0)

Fit the registration procedure.

>>> shift_registration = LeastSquaresShiftRegistration()
>>> shift_registration.fit(X)
LeastSquaresShiftRegistration(...)

Compute the \(R^2\) correlation index

>>> scorer = AmplitudePhaseDecomposition()
>>> score = scorer(shift_registration, X)
>>> round(score, 3)
0.971

Also it is possible to get all the values of the decomposition:

>>> X_reg = shift_registration.transform(X)
>>> stats = scorer.stats(X, X_reg)
>>> round(stats.r_squared, 3)
0.971
>>> round(stats.mse_amplitude, 3)
0.006
>>> round(stats.mse_phase, 3)
0.214
>>> round(stats.c_r, 3)
0.976

Methods

score_function(X, y)

Compute the score of the transformation performed.

stats(X, y)

Compute the decomposition statistics.

score_function(X, y)[source]#

Compute the score of the transformation performed.

Parameters:
  • X (FData) – Original functional data.

  • y (FData) – Functional data registered.

Returns:

Score of the transformation.

Return type:

float

stats(X, y)[source]#

Compute the decomposition statistics.

Parameters:
  • X (FData) – Original functional data.

  • y (FData) – Functional data registered.

Returns:

The decomposition statistics.

Return type:

AmplitudePhaseDecompositionStats