mojolearn.Isomap#

class mojolearn.Isomap(*, n_neighbors=5, radius=None, n_components=2, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='auto', n_jobs=None, metric='minkowski', p=2, metric_params=None, numeric_mode=None)[source]#

Bases: _Base

Isomap embedding: kernel PCA on geodesic distances.

Follows scikit-learn’s Isomap: builds a nearest-neighbor (or radius) graph, computes shortest-path distances on it, and embeds the centered kernel -0.5 * D**2 by its top eigenvectors. If the graph has more than one connected component, a warning is issued and the components are joined. Shortest paths always use Dijkstra’s algorithm, and the eigenproblem is always solved exactly.

Parameters:
  • n_neighbors (int or None, default 5) – Neighbors per point. Set to None to use radius instead.

  • radius (float or None, default None) – Connect every point within this distance (inclusive). Only one of n_neighbors and radius may be set.

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

  • eigen_solver ({“auto”, “dense”}, default “auto”) – Both solve exactly. "arpack" raises NotImplementedError.

  • tol (ignored)

  • max_iter (ignored)

  • path_method ({“auto”, “FW”, “D”}, default “auto”) – Accepted for scikit-learn compatibility; every value runs Dijkstra.

  • neighbors_algorithm (ignored)

  • n_jobs (ignored)

  • metric (str, default “minkowski”) – Distance metric: "euclidean", "l2", "minkowski" (with p), "manhattan" ("cityblock", "l1"), "chebyshev" ("infinity") or "cosine"; a callable or any other name raises NotImplementedError.

  • p (float, default 2) – Minkowski power (must be positive).

  • metric_params (dict or None, default None) – Only {"p": ...} is supported; other keys raise NotImplementedError.

  • numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default ("identical" unless changed). "identical" gives the same bits on NVIDIA and AMD GPUs; "fast" applies on Apple GPUs.

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

  • dist_matrix_ (ndarray of shape (n_samples, n_samples)) – Geodesic distances between training points.

  • n_connected_components_ (int)

  • n_features_in_ (int)

Raises:

ValueError – If both or neither of n_neighbors and radius are set, radius is negative, or path_method or eigen_solver is unknown.

Examples

>>> import numpy as np, mojolearn
>>> X = np.random.default_rng(0).random((500, 8), dtype=np.float32)
>>> Y = mojolearn.Isomap(n_neighbors=10, n_components=2).fit_transform(X)
__init__(*, n_neighbors=5, radius=None, n_components=2, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='auto', n_jobs=None, metric='minkowski', p=2, metric_params=None, numeric_mode=None)[source]#

Methods

fit(X[, y])

Compute the embedding of X.

fit_transform(X[, y])

Fit the model and return embedding_.

get_params([deep])

Return this estimator's constructor parameters.

reconstruction_error()

Return the reconstruction error of the embedding.

set_params(**params)

Set constructor parameters by keyword.

transform(X)

Embed new points.

fit(X, y=None)[source]#

Compute the embedding of X.

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

  • y (ignored)

Returns:

self

fit_transform(X, y=None)[source]#

Fit the model 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)[source]#

Embed new points.

Each query’s geodesic distance to the training points goes through its nearest training neighbors (or, with radius, every training point within the radius), then is projected as in kernel PCA.

Parameters:

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

Returns:

ndarray of shape (n_queries, n_components), float32

Raises:

ValueError – With radius, if a query has no training point within it.

reconstruction_error()[source]#

Return the reconstruction error of the embedding.

Computed as in scikit-learn: the Frobenius norm of the difference between the centered geodesic kernel and its rank-n_components approximation, divided by n_samples.

Returns:

float