pyriemann.estimation.Kernels

class pyriemann.estimation.Kernels(metric='linear', n_jobs=None, **kwds)

Estimation of kernel matrices between channels of time series.

Perform a kernel matrix estimation for each given time series, evaluating a kernel function between each pair of channels (rather than between pairs of time samples) and allowing to extract nonlinear channel relationship [1].

For an input time series \(X \in \mathbb{R}^{c \times t}\), composed of \(c\) channels and \(t\) time samples, kernel function \(\kappa()\) is computed between channels \(i\) and \(j\):

\[K_{i,j} = \kappa \left( X[i], X[j] \right)\]

Linear kernel is related to pyriemann.estimation.Covariances [1], but this class allows to generalize to nonlinear relationships.

Parameters:
metricstring, default=’linear’

The metric to use when computing kernel function between channels [2]: “linear”, “poly”, “polynomial”, “rbf”, “laplacian”, “cosine”.

n_jobsint, default=None

The number of jobs to use for the computation [2]. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel.

**kwdsdict

Any further parameters are passed directly to the kernel function [2].

See also

Covariances

Notes

Added in version 0.4.

References

__init__(metric='linear', n_jobs=None, **kwds)

Init.

fit(X, y=None)

Fit.

Do nothing. For compatibility purpose.

Parameters:
Xndarray, shape (n_matrices, n_channels, n_times)

Multi-channel time-series.

yNone

Not used, here for compatibility with sklearn API.

Returns:
selfKernels instance

The Kernels instance.

fit_transform(X, y=None)

Fit and transform in a single function.

Estimate kernel matrices from time series.

Parameters:
Xndarray, shape (n_matrices, n_channels, n_times)

Multi-channel time-series.

yNone

Not used, here for compatibility with sklearn API.

Returns:
X_newndarray, shape (n_matrices, n_channels, n_channels)

Kernel matrices.

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.

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.

transform(X)

Estimate kernel matrices from time series.

Parameters:
Xndarray, shape (n_matrices, n_channels, n_times)

Multi-channel time-series.

Returns:
X_newndarray, shape (n_matrices, n_channels, n_channels)

Kernel matrices.

Examples using pyriemann.estimation.Kernels

Compare covariance and kernel estimators

Compare covariance and kernel estimators

Classify fNIRS data with block diagonal matrices for HbO and HbR

Classify fNIRS data with block diagonal matrices for HbO and HbR