topo.layouts.projector

Module Contents

Classes

Projector

A scikit-learn compatible class that handles all projection methods.

Functions

_remove_anchor_anchor_edges(edges, data, anchors)

Attributes

_have_hnswlib

_have_nmslib

_have_annoy

_have_faiss

_HAS_PYMDE

topo.layouts.projector._have_hnswlib = True
topo.layouts.projector._have_nmslib = True
topo.layouts.projector._have_annoy = True
topo.layouts.projector._have_faiss = True
class topo.layouts.projector.Projector(n_components=2, projection_method='MAP', metric='euclidean', n_neighbors=10, n_jobs=1, landmarks=None, landmark_method='kmeans', num_iters=800, init='spectral', nbrs_backend='nmslib', keep_estimator=False, random_state=None, verbose=False)

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

A scikit-learn compatible class that handles all projection methods. Ideally, it takes in either a orthonormal eigenbasis or a graph kernel learned from such an eigenbasis. It is included in TopOMetry to allow custom TopOGraph-like pipelines (projection is the final step).

Parameters:
  • n_components (int (optional, default 2).) – Number of dimensions to optimize the layout to. Usually 2 or 3 if you’re into visualizing data.

  • projection_method (str (optional, default 'Isomap').) –

    Which projection method to use. Only ‘Isomap’, ‘t-SNE’ and ‘MAP’ are implemented out of the box. ‘t-SNE’ uses and ‘MAP’ relies on code that is adapted from UMAP. Current options are:

    These are frankly quite direct to add, so feel free to make a feature request if your favorite method is not listed here.

  • metric (str (optional, default 'euclidean').) – The metric to use when computing distances. Possible values are: ‘cosine’, ‘euclidean’ and others. Accepts precomputed distances (‘precomputed’).

  • n_neighbors (int (optional, default 10).) – The number of neighbors to use when computing the kernel matrix. Ignored if pairwise set to True.

  • landmarks (int or np.ndarray (optional, default None).) – If passed as int, will obtain the number of landmarks. If passed as np.ndarray, will use the specified indexes in the array. Any value other than None will result in only the specified landmarks being used in the layout optimization, and will populate the Projector.landmarks_ slot.

  • landmark_method (str (optional, default 'kmeans').) – The method to use for selecting landmarks. If landmarks is passed as an int, this will be used to select the landmarks. Can be either ‘kmeans’ or ‘random’.

  • num_iters (int (optional, default 1000).) – Most (if not all) methods optimize the layout up to a limit number of iterations. Use this parameter to set this number.

  • keep_estimator (bool (optional, default False).) – Whether to keep the used estimator as Projector.estimator_ after fitting. Useful if you want to use it later (e.g. UMAP allows inverse transforms and out-of-sample mapping).

__repr__()

Return repr(self).

_parse_backend()
fit(X, **kwargs)

Calls the desired projection method on the specified data.

Parameters:
  • X (array-like, shape (n_samples, n_features) or topo.Kernel() class.) – The set of points to compute the kernel matrix for. Accepts np.ndarrays and scipy.sparse matrices or a topo.Kernel() object. If precomputed, assumed to be a square symmetric semidefinite matrix.

  • kwargs (dict (optional, default {}).) – Additional keyword arguments for the desired projection method.

Returns:

Projector() class with populated Projector.Y_ attribute.

transform(X=None)

Calls the transform method of the desired method. If the desired method does not have a transform method, calls the results from the fit method.

Returns:

Y (np.ndarray (n_samples, n_components).) – Projection results

fit_transform(X, **kwargs)

Calls the fit_transform method of the desired method. If the desired method does not have a fit_transform method, calls the results from the fit method.

Returns:

Y (np.ndarray (n_samples, n_components).) – Projection results

topo.layouts.projector._HAS_PYMDE = True
topo.layouts.projector._remove_anchor_anchor_edges(edges, data, anchors)