Skip to main content

Overview

Locally Linear Embedding (LLE) performs non-linear dimensionality reduction by preserving local linear relationships between neighbors. It assumes data lies on a locally linear manifold.

Constructor

new LocallyLinearEmbedding(options?: LocallyLinearEmbeddingOptions)
options
LocallyLinearEmbeddingOptions
Configuration options for LLE

Methods

fit

fit(X: Matrix): this
Compute the LLE embedding from training data.
X
Matrix
required
Training data of shape [nSamples, nFeatures]
Returns: The fitted LocallyLinearEmbedding instance

fitTransform

fitTransform(X: Matrix): Matrix
Fit the model and return the embedding.
X
Matrix
required
Training data of shape [nSamples, nFeatures]
Returns: Embedded data of shape [nSamples, nComponents]

transform

transform(X: Matrix): Matrix
Transform new data using the fitted model.
X
Matrix
required
New data to transform of shape [nSamples, nFeatures]
Returns: Embedded data of shape [nSamples, nComponents]

Properties

embedding_
Matrix | null
Embedded coordinates in low-dimensional space, shape [nSamples, nComponents]
reconstructionError_
number | null
Reconstruction error of the embedding
nFeaturesIn_
number | null
Number of features seen during fit

Example

import { LocallyLinearEmbedding } from '@elucidate/elucidate';

// Manifold data
const data = [
  [1.0, 2.0, 1.0],
  [1.2, 2.1, 1.1],
  [1.1, 2.3, 1.2],
  [2.0, 3.0, 2.0],
  [2.1, 3.2, 2.1],
  [2.2, 3.1, 2.2],
];

const lle = new LocallyLinearEmbedding({ 
  nNeighbors: 3,
  nComponents: 2,
  reg: 1e-3 
});

const embedding = lle.fitTransform(data);
console.log('Embedded coordinates:', embedding);
console.log('Reconstruction error:', lle.reconstructionError_);

// Transform new data
const newData = [
  [1.5, 2.5, 1.5],
  [2.5, 3.5, 2.5],
];

const newEmbedding = lle.transform(newData);
console.log('New points embedded:', newEmbedding);

Notes

  • LLE works best for data on smooth, locally linear manifolds
  • The reg parameter helps with numerical stability
  • The algorithm preserves local geometry but may distort global structure
  • Requires careful selection of nNeighbors based on data density

Build docs developers (and LLMs) love