SymbolicFourierApproximation#

class pyts.approximation.SymbolicFourierApproximation(n_coefs: int | float | None = None, n_bins: int = 4, strategy: str = 'quantile', drop_sum: bool = False, anova: bool = False, norm_mean: bool = False, norm_std: bool = False, alphabet: str | ArrayLike | None = None)[source]#

Symbolic Fourier Approximation.

Parameters:
n_coefsNone, int or float (default = None)

The number of Fourier coefficients to keep. If None, all the Fourier coeeficients are kept. If an integer, the n_coefs most significant Fourier coefficients are returned if anova=True, otherwise the first n_coefs Fourier coefficients are returned. If a float, it represents a percentage of the size of each time series and must be between 0 and 1. The number of coefficients will be computed as ceil(n_coefs * (n_timestamps - 1)) if drop_sum=True and ceil(n_coefs * n_timestamps) if drop_sum=False.

n_binsint (default = 4)

The number of bins to produce. The intervals for the bins are determined by the minimum and maximum of the input data. It must be between 2 and 26.

strategystr (default = ‘quantile’)

Strategy used to define the widths of the bins:

  • ‘uniform’: All bins in each sample have identical widths

  • ‘quantile’: All bins in each sample have the same number of points

  • ‘normal’: Bin edges are quantiles from a standard normal distribution

  • ‘entropy’: Bin edges are computed using information gain

drop_sumbool (default = False)

If True, the first Fourier coefficient (i.e. the sum of the time series) is dropped. If False, the real part of the first Fourier coefficient is kept.

anovabool (default = False)

If True, the Fourier coefficient selection is done via a one-way ANOVA test. If False, the first Fourier coefficients are selected.

norm_meanbool (default = False)

If True, center the data before scaling. If norm_mean=True and anova=False, the first Fourier coefficient will be dropped.

norm_stdbool (default = False)

If True, scale the data to unit variance.

alphabetNone, ‘ordinal’ or array-like, shape = (n_bins,)

Alphabet to use. If None, the first n_bins letters of the Latin alphabet are used if n_bins is lower than 27, otherwise the alphabet will be defined to [chr(i) for i in range(n_bins)]. If ‘ordinal’, integers are used.

Attributes:
bin_edges_array, shape = (n_bins - 1,) or (n_timestamps, n_bins - 1)

Bin edges with shape = (n_bins - 1,) if strategy='normal' or (n_timestamps, n_bins - 1) otherwise.

support_array, shape = (n_coefs,)

Indices of the kept Fourier coefficients.

References

[1]

P. Schäfer, and M. Högqvist, “SFA: A Symbolic Fourier Approximation and Index for Similarity Search in High Dimensional Datasets”, International Conference on Extending Database Technology, 15, 516-527 (2012).

Examples

>>> from pyts.approximation import SymbolicFourierApproximation
>>> from pyts.datasets import load_gunpoint
>>> X, _, _, _ = load_gunpoint(return_X_y=True)
>>> transformer = SymbolicFourierApproximation(n_coefs=4)
>>> X_new = transformer.fit_transform(X)
>>> X_new.shape
(50, 4)

Methods

__init__([n_coefs, n_bins, strategy, ...])

fit(X[, y])

Select Fourier coefficients and compute bin edges for each feature.

fit_transform(X[, y])

Fit then transform the provided data.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Transform the provided data.

__init__(n_coefs: int | float | None = None, n_bins: int = 4, strategy: str = 'quantile', drop_sum: bool = False, anova: bool = False, norm_mean: bool = False, norm_std: bool = False, alphabet: str | ArrayLike | None = None) → None[source]#
fit(X: ArrayLike, y: ArrayLike | None = None) → Self[source]#

Select Fourier coefficients and compute bin edges for each feature.

Parameters:
Xarray-like, shape = (n_samples, n_timestamps)

Data to transform.

yNone or array-like, shape = (n_samples,) (default = None)

Class labels for each sample. Only used if anova=True or strategy='entropy'.

fit_transform(X: ArrayLike, y: ArrayLike | None = None) → NDArray[Any][source]#

Fit then transform the provided data.

Parameters:
Xarray-like, shape = (n_samples, n_timestamps)

Data to transform.

yNone or array-like, shape = (n_samples,)

Class labels for each sample. Only used if anova=True or strategy='entropy'.

Returns:
X_newarray-like, shape = (n_samples, n_coefs)

Transformed data.

transform(X: ArrayLike) → NDArray[Any][source]#

Transform the provided data.

Parameters:
Xarray-like, shape = (n_samples, n_timestamps)

Data to transform.

Returns:
X_newarray, shape = (n_samples, n_coefs)

Transformed data.