EllipticFourierAnalysis#

class ktch.harmonic.EllipticFourierAnalysis(n_harmonics: int = 20, n_dim: int = 2, reflect: bool = False, n_jobs: int | None = None, verbose: int = 0)[source]#

Elliptic Fourier Analysis (EFA)

Parameters:
n_harmonics: int, default=20

harmonics

n_dim: int, default=2

dimension

reflect: bool, default=False

reflect

Notes

EFA is widely applied for outline shape analysis in two-dimensional space [Kuhl_Giardina_1982].

\[\begin{split}\begin{align} x(l) &= \frac{a_0}{2} + \sum_{i=1}^{n} \left[ a_i \cos\left(\frac{2\pi i t}{T}\right) + b_i \sin\left(\frac{2\pi i t}{T}\right) \right]\\ y(l) &= \frac{c_0}{2} + \sum_{i=1}^{n} \left[ c_i \cos\left(\frac{2\pi i t}{T}\right) + d_i \sin\left(\frac{2\pi i t}{T}\right) \right]\\ \end{align}\end{split}\]

EFA is also applied for a closed curve in the three-dimensional space (e.g., [Lestrel_1997], [Lestrel_et_al_1997], and [Godefroy_et_al_2012]).

References

[Kuhl_Giardina_1982]

Kuhl, F.P., Giardina, C.R. (1982) Elliptic Fourier features of a closed contour. Comput. Graph. Image Process. 18: 236–258. https://doi.org/10.1016/0146-664X(82)90034-X

[Lestrel_1997]

Lestrel, P.E., 1997. Introduction and overview of Fourier descriptors, in: Fourier Descriptors and Their Applications in Biology. Cambridge University Press, pp. 22–44. https://doi.org/10.1017/cbo9780511529870.003

[Lestrel_et_al_1997]

Lestrel, P.E., Read, D.W., Wolfe, C., 1997. Size and shape of the rabbit orbit: 3-D Fourier descriptors, in: Lestrel, P.E. (Ed.), Fourier Descriptors and Their Applications in Biology. Cambridge University Press, pp. 359–378. https://doi.org/10.1017/cbo9780511529870.017

[Godefroy_et_al_2012]

Godefroy, J.E., Bornert, F., Gros, C.I., Constantinesco, A., 2012. Elliptical Fourier descriptors for contours in three dimensions: A new tool for morphometrical analysis in biology. C. R. Biol. 335, 205–213. https://doi.org/10.1016/j.crvi.2011.12.004

fit_transform(X, t=None, norm=True, return_orientation_scale=False)[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:
Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_feature_names_out(input_features: None | npt.ArrayLike = None) np.ndarray[source]#

Get output feature names.

Parameters:
input_featuresNone | npt.ArrayLike, optional

Input feature names, by default None

Returns:
feature_names_outndarray of str objects

Transformed feature names.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

inverse_transform(X_transformed, t_num=100, norm=True, as_frame=False)[source]#

Inverse analysis of elliptic Fourier analysis.

Parameters:
X_transformedarray-like of shape (n_samples, n_features)

Elliptic Fourier coefficients.

t_numint, default = 100

Number of coordinate values.

as_framebool, default = False

If True, return pd.DataFrame.

Returns:
X_coordsarray-like of shape (n_samples, t_num, 2) or pd.DataFrame

Coordinate values reconstructed from the elliptic Fourier coefficients.

set_inverse_transform_request(*, X_transformed: bool | None | str = '$UNCHANGED$', as_frame: bool | None | str = '$UNCHANGED$', norm: bool | None | str = '$UNCHANGED$', t_num: bool | None | str = '$UNCHANGED$') EllipticFourierAnalysis#

Configure whether metadata should be requested to be passed to the inverse_transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
X_transformedstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for X_transformed parameter in inverse_transform.

as_framestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for as_frame parameter in inverse_transform.

normstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for norm parameter in inverse_transform.

t_numstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for t_num parameter in inverse_transform.

Returns:
selfobject

The updated object.

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”, “polars”}, 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

Added in version 1.4: “polars” option was added.

Returns:
selfestimator instance

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_transform_request(*, norm: bool | None | str = '$UNCHANGED$', return_orientation_scale: bool | None | str = '$UNCHANGED$', t: bool | None | str = '$UNCHANGED$') EllipticFourierAnalysis#

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
normstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for norm parameter in transform.

return_orientation_scalestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for return_orientation_scale parameter in transform.

tstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for t parameter in transform.

Returns:
selfobject

The updated object.

transform(X: list(npt.ArrayLike) | npt.ArrayLike, t: npt.ArrayLike = None, norm: bool = True, return_orientation_scale: bool = False) npt.ArrayLike[source]#

EFA.

Parameters:
X: {list of array-like, array-like} of shape (n_samples, n_coords, dim)

Coordinate values of n_samples. The i-th array-like of shape (n_coords_i, 2) represents 2D coordinate values of the i-th sample.

t: array-like of shape (n_samples, n_coords), optional

Parameters indicating the position on the outline of n_samples. The i-th ndarray of shape (n_coords_i, ) corresponds to each coordinate value in the i-th element of X. If t=None, then t is calculated based on the coordinate values with the linear interpolation.

norm: bool, default=True

Normalize the elliptic Fourier coefficients by the major axis of the 1st ellipse.

return_orientation_scale: bool, default=False

Return orientation and scale of the outline. If norm=True, the orientation and scale are normalized by the 1st ellipse. Then, the orientation and scale are returned as the last columns of the output.

Returns:
X_transformed: array-like of shape (n_samples, (1+2*n_harmonics)*n_dim)

Returns the array-like of coefficients. (a_0, a_1, …, a_n, b_0, b_1, …, b_n, , c_0, c_1, …, c_n, d_0, d_1, …, d_n)