mojolearn.LocallyLinearEmbedding#

class mojolearn.LocallyLinearEmbedding(*, n_neighbors=5, n_components=2, reg=0.001, eigen_solver='auto', tol=1e-06, max_iter=100, method='standard', hessian_tol=0.0001, modified_tol=1e-12, neighbors_algorithm='auto', random_state=None, n_jobs=None, numeric_mode=None)#

Locally linear embedding.

Follows scikit-learn’s LocallyLinearEmbedding: reconstructs each point from its Euclidean nearest neighbors and finds the low-dimensional embedding that best preserves those reconstruction weights. Supports the standard, LTSA, Hessian and modified variants.

Parameters:
  • n_neighbors (int, default 5) – Neighbors per point; must be less than n_samples.

  • n_components (int, default 2) – Embedding dimension.

  • reg (float, default 1e-3) – Regularization of the local weight solves.

  • eigen_solver ({“auto”, “dense”}, default “auto”) – "dense" always runs the full exact solve. "auto" with method="standard", more than 200 samples and n_components + 1 < 10 uses an iterative solver for the smallest eigenvectors; otherwise it runs the full solve. "arpack" raises NotImplementedError.

  • tol (ignored)

  • max_iter (int, default 100) – Iteration limit of the iterative solver.

  • method ({“standard”, “ltsa”, “hessian”, “modified”}, default “standard”) – LLE variant. "hessian" needs n_neighbors > n_components * (n_components + 3) / 2; "modified" needs n_neighbors >= n_components.

  • hessian_tol (float, default 1e-4) – Tolerance for method="hessian".

  • modified_tol (float, default 1e-12) – Tolerance for method="modified".

  • neighbors_algorithm (ignored)

  • random_state (int or None, default None) – Seed of the iterative solver’s start; None means 0.

  • n_jobs (ignored)

  • numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default ("identical" unless changed). In identical mode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs. "fast" is available on Apple GPUs only.

Variables:
  • embedding_ (ndarray of shape (n_samples, n_components))

  • reconstruction_error_ (float)

  • n_features_in_ (int)

Raises:

ValueError – For an unknown method or eigen_solver, or n_neighbors out of range for the method.

Examples

>>> import numpy as np, mojolearn
>>> X = np.random.default_rng(0).random((500, 8), dtype=np.float32)
>>> Y = mojolearn.LocallyLinearEmbedding(n_neighbors=10, n_components=2).fit_transform(X)

Methods

fit(X[, y])

Compute the embedding of X.

fit_transform(X[, y])

Compute the embedding and return embedding_.

get_params([deep])

Return this estimator's constructor parameters.

set_params(**params)

Set constructor parameters by keyword.

transform(X)

Embed new points.

fit(X, y=None)#

Compute the embedding of X.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (ignored)

Returns:

self

fit_transform(X, y=None)#

Compute the embedding and return embedding_.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (ignored)

Returns:

ndarray of shape (n_samples, n_components), float32

transform(X)#

Embed new points.

Each query is written as a weighted combination of its nearest training points, and the same weights are applied to their embeddings.

Parameters:

X (array-like of shape (n_queries, n_features))

Returns:

ndarray of shape (n_queries, n_components), float32

get_params(deep=True)#

Return this estimator’s constructor parameters.

Parameters:

deep (bool, default True) – Accepted for scikit-learn compatibility; it has no effect.

Returns:

dict – Parameter name to current value.

set_params(**params)#

Set constructor parameters by keyword.

Raises:

ValueError – If a keyword is not a parameter of this estimator.

Returns:

self