evomap.mapping._cmds#

Classic (SVD-based) Multidimensional Scaling, as proposed in:

Torgerson, W.S. Multidimensional scaling: I. Theory and method. Psychometrika 17, 401–419 (1952).

Thanks to Francis Song, from whom this implementation has borrowed. Source: http://www.nervouscomputer.com/hfs/cmdscale-in-python/

Classes#

Module Contents#

class evomap.mapping._cmds.CMDS(n_dims=2)[source]#
n_dims = 2#
__str__()[source]#

Create a string representation of the CMDS instance.

static _cmdscale(D, n_dims, eps=1e-10)[source]#

Perform classical multidimensional scaling (CMDS) on the input distance matrix.

CMDS reduces the dimensionality of a distance matrix while preserving the pairwise distances as well as possible using eigenvalue decomposition.

Parameters:
  • D (np.array of shape (n, n)) – Symmetric distance matrix to be scaled.

  • n_dims (int) – Number of dimensions to which the data should be reduced.

  • eps (float, optional, default=1e-16) – Tolerance for numerical precision in rounding the resulting coordinates.

Returns:

  • Y (np.array of shape (n, n_dims)) – Configuration matrix with the reduced dimensionality representation of the points.

  • e (np.array of shape (n,)) – The eigenvalues corresponding to the dimensions.

Raises:

ValueError – If the input matrix D is not square or symmetric.

fit(X)[source]#

Fit the CMDS model to the provided distance matrix.

Parameters:

X (np.array of shape (n, n)) – Symmetric distance matrix to be scaled.

Returns:

self – Returns the instance itself with the configuration matrix Y_ stored as an attribute.

Return type:

object

fit_transform(X)[source]#

Fit the CMDS model to the distance matrix and return the transformed coordinates.

Parameters:

X (np.array of shape (n, n)) – Symmetric distance matrix to be scaled.

Returns:

The transformed coordinates (configuration matrix) in the reduced dimensional space.

Return type:

np.array of shape (n, n_dims)