pyts.approximation.SymbolicFourierApproximation

class pyts.approximation.SymbolicFourierApproximation(n_coefs=None, n_bins=4, strategy='quantile', drop_sum=False, anova=False, norm_mean=False, norm_std=False, alphabet=None)[source]

Symbolic Fourier Approximation.

Parameters:
n_coefs : None, 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_bins : int (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.

strategy : str (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_sum : bool (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.

anova : bool (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_mean : bool (default = False)

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

norm_std : bool (default = False)

If True, scale the data to unit variance.

alphabet : None, ‘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.

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)
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.

Methods

__init__([n_coefs, n_bins, strategy, …]) Initialize self.
fit(X[, y]) Select Fourier coefficients and compute bin edges for each feature.
fit_transform(X[, y]) Fit then transform the provided data.
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=None, n_bins=4, strategy='quantile', drop_sum=False, anova=False, norm_mean=False, norm_std=False, alphabet=None)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y=None)[source]

Select Fourier coefficients and compute bin edges for each feature.

Parameters:
X : array-like, shape = (n_samples, n_timestamps)

Data to transform.

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

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

fit_transform(X, y=None)[source]

Fit then transform the provided data.

Parameters:
X : array-like, shape = (n_samples, n_timestamps)

Data to transform.

y : None or array-like, shape = (n_samples,)

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

Returns:
X_new : array-like, shape = (n_samples, n_coefs)

Transformed data.

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 : dict

Parameter names mapped to their values.

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

Estimator instance.

transform(X)[source]

Transform the provided data.

Parameters:
X : array-like, shape = (n_samples, n_timestamps)

Data to transform.

Returns:
X_new : array, shape = (n_samples, n_coefs)

Transformed data.