pyriemann.embedding.LocallyLinearEmbedding

class pyriemann.embedding.LocallyLinearEmbedding(n_components=2, n_neighbors=5, metric='riemann', kernel=None, reg=0.001)

Locally Linear Embedding of SPD matrices.

Locally Linear Embedding (LLE) is a non-linear, neighborhood-preserving dimensionality reduction algorithm which consists of three main steps [1]. For each SPD matrix X[i] [2]:

  1. find its k-nearest neighbors k-NN(X[i]),

  2. calculate the best reconstruction of X[i] based on its k-NN,

  3. calculate a low-dimensional embedding for all matrices based on the weights in step 2.

Parameters:
n_componentsint | None, default=2

Dimensionality of projected space. If None, n_components is set to n_matrices - 1.

n_neighborsint | None, default=5

Number of neighbors for reconstruction of each matrix. If None, all available matrices are used. If n_neighbors > n_matrices, n_neighbors is set to n_matrices - 1.

metricstring, default=”riemann”

Metric used for k-NN and kernel estimation. For the list of supported metrics, see pyriemann.utils.kernel.kernel().

kernelcallable | None, default=None

Kernel function to use for the embedding. If None, the canonical kernel specified by the metric is used. Must be a function that takes the arguments (X, Cref, metric).

regfloat, default=1e-3

Regularization parameter.

Attributes:
embedding_ndarray, shape (n_matrices, n_components)

Embedding vectors of the training set.

error_float

Reconstruction error associated with embedding_.

data_ndarray, shape (n_matrices, n_channels, n_channels)

Training set.

Notes

Added in version 0.3.

References

[1]

Nonlinear Dimensionality Reduction by Locally Linear Embedding S. Roweis and L. K. Saul, in Science, Vol 290, Issue 5500, pp. 2323-2326, 2000.

[2]

Clustering and dimensionality reduction on Riemannian manifolds A. Goh and R. Vidal, in 2008 IEEE Conference on Computer Vision and Pattern Recognition

__init__(n_components=2, n_neighbors=5, metric='riemann', kernel=None, reg=0.001)
fit(X, y=None)

Fit the model from X.

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

Set of SPD matrices.

yNone

Not used, here for compatibility with sklearn API.

Returns:
selfLocallyLinearEmbedding instance

The LocallyLinearEmbedding instance.

fit_transform(X, y=None)

Fit and calculate the coordinates of the embedded matrices.

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

Set of SPD matrices.

yNone

Not used, here for compatibility with sklearn API.

Returns:
X_newndarray, shape (n_matrices, n_components)

Coordinates of embedded 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, y=None)

Calculate embedding coordinates.

Calculate embedding coordinates for new matrices based on fitted matrices.

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

Set of SPD matrices.

yNone

Not used, here for compatibility with sklearn API.

Returns:
X_newndarray, shape (n_matrices, n_components)

Coordinates of embedded matrices.