UNPKG

clustering-tfjs

Version:

High-performance TypeScript clustering algorithms (K-Means, Spectral, Agglomerative) with TensorFlow.js acceleration and scikit-learn compatibility

23 lines 1.03 kB
import * as tf from '../tf-adapter'; /** * Optimised Euclidean pairwise distance using the identity * ‖x − y‖² = ‖x‖² + ‖y‖² − 2·xᵀy to avoid building an (n,n,d) tensor. */ export declare function pairwiseEuclideanMatrix(points: tf.Tensor2D): tf.Tensor2D; /** * Computes the pairwise distance matrix for the given points according to the * requested metric. * * The result is an `(n, n)` tensor `D` where `D[i, j]` contains the distance * between row `i` and row `j` of the input `points`. * * Supported metrics: * • "euclidean" – ℓ2 distance (uses an optimised implementation) * • "manhattan" – ℓ1 distance * • "cosine" – 1 − cosine-similarity * * For performance and numerical stability the computation is wrapped in * `tf.tidy` so that all intermediate tensors are eagerly disposed. */ export declare function pairwiseDistanceMatrix(points: tf.Tensor2D, metric?: 'euclidean' | 'manhattan' | 'cosine'): tf.Tensor2D; //# sourceMappingURL=pairwise_distance.d.ts.map