milia.represent.diffusion#
Diffusion maps (Coifman and Lafon, 2006).
Functions
|
Diffusion-map coordinates and eigenvalues of the rows of |
Classes
|
Diffusion-map embedding as a scikit-learn estimator. |
- milia.represent.diffusion.embed(X, n=8, alpha=1.0, sigma='median')#
Diffusion-map coordinates and eigenvalues of the rows of
X.A Gaussian kernel on Euclidean distance is alpha-normalised (
alpha=1removes the effect of sampling density), turned into a Markov matrix, and its leading non-trivial eigenvectors give the coordinates. DenseO(n^2)memory, fine for a few thousand rows.- Parameters:
- Return type:
- Returns:
(eigenvalues, coordinates)of shapes(n,)and(n_samples, n), eigenvalues in decreasing order.
Examples
>>> X = np.vstack([np.zeros((10, 2)), np.full((10, 2), 5.0)]) + np.random.default_rng(0).normal(size=(20, 2)) >>> values, coords = embed(X, n=2) >>> coords.shape, bool(values[0] >= values[1]) ((20, 2), True)
- class milia.represent.diffusion.Diffusion(n_components=8, alpha=1.0, sigma='median')#
Bases:
BaseEstimatorDiffusion-map embedding as a scikit-learn estimator.
Like t-SNE it embeds the data it is fitted on and has no out-of-sample
transform; usefit_transform().- Parameters:
- Variables:
eigenvalues – Eigenvalues of the kept coordinates, for spotting a spectral gap.
embedding – The coordinates of the training rows.
Examples
>>> model = Diffusion(n_components=2).fit(np.random.default_rng(0).normal(size=(30, 3))) >>> model.embedding_.shape, model.eigenvalues_.shape ((30, 2), (2,))
- fit(X, y=None)#
Embed the training rows.
- fit_transform(X, y=None)#
Fit and return the diffusion coordinates of the training rows.
- Parameters:
- Return type:
- Returns:
The coordinates, shape
(n_samples, n_components).
Examples
>>> X = np.random.default_rng(0).normal(size=(30, 3)) >>> Diffusion(n_components=3).fit_transform(X).shape (30, 3)