orthrus.manifold namespace

Submodules

orthrus.manifold.mds module

This module contains classes implementing manifold learning algorithms.

class orthrus.manifold.mds.MDS(n_components=2, use_cuda=False, prev_embedding=None)

Bases: sklearn.base.BaseEstimator

This class compute the Multidimensional Scaling (MDS) embedding of an \(\text{n_samples}\times\text{n_samples}\) distance matrix \(X\) for n_components. So that the data is embedding into Euclidean space with dimension n_components. The algorithm is as follows:

  1. Compute \(D = X\odot X\) (Distances squared) where \(\odot\) indicates the point-wise product.

  2. Compute \(B = CDC\) where \(C\) is the double-centering matrix \(C=I-\frac{1}{\text{n_samples}}ee^T\) and \(e\) is the ones vector of dimension \(\text{n_samples}\).

  3. Compute \(E\), the matrix whose columns are the eigenvectors of \(B\), and compute \(\lambda\) the vector of corresponding eigenvalues.

  4. Let \(\tilde{\Lambda}\) be the diagonal matrix containing the top n_components largest eigenvalues in descending order, and let \(\tilde{E}\) be the matrix whose columns are the eigenvectors, columns of \(E\), that correspond to the diagonal entries in \(\tilde{\Lambda}\).

  5. The embedding is given by \(Y = \tilde{E}\tilde{\Lambda}^{\frac{1}{2}}\).

Parameters
  • n_components (int) – The number of components (dimensions) to use for the embedding.

  • use_cuda (bool) – Flag indicating whether or not to use cuda tensors on the gpu.

  • prev_embedding (ndarray of shape (n_samples, n_components)) – Optional embedding used to orient the new embedding from. This is useful if you are generating sequential embeddings where you want continuity between frames.

eigenvalues_

The eigenvalues corresponding to the MDS embedding.

Type

ndarray of shape (n_samples,)

eigenvectors_

The eigenvectors corresponding to the MDS embedding.

Type

ndarray of shape (n_samples, n_samples)

embedding_

The embedding given by MDS with n_components.

Type

ndarray of shape (n_samples, n_components)

fit(X, y=None)

Computes the position of the points in the embedding space. Stores the eigenvalues and eigenvectors into MDS.eigenvalues_ and MDS.eigenvectors_ respectively. Stores the embedding into MDS.embedding_

Parameters
  • X (array-like of shape (n_samples, n_samples) or (n_samples, n_features)) – An array representing the distances between samples. Should be a symmetric non-negative matrix, but if not euclidean l2 will be used between samples.

  • y (Ignored) –

Returns

The fit MDS instance.

Return type

MDS

fit_transform(X, y=None)

Fits the MDS model to the data via MDS.fit(), returns the embedding stored in MDS.embedding_.

Parameters
  • X (array-like of shape (n_samples, n_samples)) – An array representing the distances between samples. Should be a symmetric non-negative matrix.

  • y (Ignored) –

Returns

The embedding produced my MDS with n_components

Return type

ndarray of shape (n_samples, n_features)